我正在尝试使用dialogflow从webhook通过facebook bot发送多条消息。我想发送一条只包含文字的邮件,然后是airline template,然后快速回复。我可以发送一个文本,然后快速回复,我可以单独发送一个航空公司模板,但我无法弄清楚如何在订单中发送它们。
我可以发送文字&以这种方式快速回复邮件:
return ({
"speech": "",
"messages": [
{
"type": 0,
"speech": copy1
},
{
"type": 2,
"title": obj.QRtitle,
"replies":[
qR1 = obj.qR1 || '',
qR2 = obj.qR2 || '',
qR3 = obj.qR3 || '',
qR4 = obj.qR4 || '',
qR5 = obj.qR5 || '',
qR6 = obj.qR6 || '',
qR7 = obj.qR7 || '',
qR8 = obj.qR8 || '',
qR9 = obj.qR9 || '',
qR10 = obj.qR10 || '',
]
},
],
"source": "facebook"
});
},
然后我可以这样发送航空公司模板:
return ({
"data" : {
"facebook" : {
"attachment" : {
"type" : "template",
"payload" : {
"template_type": "airline_boardingpass",
"intro_message": object.intro_message|| '',
"locale": "en_US",
"boarding_pass": [
{
"passenger_name": object.passenger_name,
"pnr_number": "ABCDEF",
"seat": object.seat|| '',
"logo_image_url": object.logo_image_url|| '',
"header_image_url": object.header_image_url|| '',
"qr_code": object.qrcode_data,
"above_bar_code_image_url": object.above_bar_code_image_url|| '',
"auxiliary_fields": [
{
"label": "Terminal",
"value": object.terminal
},
{
"label": "Departure",
"value": object.departure_date_time|| '',
}
],
"secondary_fields": [
{
"label": "Boarding",
"value": object.boarding_time|| '',
},
{
"label": "Gate",
"value": object.departure_gate
},
{
"label": "Seat",
"value": object.seat
},
],
"flight_info": {
"flight_number": object.flight_number,
"departure_airport": {
"airport_code": object.departure_airport_code,
"city": object.departure_city,
"terminal": object.departure_term,
"gate": object.departure_gate
},
"arrival_airport": {
"airport_code": object.arrival_airport_code,
"city": object.arrival_city
},
"flight_schedule": {
"departure_time": object.departure_time|| '',
"arrival_time": object.arrival_time|| '',
}
}
}
]
},
},
},
},
"source": "facebook"
});
我无法弄清楚如何将两者合并成功发送 - 任何建议都会有所帮助。
答案 0 :(得分:1)
Dialogflow支持自定义有效负载消息对象。以下是您的响应的修改版本,应该可以使用。它的工作原理是将自定义有效负载从顶级Dialogflow响应中的自定义有效负载移动到与Dialogflow webhook响应相同级别的自定义有效负载消息对象,作为其他文本和快速回复消息:
{
"messages": [
{
"speech": "copy1",
"type": 0
},
{
"replies": [
"replies..."
],
"title": "obj.QRtitle",
"type": 2
},
{
"platform": "facebook",
"type": 4,
"payload": {
"attachment": {
"type": "template",
"payload": {
"template_type": "airline_boardingpass",
"intro_message": "object.intro_message",
"locale": "en_US",
"boarding_pass": [
{
"passenger_name": "object.passenger_name",
"pnr_number": "ABCDEF",
"seat": "object.seat",
"logo_image_url": "object.logo_image_url",
"header_image_url": "object.header_image_url",
"qr_code": "object.qrcode_data",
"above_bar_code_image_url": " object.above_bar_code_image_url",
"auxiliary_fields": [
{
"label": "Terminal",
"value": "object.terminal"
},
{
"label": "Departure",
"value": "object.departure_date_time"
}
],
"secondary_fields": [
{
"label": "Boarding",
"value": "object.boarding_time"
},
{
"label": "Gate",
"value": "object.departure_gate"
},
{
"label": "Seat",
"value": "object.seat"
}
],
"flight_info": {
"flight_number": "object.flight_number",
"departure_airport": {
"airport_code": "object.departure_airport_code",
"city": "object.departure_city",
"terminal": "object.departure_term",
"gate": "object.departure_gate"
},
"arrival_airport": {
"airport_code": "object.arrival_airport_code",
"city": "object.arrival_city"
},
"flight_schedule": {
"departure_time": "object.departure_time",
"arrival_time": "object.arrival_time"
}
}
}
]
}
}
}
}
],
"source": "facebook",
"speech": ""
}