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

Fixes #35 Multiple messages not supported with payloads #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/dialogflow-fulfillment.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ class WebhookClient {
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) {
} else if (response instanceof Payload || response instanceof RichResponse) {
this.responseMessages_.push(response);
} else {
throw new Error(`Unknown response type: "${JSON.stringify(response)}"`);
Expand Down Expand Up @@ -492,16 +490,18 @@ class WebhookClient {
// if platform may support messages, send messages
// if there is a payload, send the payload for the repsonse
const payload = this.existingPayload_(requestSource);
if (payload && !payload.sendAsMessage) {
this.client.addPayloadResponse_(payload, requestSource);
}

if (messages.length === 1 &&
messages[0] instanceof Text) {
this.client.addTextResponse_();
} else if (SUPPORTED_RICH_MESSAGE_PLATFORMS.indexOf(this.requestSource) > -1
|| SUPPORTED_PLATFORMS.indexOf(this.requestSource) < 0) {
this.client.addMessagesResponse_(requestSource);
}
if (payload && !payload.sendAsMessage) {
this.client.addPayloadResponse_(payload, requestSource);
}

this.client.sendResponses_(requestSource);
}

Expand Down
1 change: 1 addition & 0 deletions src/rich-responses/payload-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Payload extends RichResponse {
return {
payload: this.getPayload_(this.platform),
platform: this.platform,
sendAsMessage: true,
};
}
}
Expand Down