2016-08-09 12 views
2

私は非常に単純なボットを設定しようとしています。私はアクセストークンを生成し、私のウェブサーバ(SSL認定)に簡単なindex.phpファイルを作成し、index.phpファイルを指し示すwebhookを設定し、私のwebhookを私のページイベント(developers.facebook.comのすべて)に登録し、ボットと無回答を得た。何が問題なのでしょうか?メッセンジャーボットが動作しない

(私はすべてチェックしています両方のトークンを、私は管理者など)午前

ここでは私のコードです:

<?php 
$access_token = "i-filled-this-out"; 
$verify_token = "i-also-filled-this-out"; 
$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; 
} 

$input = json_decode(file_get_contents('php://input'), true); 
$sender = $input['entry'][0]['messaging'][0]['sender']['id']; 
$message = $input['entry'][0]['messaging'][0]['message']['text']; 
$message_to_reply = ''; 

$message_to_reply = 'Huh! what do you mean?'; 

//API Url 
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token; 
//Initiate cURL. 
$ch = curl_init($url); 
//The JSON data. 
$jsonData = '{ 
    "recipient":{ 
     "id":"'.$sender.'" 
    }, 
    "message":{ 
     "text":"'.$message_to_reply.'" 
    } 
}'; 
//Encode the array into JSON. 
$jsonDataEncoded = $jsonData; 
//Tell cURL that we want to send a POST request. 
curl_setopt($ch, CURLOPT_POST, 1); 
//Attach our encoded JSON string to the POST fields. 
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded); 
//Set the content type to application/json 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 
//Execute the request 
if(!empty($input['entry'][0]['messaging'][0]['message'])){ 
    $result = curl_exec($ch); 
} 

答えて

0

は、あなたのウェブフックが送られたPOSTリクエストにHTTP 200応答を返していることを確認してくださいfacebookで。

実行中のWebサーバーは?ログをチェックして、WebHookがFacebookからのPOST要求を受信して​​いるかどうか(そして200を返しているかどうか)を確認します。

あなたのウェブフックをテストする最良の方法は、郵便配達員のようなものを使って、Facebookの標準的なPOSTを模倣し、あなたが提供している回答をチェックすることです。

関連する問題