Dialogflow Messenger集成(V1 API)的列表模板

时间:2018-09-03 22:18:00

标签: php facebook dialogflow api-ai

我正在开发一个Facebook应用程序,该应用程序使用一个Messenger bot来发布到我的dialogflow代理中,然后再将它发布到我的后端PHP webhook。

问题是我找不到正确的文档来发回列表模板。

我有这个(有效的)代码可以发送回按钮模板:

$array = array(
    "source" => $source,
    "speech" => 'test string',
    "data" => [  "facebook" => [
        "attachment" => [
            "type" => "template",
            "payload" => [
                "template_type"=>"button",
                "text"=>"Try the URL button!",
                "buttons"=>[
                  [
                    "type"=>"web_url",
                    "url"=>"https://www.messenger.com/",
                    "title"=>"URL Button",
                    "webview_height_ratio"=>"full"
                  ]
                ]
            ]
        ]

        ]
    ],
    "displayText" => 'xd',
    "contextOut" => array()
);
echo json_encode($array);

要清楚;这段代码可以正常工作,我从这里的文档中获取了它: https://developers.facebook.com/docs/messenger-platform/send-messages/template/button

但是,如果我从同一来源获取代码,并将其改编成dialogflow并按如下所示实现它:

$elementList = array();
foreach ($listings->results as $value) {
    array_push($elementList, [
        "title" => $value->eventname,
        "subtitle"=> $value->description,
        "image_url"=> $value->imageurl,
        "buttons"=>[
            [
            "title"=> "View",
            "type"=>"web_url",
            "url"=>$value->link,
            "messenger_extensions"=> true,
            "webview_height_ratio"=> "tall",
            "fallback_url"=> $value->link
            ]

        ]
    ]);
}



$array = array(
    "source" => $source,
    "data" => [  "facebook" => [
        "attachment" => [
            "type" => "template",
            "payload" => [
                "template_type"=>"list",
                "top_element_style"=>"compact",
                "elements"=> $elementList,
                "buttons"=> [
                    [
                      "title"=> "View More",
                      "type"=> "postback",
                      "payload"=> "payload"            
                    ]
                ]
            ]
        ]

        ]
    ],
    "contextOut" => array()
);
echo json_encode($array);

该数组以我想要的格式出现,并且与文档中显示的格式相同。但是,当我将其发布到dialogflow并在Messenger客户端中对其进行测试时;我得到一个空白的答复。

任何指导表示赞赏。

0 个答案:

没有答案