diff --git a/src/dialogflow-fulfillment.js b/src/dialogflow-fulfillment.js index dcaf489..416ce48 100644 --- a/src/dialogflow-fulfillment.js +++ b/src/dialogflow-fulfillment.js @@ -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 diff --git a/src/v2-agent.js b/src/v2-agent.js index df0e69a..2c036aa 100644 --- a/src/v2-agent.js +++ b/src/v2-agent.js @@ -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); @@ -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