Reputation: 87
I am trying to send multiple messages from a webhook through a facebook bot using dialogflow. I want to send a a message with only text, then an airline template, then a quick reply. I can send just a text then a quick reply, and I can send just an airline template separately but I am having trouble figuring out how to send them in the order.
I can send text & quick reply messages this way:
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"
});
},
and then I can send an airline template this way:
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"
});
I am having trouble figuring out how to merge the two to send it successfully -- any advice would be helpful.
Upvotes: 1
Views: 1104
Reputation: 3469
Dialogflow support custom payload message objects. Below is a modified version of your response that should work. It works by moving your custom payload from a custom payload in the top level Dialogflow response to a custom payload message objects at the same level of the Dialogflow webhook response as the other text and quick reply messages:
{
"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": ""
}
Upvotes: 1