dialogflow-fulfillment-nodejs icon indicating copy to clipboard operation
dialogflow-fulfillment-nodejs copied to clipboard

Multiple agent.add fails with integrations

Open sarupbanskota opened this issue 7 years ago • 14 comments

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?

sarupbanskota avatar Nov 03 '18 04:11 sarupbanskota

What is the use case for having multiple custom payloads?

dadisigursveinn avatar Nov 04 '18 14:11 dadisigursveinn

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?

sarupbanskota avatar Nov 10 '18 13:11 sarupbanskota

Also, breaking down a larger message into 3 different messages within a handler.

sarupbanskota avatar Nov 11 '18 03:11 sarupbanskota

I'm facing same issue. Don't know why this library does not support multiple payload.

Ashwin-Kapes avatar Dec 01 '18 12:12 Ashwin-Kapes

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.

maganap avatar Dec 18 '18 11:12 maganap

#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 .

jdpt0 avatar Dec 18 '18 11:12 jdpt0

@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}));

maganap avatar Dec 18 '18 14:12 maganap

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!

thomaslombart avatar Feb 19 '19 14:02 thomaslombart

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.

edersonbolognatrt15 avatar May 24 '19 15:05 edersonbolognatrt15

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.

supachailllpay avatar Jun 04 '19 23:06 supachailllpay

I might have time to work on this and open a PR. Any advice or pointers for someone new to the project?

hcharley avatar Aug 08 '19 01:08 hcharley

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
		}
	],

cbeaujoin avatar Aug 14 '19 11:08 cbeaujoin

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?

tohure avatar Aug 16 '19 05:08 tohure

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.

charleswong28 avatar Nov 01 '20 11:11 charleswong28