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

Ability to add custom Fulfillment text #96

Open
wants to merge 2 commits 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
18 changes: 18 additions & 0 deletions src/dialogflow-fulfillment.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,24 @@ class WebhookClient {
getContext(contextName) {
return this.contexts.filter( (context) => context.name === contextName )[0] || null;
}

/**
* Set the fulfillmentText
*
* @example
* const { WebhookClient } = require('dialogflow-webhook');
* const agent = new WebhookClient({request: request, response: response});
* let context = agent.setFulfillmentText('sample fulfillment text');
*
* @param {string} text a string representing the fulfillmentText
*/
setFulfillmentText(text) {
if (typeof text !== 'string' || !text) {
throw new Error('Fulfillment text must be a string');
}

this.client.setFulfillmentText_(text);
}

/**
* Set the followup event
Expand Down
11 changes: 11 additions & 0 deletions src/v2-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class V2Agent {
sendJson_(responseJson) {
responseJson.outputContexts = this.agent.outgoingContexts_;
this.agent.followupEvent_ ? responseJson.followupEventInput = this.agent.followupEvent_ : undefined;
this.agent.fulfillmentText_ ? responseJson.fulfillmentText = this.agent.fulfillmentText_ : undefined;

debug('Response to Dialogflow: ' + JSON.stringify(responseJson));
this.agent.response_.json(responseJson);
Expand Down Expand Up @@ -259,6 +260,16 @@ class V2Agent {
v1Context.parameters = v2Context.parameters;
return v1Context;
}

/**
* Add a v2 fulfillmentText
*
* @param {string} text a string representing the fulfillmentText
* @private
*/
setFulfillmentText_(text) {
this.agent.fulfillmentText_ = text;
}

/**
* Add an v2 followup event
Expand Down