DialogFlow + LINE.me 与丰富消息的集成
DialogFlow + LINE.me integration with rich messages
我正在使用 fulfillment webhook 集成 DialogFlow 和 LINE。当文本位于响应的 speech
字段中时,我能够成功将消息回复到用户的 LINE。
{
"speech": "your number is 1234"
}
但是,如果我按照文档添加特定于 LINE 的回复,它不会起作用,这意味着它什么都不回复。
{
"data": {
"line": {
"replyToken": "e4050bccd34b52...b119069d27bb5",
"messages": [
{
"text": "Hi",
"type": "text"
}
]
}
}
}
这意味着我只能回复一条短信,而不能回复其他富消息。
是我做错了什么还是 DialogFlow 的问题?
我终于知道怎么做了!
问题中的响应格式不正确。正确的格式类似于:
{
'messages': [
<message object>,
<message object>
]
}
可以使用哪些类型可以参考message object。
需要注意的一件事是类型 4,您可以简单地使用 LINE.
中指定的有效载荷
例如,
{
'messages': [
{
'type': 0,
'speech': 'ABC'
},
{
"type": 4,
"payload": {
"line": {
"type": "template", "altText": "This is a buttons template",
"template": {
"type": "buttons",
"thumbnailImageUrl": "https://images.justlanded.com/event_images/Tets/photo/events_original_45195_42919.jpg",
"imageAspectRatio": "rectangle",
"imageSize": "cover",
"imageBackgroundColor": "#FFFFFF",
"title": "Menu",
"text": "Please select",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=123"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=123"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
}
]
}
}
}
}
]
}
我正在使用 fulfillment webhook 集成 DialogFlow 和 LINE。当文本位于响应的 speech
字段中时,我能够成功将消息回复到用户的 LINE。
{
"speech": "your number is 1234"
}
但是,如果我按照文档添加特定于 LINE 的回复,它不会起作用,这意味着它什么都不回复。
{
"data": {
"line": {
"replyToken": "e4050bccd34b52...b119069d27bb5",
"messages": [
{
"text": "Hi",
"type": "text"
}
]
}
}
}
这意味着我只能回复一条短信,而不能回复其他富消息。
是我做错了什么还是 DialogFlow 的问题?
我终于知道怎么做了! 问题中的响应格式不正确。正确的格式类似于:
{
'messages': [
<message object>,
<message object>
]
}
可以使用哪些类型可以参考message object。 需要注意的一件事是类型 4,您可以简单地使用 LINE.
中指定的有效载荷例如,
{
'messages': [
{
'type': 0,
'speech': 'ABC'
},
{
"type": 4,
"payload": {
"line": {
"type": "template", "altText": "This is a buttons template",
"template": {
"type": "buttons",
"thumbnailImageUrl": "https://images.justlanded.com/event_images/Tets/photo/events_original_45195_42919.jpg",
"imageAspectRatio": "rectangle",
"imageSize": "cover",
"imageBackgroundColor": "#FFFFFF",
"title": "Menu",
"text": "Please select",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=123"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=123"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
}
]
}
}
}
}
]
}