错误显示发送按钮作为响应在Facebook messenger bot
问题描述:
我正在构建与api.ai集成的Facebook messenger bot。我的api.ai代理连接到webhook - api.php。我现在面临的挑战是我想通过webhook向机器人发送按钮响应(格式化的消息)。 我跟着这个文档 - https://docs.api.ai/docs/webhook错误显示发送按钮作为响应在Facebook messenger bot
而且我在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;
?>
谢谢。
答
$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
你是什么意思,它不显示?这是不是传递的信息?如果这是问题,你可以发布你的堆栈跟踪吗? – akinmail