WebhookClient

This is the class that handles the communication with Dialogflow's webhook fulfillment API v1 & v2 with support for rich responses across 8 platforms and Dialogflow's simulator

Kind: global class

new WebhookClient(options)

Constructor for WebhookClient object To be used in the Dialogflow fulfillment webhook logic

Param Type Description
options Object JSON configuration.
options.request Object Express HTTP request object.
options.response Object Express HTTP response object.

webhookClient.agentVersion : number

The agent version (v1 or v2) based on Dialogflow webhook request https://dialogflow.com/docs/reference/v2-comparison

Kind: instance property of WebhookClient

webhookClient.intent : string

Dialogflow intent name or null if no value: https://dialogflow.com/docs/intents

Kind: instance property of WebhookClient

webhookClient.action : string

Dialogflow action or null if no value: https://dialogflow.com/docs/actions-and-parameters

Kind: instance property of WebhookClient

webhookClient.parameters : Object

Dialogflow parameters included in the request or null if no value https://dialogflow.com/docs/actions-and-parameters

Kind: instance property of WebhookClient

webhookClient.contexts : string

Dialogflow contexts included in the request or null if no value https://dialogflow.com/docs/contexts

Kind: instance property of WebhookClient

webhookClient.requestSource : string

Dialogflow source included in the request or null if no value https://dialogflow.com/docs/reference/agent/query#query_parameters_and_json_fields

Kind: instance property of WebhookClient

webhookClient.originalRequest : object

Dialogflow original request object from detectIntent/query or platform integration (Google Assistant, Slack, etc.) in the request or null if no value https://dialogflow.com/docs/reference/agent/query#query_parameters_and_json_fields

Kind: instance property of WebhookClient

webhookClient.query : string

Original user query as indicated by Dialogflow or null if no value

Kind: instance property of WebhookClient

webhookClient.locale : string

Original request language code or locale (i.e. "en" or "en-US")

Kind: instance property of WebhookClient

webhookClient.session : string

Dialogflow input contexts included in the request or null if no value Dialogflow v2 API only https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/WebhookRequest#FIELDS.session

Kind: instance property of WebhookClient

webhookClient.consoleMessages : Array.<RichResponse>

List of messages defined in Dialogflow's console for the matched intent https://dialogflow.com/docs/rich-messages

Kind: instance property of WebhookClient

webhookClient.alternativeQueryResults : object

List of alternative query results Query results can be from other Dialogflow intents or Knowledge Connectors https://cloud.google.com/dialogflow-enterprise/alpha/docs/knowledge-connectors Note:this feature only availbe in Dialogflow v2

Kind: instance property of WebhookClient

webhookClient.add(responses)

Add a response or list of responses to be sent to Dialogflow

Kind: instance method of WebhookClient

Param Type Description
responses RichResponse | string | Array.<RichResponse> | Array.<string> (list) or single responses

webhookClient.end(responses)

Add a response or list of responses to be sent to Dialogflow and end the conversation Note: Only supported on Dialogflow v2's telephony gateway, Google Assistant and Alexa integrations

Kind: instance method of WebhookClient

Param Type Description
responses RichResponse | string | Array.<RichResponse> | Array.<string> (list) or single responses

webhookClient.addResponse_(response)

Add a response to be sent to Dialogflow Private method to add a response to be sent to Dialogflow

Kind: instance method of WebhookClient

Param Type Description
response RichResponse | string an object or string representing the rich response to be added

webhookClient.handleRequest(handler) ⇒ Promise

Handles the incoming Dialogflow request using a handler or Map of handlers Each handler must be a function callback.

Kind: instance method of WebhookClient

Param Type Description
handler Map | requestCallback map of Dialogflow action name to handler function or function to handle all requests (regardless of Dialogflow action).

webhookClient.setContext(context) ⇒ WebhookClient

Set a new Dialogflow outgoing context: https://dialogflow.com/docs/contexts

Kind: instance method of WebhookClient

Param Type Description
context string | Object name of context or an object representing a context

Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); agent.setContext('sample context name'); const context = {'name': 'weather', 'lifespan': 2, 'parameters': {'city': 'Rome'}}; agent.setContext(context);

webhookClient.clearOutgoingContexts() ⇒ WebhookClient

Clear all existing outgoing contexts: https://dialogflow.com/docs/contexts

Kind: instance method of WebhookClient
Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); agent.clearOutgoingContexts();

webhookClient.clearContext(context) ⇒ WebhookClient

Clear an existing outgoing context: https://dialogflow.com/docs/contexts

Kind: instance method of WebhookClient

Param Type Description
context string name of an existing outgoing context

Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); agent.clearContext('sample context name');

webhookClient.getContext(contextName) ⇒ Object

Get an context from the Dialogflow webhook request: https://dialogflow.com/docs/contexts

Kind: instance method of WebhookClient
Returns: Object - context context object with the context name

Param Type Description
contextName string name of an context present in the Dialogflow webhook request

Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); let context = agent.getContext('sample context name');

webhookClient.setFollowupEvent(event)

Set the followup event

Kind: instance method of WebhookClient

Param Type Description
event string | Object string with the name of the event or an event object

Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); let event = agent.setFollowupEvent('sample event name');

webhookClient.conv() ⇒ DialogflowConversation | null

Get Actions on Google DialogflowConversation object

Kind: instance method of WebhookClient
Returns: DialogflowConversation | null - DialogflowConversation object or null
Example
js const { WebhookClient } = require('dialogflow-webhook'); const agent = new WebhookClient({request: request, response: response}); let conv = agent.conv(); conv.ask('Hi from the Actions on Google client library'); agent.add(conv);

V2Agent

Class representing a v2 Dialogflow agent

Kind: global class

new V2Agent(agent)

Constructor for V2Agent object To be used in with WebhookClient class

Param Type Description
agent Object instance of WebhookClient class

v2Agent.end_(responses)

Add a response or list of responses to be sent to Dialogflow and end the conversation Note: Only supported on Dialogflow v2's telephony gateway, Google Assistant and Alexa integrations

Kind: instance method of V2Agent

Param Type Description
responses RichResponse | string | Array.<RichResponse> | Array.<string> (list) or single responses

V1Agent

Class representing a v1 Dialogflow agent

Kind: global class

new V1Agent(agent)

Constructor for V1Agent object To be used in with WebhookClient class

Param Type Description
agent Object instance of WebhookClient class

v1Agent.end_()

Add a response or list of responses to be sent to Dialogflow and end the conversation Note: not support on v1

Kind: instance method of V1Agent