我正在尝试向一个Webhook调用Dialogflow发送多条消息,该调用将传递给Messenger。现在我的Webhook响应了一个故障的JSON主体:
{
'fulfillmentText': "Text",
'fulfillmentMessages': [{
"platform": "facebook",
"text": [{
"text": "Text"
}]
}],
'source': "facebook"
}
当我通过Messenger测试Webhook时,我看到正在输入符号,但从未收到 Text 消息。在从Dialogflow控制台测试同一个Webhook时我得到了
Webhook执行成功
返回。我想我错过了一些JSON字段,告诉Dialogflow它必须以哪种格式发送JSON和Messenger API。谁有任何关于如何解决这个问题的线索?
修改 我最近没有工作的试用......
{
"fulfillmentText": "Hola!",
"fulfillmentMessages": [
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
},
{
"text": {
"text": [
"Title: this is a title"
]
},
"platform": "FACEBOOK"
}
]
}
答案 0 :(得分:3)
如果您只发送文字,则只需向fulfillmentText
提供字符串,而无需提供fulfillmentMessages
属性。
如果您确实为目标平台提供了fulfillmentMessages
属性,Dialogflow会将您的有效负载发送到Facebook。在这种情况下,如果有效负载无效,Facebook上实际上不会显示任何消息。删除响应JSON的fulfillmentMessages
属性,您的机器人应该响应。
如果您想在回复中添加卡片,可以发送以下回复:
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji .",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
<小时/> 编辑:如果你想发送多条消息,可以发送这样的响应(这个JSON会发送两张相同的卡,但你可以根据this documentation更改消息类型(卡/文本/等)):
{
"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji .",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
},
{
"platform": "FACEBOOK",
"card": {
"title": "Title: this is a title",
"subtitle": "This is an subtitle. Text can include unicode characters including emoji .",
"imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"buttons": [
{
"text": "This is a button",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
答案 1 :(得分:1)
我邮寄了有关此问题的Dialogflow支持,结果发现目前无法从webhook发送多条消息。
您好,
此时,无法直接发送顺序消息 来自webhook。但是,如果您使用我们的单击之一 支持丰富消息的集成,您可以在其中调用意图 从webhook通过事件定义多个消息 描述于 https://dialogflow.com/docs/events#invoking_event_from_webhook。
如果您有任何问题,请与我们联系。
问候,来自Dialogflow的Ankita