-1
Facebookのメッセンジャーのボットを開発中です。私はテストページ、フェイスブックアプリ、WebHookページをPHPで作成しました。フェイスブックメッセンジャーボット失敗のWebhook
テストページにボットを登録しましたが、結果は肯定的でしたが、ページにメッセージを送信しようとすると、ページにアクセスできない場合のように応答しません。
ここに私のPHPスクリプト:あなたが一緒にそれらすべてを組み合わせる前に
$access_token = "EAAY...ZD";
$verify_token = "verifica_token";
$hub_verify_token = null;
if(isset($_REQUEST['hub_challenge'])) {
$challenge = $_REQUEST['hub_challenge'];
$hub_verify_token = $_REQUEST['hub_verify_token'];
}
if ($hub_verify_token === $verify_token) {
echo $challenge;
}
// handle bot's anwser
$input = json_decode(file_get_contents('php://input'), true);
$senderId = $input['entry'][0]['messaging'][0]['sender']['id'];
$messageText = $input['entry'][0]['messaging'][0]['message']['text'];
$answer = "I don't understand. Ask me 'hi'.";
if($messageText == "hi") {
$answer = "Hello";
}
$response = [
'recipient' => [ 'id' => $senderId ],
'message' => [ 'text' => $answer ]
];
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_exec($ch);
curl_close($ch);
@iownthegameこんにちは、私は、この変数にこのコードを試してみました: $ SENDERID = 100000061458447 //必要があり、私のFacebookのID 私はこのエラー私のリターンを実行します。 { "エラー":{ "メッセージ"、": "(#100)Invalid fbid"、 "type": "OAuthException"、 "code":100、 "fbtrace_id": "HKdGEATQe78"}} –
あなたのfbidで試してみることはできません。 bot – iownthegame
okにメッセージを送信したときにボットが受信したが、ボットにメッセージを書き込むと、WebHookはメッセージを受信しません。 –