Messenger 聊天机器人发送过多消息

时间:2021-03-15 13:10:38

标签: php facebook facebook-graph-api chatbot facebook-messenger

我目前正在开发的聊天机器人有一些问题,它会不间断地回复消息。 我对此很陌生,下面的代码我只是将下面的代码复制到 youtube 视频中,代码正在运行,但我不明白为什么它发送了太多消息

<?php

file_put_contents("fb.txt", file_get_contents("php://input"));

$fb = file_get_contents('fb.txt');
$fb = json_decode($fb);
$sid = $fb->entry[0]->messaging[0]->sender->id;
if($sid == "105140841657941"){
    exit();
}
$data = array(
    'messaging_type' => 'RESPONSE',
   'recipient' => array('id' => "$sid"),
   'messsage' => array('text' => "Nice to Meet you")
);
$options = array(
    'http' => array(
        'method' => 'POST',
        'content' => json_encode($data),
        'header' => "Content-type: application/json\n"
        )
);

$context = stream_context_create($options);

$token = "SAMPLE TOKEN";
file_get_contents("https://graph.facebook.com/v10.0/me/messages?access_token=$token", false, $context);
file_put_contents("fb.txt", "");
?>

0 个答案:

没有答案