Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Multiple agent.add fails with integrations #177

Open
sarupbanskota opened this issue Nov 3, 2018 · 14 comments
Open

Multiple agent.add fails with integrations #177

sarupbanskota opened this issue Nov 3, 2018 · 14 comments
Labels
Feature Request New feature or request

Comments

@sarupbanskota
Copy link

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 #173, #35 and #146 which appear related.

What do you suggest I try?

@dadisigursveinn
Copy link

What is the use case for having multiple custom payloads?

@sarupbanskota
Copy link
Author

sarupbanskota commented Nov 10, 2018

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
Copy link
Author

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

@mattcarrollcode mattcarrollcode added the Feature Request New feature or request label Nov 13, 2018
@Ashwin-Kapes
Copy link

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

@maganap
Copy link

maganap commented Dec 18, 2018

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.

@jdpt0
Copy link

jdpt0 commented Dec 18, 2018

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

@maganap
Copy link

maganap commented Dec 18, 2018

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

@thomaslombart
Copy link

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!

@edersonbolognatrt15
Copy link

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.

@supachailllpay
Copy link

supachailllpay commented Jun 4, 2019

Since multiple custom payloads are allowed on Dialogflow UI. I see no reason to limit only for single payload here.

addResponse_(response) {
if (typeof response === 'string') {
response = new Text(response);
}
if (response instanceof DialogflowConversation) {
this.client.addActionsOnGoogle_(response.serialize());
} else if (response instanceof Suggestion && this.existingSuggestion_(response.platform)) {
this.existingSuggestion_(response.platform).addReply_(response.replies[0]);
} else if (response instanceof Payload && this.existingPayload_(response.platform)) {
throw new Error(`Payload response for ${response.platform} already defined.`);
} else if (response instanceof RichResponse) {
this.responseMessages_.push(response);
} else {
throw new Error(`Unknown response type: "${JSON.stringify(response)}"`);
}
}

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.

@hcharley
Copy link

hcharley commented Aug 8, 2019

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

@cbeaujoin
Copy link

cbeaujoin commented Aug 14, 2019

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

@tohure
Copy link

tohure commented Aug 16, 2019

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?

@charleswong28
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests