我正在建立一个与api.ai集成的脸书信使机器人。我的api.ai代理连接到webhook - api.php。我现在面临的挑战是,我想通过我的webhook向机器人发送一个按钮响应(格式化消息)。我遵循了这个文档- https://docs.api.ai/docs/webhook
我在api.php中这样做了,但是它没有显示按钮
<?php
header('Content-Type: application/json');
ob_start();
$json = file_get_contents('php://input');
$request = json_decode($json, true);
$action = $request["result"]["action"];
$parameters = $request["result"]["parameters"];
$data =json_encode([
'speech' => "test",
'displayText' => "test",
'data' => "{
'facebook': {
'recipient':{
'id':'USER_ID'
},
'message':{
'attachment':{
'type':'template',
'payload':{
'template_type':'button',
'text':'What do you want to do next?',
'buttons':[
{
'type':'web_url',
'url':'https://petersapparel.parseapp.com',
'title':'Show Website'
},
{
'type':'postback',
'title':'Start Chatting',
'payload':'USER_DEFINED_PAYLOAD'
}
]
}
}
}
}
}
}",
'source' => "source"
]);
echo $data;
?>
谢谢。
发布于 2017-04-10 21:31:04
$qrString = "Date|Location|Category";
$qrActions = "ActionSetDate|ActionSetLocation|ActionSetCategory";
$webhookResponseArray['data']['facebook']['text'] = "Choose an action...";
// make array of prompts and actions
$qrArray = array();
$actionArray = explode('|', $qrActions);
$i = 0;
$a = array();
foreach (explode('|', $qrString) as $qrButton)
{
$a['content_type'] = 'text';
$a['title'] = $qrButton;
$a['payload'] = $actionArray[$i];
$qrArray[] = $a;
$i++;
}
$webhookResponseArray['data']['facebook']['quick_replies'] = $qrArray;
// encode and send webhookResponseArray
https://stackoverflow.com/questions/43298593
复制相似问题