dialogflow-fulfillment-nodejs
dialogflow-fulfillment-nodejs copied to clipboard
Multiple agent.add fails with integrations
Hi folks! 👋
I want to send multiple custom payloads through one intent handler.
Appears like multiple agent.adds with custom payloads (e.g using agent.FACEBOOK) currently fail.
From the Cloud Function log:
Error: Payload response for FACEBOOK already defined. at WebhookClient.addResponse_
I could look into it and open a PR, but I noticed https://github.com/dialogflow/dialogflow-fulfillment-nodejs/pull/173, https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/35 and https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/146 which appear related.
What do you suggest I try?
What is the use case for having multiple custom payloads?
Within an async function, we could first send out a typing_on sender action while a request is being awaited, and then we could send out the next message on request completion.
... or is that kind of behaviour not supported?
Also, breaking down a larger message into 3 different messages within a handler.
I'm facing same issue. Don't know why this library does not support multiple payload.
Any news on this case? DialogFlow UI does handle 2 Facebook payloads correctly. It's only this library that's complaining.
As a use case, I use multiple payloads to send some "intro text" + "attachment" (generic template cards, for example) + "suggestion chips", in the same reply.
If I use the generic rich response from the library, some unwanted text shows in Facebook Messenger right before the suggestion chips (the text shows "Choose an item"). If I build the Facebook response myself using a Payload, that text is not shown, which looks much nicer.
The problem is that Facebook won't allow "intro text" + "attachment" + "suggestion chips" in the same message object. Suggestion chips can accompany an intro text, or an attachment. But text + attachment can't be together.
So 2 Payloads need to be sent: 1 for the text, and 1 for the attachment + chips.
That's when I get Error: Payload response for FACEBOOK already defined., but it does work correctly if I hardcode the payloads for Facebook on DialogFlow UI, as an intent response.
#173 makes this possible. Multiple payloads are supported using
agent.add(new Payload(agent.FACEBOOK, facebookPayload1, {sendAsMessage:true}));
agent.add(new Payload(agent.FACEBOOK, facebookPayload2, {sendAsMessage:true}));
EDIT: This is not actually possible, as pointed out by @maganap below, however mixing text responses and one payload is possible with #173 .
@jdpowell1 Thanks! I noticed about #173 and downloaded latest commit (aaade16 at the moment), it does fix the Text + Payload case when sendAsMessage:true, like:
agent.add( new Text('Hello there') );
agent.add( new Payload(agent.FACEBOOK, facebookPayload1, {sendAsMessage:true}) );
which solves my issue (Facebook: Text(text) + Payload(attachment + chips)).
Even though I don't need 2 Payloads now, I still get Error: Payload response for FACEBOOK already defined. when trying to add 2 Payloads, like in your example:
agent.add(new Payload(agent.FACEBOOK, facebookPayload1, {sendAsMessage:true}));
agent.add(new Payload(agent.FACEBOOK, facebookPayload2, {sendAsMessage:true}));
Hello guys, I'm facing the same issue here.
My use case is that I want to display to the user a list of items and I want to ask them their feedback via a thumbs up or thumbs down.
I need two payloads here:
- For the list
- For the quick replies
However as @maganap said, I can't add two payloads and I get the same error: Error: Payload response for FACEBOOK already defined.
Do you plan to add a feature where we could add two payloads ?
PS: I know that with the latest commit (aaade16), I can add a Payload and a Suggestion chip via the sendAsMessage option. However, I want to get rid of the choose an item text that is automatically provided on Facebook Messenger. That's why I want to send another custom payload with quick replies.
Thanks!
I'm having trouble sending me messages to Hangouts Chat. All messages that are in agent.add (message) do not work in chat, but work on other platforms. Is there any configuration for Chat? I looked for examples but found none.
Since multiple custom payloads are allowed on Dialogflow UI. I see no reason to limit only for single payload here.
https://github.com/dialogflow/dialogflow-fulfillment-nodejs/blob/aaade16f72a799610ae6ef168c8b47780ae58e6e/src/dialogflow-fulfillment.js#L269-L284
As line 277 only Payload response is not allowed to add more than once.
Is there any other problems or concerns? because this issue was tagged as Feature Request for a long time but it's not implemented yet.
I might have time to work on this and open a PR. Any advice or pointers for someone new to the project?
FYI, I made it works with java, it produces the following json :
"fulfillmentMessages": [
{
"payload": {
"facebook": {
"attachment": {
"payload": {
"is_reusable": true,
"url": "https://example.com/img/workflow.png"
},
"type": "image"
}
}
},
"platform": "FACEBOOK",
"sendAsMessage": true
},
{
"payload": {
"facebook": {
"quick_replies": [
{
"content_type": "user_phone_number"
}
],
"text": "📱 What is your cellphone ?"
}
},
"platform": "FACEBOOK",
"sendAsMessage": true
}
],
FYI, I made it works with java, it produces the following json :
"fulfillmentMessages": [ { "payload": { "facebook": { "attachment": { "payload": { "is_reusable": true, "url": "https://example.com/img/workflow.png" }, "type": "image" } } }, "platform": "FACEBOOK", "sendAsMessage": true }, { "payload": { "facebook": { "quick_replies": [ { "content_type": "user_phone_number" } ], "text": "📱 What is your cellphone ?" } }, "platform": "FACEBOOK", "sendAsMessage": true } ],
Have you created your own service or are you using the Java library for Dialogflow?
FYI, I made it works with java, it produces the following json :
"fulfillmentMessages": [ { "payload": { "facebook": { "attachment": { "payload": { "is_reusable": true, "url": "https://example.com/img/workflow.png" }, "type": "image" } } }, "platform": "FACEBOOK", "sendAsMessage": true }, { "payload": { "facebook": { "quick_replies": [ { "content_type": "user_phone_number" } ], "text": "📱 What is your cellphone ?" } }, "platform": "FACEBOOK", "sendAsMessage": true } ],
I've used this as a response to create a PR #325 trying to fix this issue. However, I've only tested it on Facebook Messager. It's my first day on Dialogflow. It would be great if there is someone to point me in the right direction if I am wrong.