我的聊天機器人工作得很好,但我在調試歡迎消息功能時遇到了問題,因爲它只在啓動對話時顯示出來(儘管我很確定它在同事手機上嘗試過)。如何重置我的聊天,以便將我視爲新用戶與之交互?Facebook聊天機器人 - 我如何測試歡迎消息?
這是我的歡迎PHP腳本的時刻
<?php
function webhook() {
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'MYTOKEN') {
echo $challenge;
}
$input = json_decode(file_get_contents('php://input'), true);
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$welcomejson = welcomemessage();
welcomesend($json);
function message() {
$json = '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"message":{
"text":"Welcome to My BOT!"
}
}
]
}';
return $json;
}
function send($json) {
$url = 'https://graph.facebook.com/v2.6/MYPAGEID/thread_settings?access_token=MYTOKEN';
//Initiate cURL.
$ch = curl_init($url);
//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, $jsonData);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
}
你能指出我的地方我可以找到如何在PHP中做到這一點嗎?謝謝 – Ukor
@Ukor https://gist.github.com/visitdigital/58c71acb123870d1ac2ec714d7536587 –