希望你们中的一些人能帮上忙,因为几天前,我试图使用以下代码在我的FaceBook机器人中显示一个像轮播这样的列表:
public function returnCarousel(){
$messagearray = array (
'message' =>
array (
'attachment' =>
array (
'type' => 'list',
'payload' =>
array (
'template_type' => 'list',
'top_element_style' => 'compact',
'elements' =>
array (
0 =>
array (
'title' => 'Classic T-Shirt Collection',
'subtitle' => 'See all our colors',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
'buttons' =>
array (
0 =>
array (
'title' => 'View',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/collection',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
1 =>
array (
'title' => 'Classic White T-Shirt',
'subtitle' => 'See all our colors',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=100',
'messenger_extensions' => false,
'webview_height_ratio' => 'tall',
),
),
2 =>
array (
'title' => 'Classic Blue T-Shirt',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png',
'subtitle' => '100% Cotton, 200% Comfortable',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
'buttons' =>
array (
0 =>
array (
'title' => 'Shop Now',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/shop?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
),
'buttons' =>
array (
0 =>
array (
'title' => 'View More',
'type' => 'postback',
'payload' => 'payload',
),
),
),
),
),
);
$this->sendMessage($messagearray);
}
public function sendMessage($parameters) {
echo json_encode($parameters);
}
在我的ngrok控制台中,没有显示轮播,也没有错误返回提示:
{“ message”:{“ attachment”:{“ type”:“ list”,“ payload”:{“ template_type”:“ list”,“ top_element_style”:“ compact”,“ elements”:[{“ title“:”经典T恤系列“,” subtitle“:”查看我们所有的颜色“,” image_url“:” https://peterssendreceiveapp.ngrok.io/img/collection.png“,” buttons“:[{ “ title”:“查看”,“类型”:“ web_url”,“ url”:“ https://peterssendreceiveapp.ngrok.io/collection”,“ messenger_extensions”:true,“ webview_height_ratio”:“高”,“ fallback_url “:” https://peterssendreceiveapp.ngrok.io/“}]},{” title“:”经典白色T恤“,” subtitle“:”查看我们所有的颜色“,” default_action“:{” type“ :“ web_url”,“ url”:“ https://peterssendreceiveapp.ngrok.io/view?item=100”,“ messenger_extensions”:false,“ webview_height_ratio”:“ tall”}},{“ title”:“ Classic蓝色T恤”,“ image_url”:“ https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png”,“字幕”:“ 100%棉,200%舒适”,“ default_action”: {“ type”:“ web_url”,“ url”:“ https://peterssendreceiveapp.ngrok.io/view?item=101”,“ messenger_extensions”:true,“ webview_height_ratio”:“高”, “ fallback_url”:“ https://peterssendreceiveapp.ngrok.io/”},“按钮”:[{“ title”:“立即购买”,“ type”:“ web_url”,“ url”:“ https:// peterssendreceiveapp.ngrok.io/shop?item=101","messenger_extensions":true,"webview_height_ratio“:”高“,” fallback_url“:” https://peterssendreceiveapp.ngrok.io/“}]}]”,“按钮“:[{”标题“:”查看更多“,”类型“:”回发“,”有效载荷“:”有效载荷“}]}}}}}
如果我发送了一张有效的卡片,请您帮忙
答案 0 :(得分:0)
已解决:我对数组进行了格式化,使它正常工作。
$messagearray = array (
'speech' => 'Carousel',
'messages' => array (
0 => array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Amarilla',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaamarilla.jpg',
'buttons' =>
array (
0 =>array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
1 =>array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Azul',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaazul.jpg',
'buttons' =>
array (
0 => array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
),);