From f83836211aeab91f84a7c3910d6ac0b81eea2f49 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Thu, 27 Sep 2018 17:09:52 -0700 Subject: [PATCH] Move docs to Dialogflow website Change-Id: I222f643d9f23f6cb171d8cdfc5c4e3e9c977c083 --- .gitignore | 4 +- README.md | 14 +- docs/Card.md | 111 --------- docs/Image.md | 55 ----- docs/Payload.md | 67 ------ docs/RichResponse.md | 28 --- docs/Suggestion.md | 55 ----- docs/Text.md | 72 ------ docs/V1Agent.md | 29 --- docs/V2Agent.md | 34 --- docs/WebhookClient.md | 275 ---------------------- script/generateDocs.js => generateDocs.js | 30 ++- package.json | 2 +- script/generateZip.js | 45 ---- 14 files changed, 31 insertions(+), 790 deletions(-) delete mode 100644 docs/Card.md delete mode 100644 docs/Image.md delete mode 100644 docs/Payload.md delete mode 100644 docs/RichResponse.md delete mode 100644 docs/Suggestion.md delete mode 100644 docs/Text.md delete mode 100644 docs/V1Agent.md delete mode 100644 docs/V2Agent.md delete mode 100644 docs/WebhookClient.md rename script/generateDocs.js => generateDocs.js (53%) delete mode 100644 script/generateZip.js diff --git a/.gitignore b/.gitignore index 9089886..a3c7cf8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ npm-debug.log log coverage *.tgz -package-lock.json \ No newline at end of file +package-lock.json +webhook-client.md +rich-responses.md \ No newline at end of file diff --git a/README.md b/README.md index b7ac6cd..be1674f 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,14 @@ Dialogflow Fulfillment makes creating fulfillment for Dialogflow v1 and v2 agent ![fulfillment library works with 8 platforms](https://raw.githubusercontent.com/dialogflow/dialogflow-fulfillment-nodejs/master/dialogflow-fulfillment-graphic.png "Dialogflow's fulfillment library works with 8 platforms") -## Current Library Support +## Supported features + Text + Cards + Images + Suggestion Chips (Quick Replies) + Payloads (Platform-specific responses) -This library is intended to help build Node.js Dialogflow Fulfillment for multiple [integrations](https://dialogflow.com/docs/integrations/) including Google Assistant, Slack, Facebook, Telegram, Kik, Skype, Line, and Viber. +This library is intended to help build Node.js Dialogflow Fulfillment for multiple [integrations](https://dialogflow.com/docs/integrations/) including Google Assistant, Slack, Facebook, Telegram, Kik, Skype, Line, and Viber. See the reference documentation for more: https://dialogflow.com/docs/reference/fulfillment-library/webhook-client If only building Dialogflow Fulfillment for the [Google Assistant](https://dialogflow.com/docs/integrations/google-assistant) and no other integrations, use the Actions of Google NPM module ([actions-on-google](https://www.npmjs.com/package/actions-on-google)) which supports all Actions on Google features. @@ -30,8 +30,8 @@ If only building Dialogflow Fulfillment for the [Google Assistant](https://dialo ## Setup Instructions - ```javascript - //Import the appropriate class +```javascript +// Import the appropriate class const { WebhookClient } = require('dialogflow-fulfillment'); //Create an instance @@ -39,8 +39,6 @@ const agent = new WebhookClient({request: request, response: response}); ``` ## Samples - - | Name | Language | | ------------------------------------ |:---------------------------------| |[Dialogflow Fulfillment & Actions on Google](https://github.com/dialogflow/fulfillment-actions-library-nodejs) | Node.js | @@ -50,12 +48,12 @@ const agent = new WebhookClient({request: request, response: response}); |[Multi-language/locale](https://github.com/dialogflow/fulfillment-multi-locale-nodejs)| Node.js | | [Dialogflow's Inline Editor Template](https://github.com/dialogflow/fulfillment-webhook-nodejs)| Node.js | - ## References & Issues + Questions? Try [StackOverflow](https://stackoverflow.com/questions/tagged/dialogflow) or [Dialogflow Developer Community](https://plus.google.com/communities/103318168784860581977). + For bugs, please report an issue on [Github](https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues). + Dialogflow [Documentation](https://docs.dialogflow.com). -+ Dialogflow [Classes Reference Doc](https://github.com/dialogflow/dialogflow-fulfillment-nodejs/tree/master/docs). ++ [Dialogflow WebhookClient class reference doc](https://dialogflow.com/docs/reference/fulfillment-library/webhook-client). ++ [Dialogflow rich response classes reference doc](https://dialogflow.com/docs/reference/fulfillment-library/webhook-client). + For more info on [Actions on Google NPM module](https://github.com/actions-on-google/actions-on-google-nodejs) + For more info on [Building Actions on Google with Dialogflow Agents Documentation](https://developers.google.com/actions/dialogflow/) diff --git a/docs/Card.md b/docs/Card.md deleted file mode 100644 index 63c65c3..0000000 --- a/docs/Card.md +++ /dev/null @@ -1,111 +0,0 @@ - - -## Card ⇐ [RichResponse](#RichResponse) -Class representing a card response - -**Kind**: global class -**Extends**: [RichResponse](#RichResponse) - -* [Card](#Card) ⇐ [RichResponse](#RichResponse) - * [new Card(card)](#new_Card_new) - * [.setTitle(title)](#Card+setTitle) ⇒ [Card](#Card) - * [.setText(text)](#Card+setText) ⇒ [Card](#Card) - * [.setImage(imageUrl)](#Card+setImage) ⇒ [Card](#Card) - * [.setButton(button)](#Card+setButton) ⇒ [Card](#Card) - * [.setPlatform(platform)](#RichResponse+setPlatform) ⇒ [RichResponse](#RichResponse) - - - -### new Card(card) -Constructor for Card object. - - -| Param | Type | Description | -| --- | --- | --- | -| card | string \| Object | response title string or an object representing a card response | - - - -### card.setTitle(title) ⇒ [Card](#Card) -Set the title for a Card - -**Kind**: instance method of [Card](#Card) - -| Param | Type | Description | -| --- | --- | --- | -| title | string | containing the title content | - -**Example** -```js -let card = new Card(); -card.setTitle('sample card title') -``` - - -### card.setText(text) ⇒ [Card](#Card) -Set the text for a Card - -**Kind**: instance method of [Card](#Card) - -| Param | Type | Description | -| --- | --- | --- | -| text | string | containing the card body text content | - -**Example** -```js -let card = new Card(); -card.setText('sample card body text') -``` - - -### card.setImage(imageUrl) ⇒ [Card](#Card) -Set the image for a Card - -**Kind**: instance method of [Card](#Card) - -| Param | Type | -| --- | --- | -| imageUrl | string | - -**Example** -```js -let card = new Card(); -card.setImage('https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png'); -``` - - -### card.setButton(button) ⇒ [Card](#Card) -Set the button for a Card - -**Kind**: instance method of [Card](#Card) - -| Param | Type | Description | -| --- | --- | --- | -| button | Object | JSON configuration | -| options.text | Object | button text | -| options.url | Object | button link URL | - -**Example** -```js -let card = new Card(); -card.setButton({ - text: 'button text', - url: 'https://assistant.google.com/' -}); -``` - - -### card.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [Card](#Card) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/Image.md b/docs/Image.md deleted file mode 100644 index fc03a9f..0000000 --- a/docs/Image.md +++ /dev/null @@ -1,55 +0,0 @@ - - -## Image ⇐ [RichResponse](#RichResponse) -Class representing a image response. - -**Kind**: global class -**Extends**: [RichResponse](#RichResponse) - -* [Image](#Image) ⇐ [RichResponse](#RichResponse) - * [new Image(image)](#new_Image_new) - * [.setImage(imageUrl)](#Image+setImage) ⇒ [Image](#Image) - * [.setPlatform(platform)](#RichResponse+setPlatform) ⇒ [RichResponse](#RichResponse) - - - -### new Image(image) -Constructor for Image object - - -| Param | Type | Description | -| --- | --- | --- | -| image | string \| Object | URL string or an object representing a image response | - - - -### image.setImage(imageUrl) ⇒ [Image](#Image) -Set the image for a Image - -**Kind**: instance method of [Image](#Image) - -| Param | Type | -| --- | --- | -| imageUrl | string | - -**Example** -```js -let image = new Image('https://example.com/placeholder.png'); -image.setImage('https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png'); -``` - - -### image.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [Image](#Image) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/Payload.md b/docs/Payload.md deleted file mode 100644 index 3d78584..0000000 --- a/docs/Payload.md +++ /dev/null @@ -1,67 +0,0 @@ - - -## Payload ⇐ [RichResponse](#RichResponse) -Class representing a payload response - -**Kind**: global class -**Extends**: [RichResponse](#RichResponse) - -* [Payload](#Payload) ⇐ [RichResponse](#RichResponse) - * [new Payload(platform, payload)](#new_Payload_new) - * [.setPayload(payload)](#Payload+setPayload) ⇒ [Payload](#Payload) - * [.setPlatform(platform)](#RichResponse+setPlatform) ⇒ [RichResponse](#RichResponse) - - - -### new Payload(platform, payload) -Constructor for Payload object - - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | string indicating target platform of payload | -| payload | Object | contents for indicated platform | - - - -### payload.setPayload(payload) ⇒ [Payload](#Payload) -Set the payload contents for a Payload - -**Kind**: instance method of [Payload](#Payload) - -| Param | Type | -| --- | --- | -| payload | string | - -**Example** -```js -const googlePayloadJson = { - expectUserResponse: true, - isSsml: false, - noInputPrompts: [], - richResponse: { - items: [{ simpleResponse: { textToSpeech: 'hello', displayText: 'hi' } }] - }, - systemIntent: { - intent: 'actions.intent.OPTION', - } -} -let payload = new Payload(PLATFORMS.ACTIONS_ON_GOOGLE, {}); -payload.setPayload(googlePayloadJson); -``` - - -### payload.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [Payload](#Payload) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/RichResponse.md b/docs/RichResponse.md deleted file mode 100644 index 766ab66..0000000 --- a/docs/RichResponse.md +++ /dev/null @@ -1,28 +0,0 @@ - - -## RichResponse -Class representing a rich response - -These classes construct v1&v2 message objects for Dialogflow -v1 Message object docs: -https://dialogflow.com/docs/reference/agent/message-objects -v2 Message object docs: -https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/projects.agent.intents#Message - -**Kind**: global class - - -### richResponse.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [RichResponse](#RichResponse) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/Suggestion.md b/docs/Suggestion.md deleted file mode 100644 index 3b2135b..0000000 --- a/docs/Suggestion.md +++ /dev/null @@ -1,55 +0,0 @@ - - -## Suggestion ⇐ [RichResponse](#RichResponse) -Class representing a suggestions response - -**Kind**: global class -**Extends**: [RichResponse](#RichResponse) - -* [Suggestion](#Suggestion) ⇐ [RichResponse](#RichResponse) - * [new Suggestion(suggestion)](#new_Suggestion_new) - * [.setReply(reply)](#Suggestion+setReply) ⇒ [Suggestion](#Suggestion) - * [.setPlatform(platform)](#RichResponse+setPlatform) ⇒ [RichResponse](#RichResponse) - - - -### new Suggestion(suggestion) -Constructor for Suggestion object - - -| Param | Type | Description | -| --- | --- | --- | -| suggestion | string \| Object | title string or an object representing a suggestion response | - - - -### suggestion.setReply(reply) ⇒ [Suggestion](#Suggestion) -Set the reply for a Suggestion - -**Kind**: instance method of [Suggestion](#Suggestion) - -| Param | Type | -| --- | --- | -| reply | string | - -**Example** -```js -let suggestion = new Suggestion('reply to be overwritten'); -suggestion.setReply('reply overwritten'); -``` - - -### suggestion.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [Suggestion](#Suggestion) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/Text.md b/docs/Text.md deleted file mode 100644 index f80a8c8..0000000 --- a/docs/Text.md +++ /dev/null @@ -1,72 +0,0 @@ - - -## Text ⇐ [RichResponse](#RichResponse) -Class representing a text response - -**Kind**: global class -**Extends**: [RichResponse](#RichResponse) - -* [Text](#Text) ⇐ [RichResponse](#RichResponse) - * [new Text(text)](#new_Text_new) - * [.setText(text)](#Text+setText) ⇒ [Text](#Text) - * [.setSsml(ssml)](#Text+setSsml) ⇒ [Text](#Text) - * [.setPlatform(platform)](#RichResponse+setPlatform) ⇒ [RichResponse](#RichResponse) - - - -### new Text(text) -Constructor for Text object - - -| Param | Type | Description | -| --- | --- | --- | -| text | string \| Object | response string or an object representing a text response | - - - -### text.setText(text) ⇒ [Text](#Text) -Set the text for a Text - -**Kind**: instance method of [Text](#Text) - -| Param | Type | Description | -| --- | --- | --- | -| text | string | containing the text response content | - -**Example** -```js -let text = new Text(); -text.setText('sample text response') -``` - - -### text.setSsml(ssml) ⇒ [Text](#Text) -Set the SSML for a Text - -**Kind**: instance method of [Text](#Text) - -| Param | Type | Description | -| --- | --- | --- | -| ssml | string | containing the SSML response content | - -**Example** -```js -let text = new Text(); -text.setSsml('This is SSML.') -``` - - -### text.setPlatform(platform) ⇒ [RichResponse](#RichResponse) -Set the platform for a specific RichResponse (optional) - -**Kind**: instance method of [Text](#Text) - -| Param | Type | Description | -| --- | --- | --- | -| platform | string | representing desired rich response target platform | - -**Example** -```js -let richResponse = new RichResponse(); -richResponse.setPlatform(PLATFORMS.ACTIONS_ON_GOOGLE) -``` diff --git a/docs/V1Agent.md b/docs/V1Agent.md deleted file mode 100644 index 6f43f19..0000000 --- a/docs/V1Agent.md +++ /dev/null @@ -1,29 +0,0 @@ - - -## V1Agent -Class representing a v1 Dialogflow agent - -**Kind**: global class - -* [V1Agent](#V1Agent) - * [new V1Agent(agent)](#new_V1Agent_new) - * [.end_()](#V1Agent+end_) - - - -### 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](#V1Agent) diff --git a/docs/V2Agent.md b/docs/V2Agent.md deleted file mode 100644 index ac8598b..0000000 --- a/docs/V2Agent.md +++ /dev/null @@ -1,34 +0,0 @@ - - -## V2Agent -Class representing a v2 Dialogflow agent - -**Kind**: global class - -* [V2Agent](#V2Agent) - * [new V2Agent(agent)](#new_V2Agent_new) - * [.end_(responses)](#V2Agent+end_) - - - -### 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](#V2Agent) - -| Param | Type | Description | -| --- | --- | --- | -| responses | [RichResponse](#RichResponse) \| string \| [Array.<RichResponse>](#RichResponse) \| Array.<string> | (list) or single responses | - diff --git a/docs/WebhookClient.md b/docs/WebhookClient.md deleted file mode 100644 index d6532b2..0000000 --- a/docs/WebhookClient.md +++ /dev/null @@ -1,275 +0,0 @@ - - -## 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 - -* [WebhookClient](#WebhookClient) - * [new WebhookClient(options)](#new_WebhookClient_new) - * [.agentVersion](#WebhookClient+agentVersion) : number - * [.intent](#WebhookClient+intent) : string - * [.action](#WebhookClient+action) : string - * [.parameters](#WebhookClient+parameters) : Object - * [.contexts](#WebhookClient+contexts) : string - * [.requestSource](#WebhookClient+requestSource) : string - * [.originalRequest](#WebhookClient+originalRequest) : object - * [.query](#WebhookClient+query) : string - * [.locale](#WebhookClient+locale) : string - * [.session](#WebhookClient+session) : string - * [.consoleMessages](#WebhookClient+consoleMessages) : [Array.<RichResponse>](#RichResponse) - * [.alternativeQueryResults](#WebhookClient+alternativeQueryResults) : object - * [.add(responses)](#WebhookClient+add) - * [.end(responses)](#WebhookClient+end) - * [.addResponse_(response)](#WebhookClient+addResponse_) - * [.handleRequest(handler)](#WebhookClient+handleRequest) ⇒ Promise - * [.setContext(context)](#WebhookClient+setContext) ⇒ [WebhookClient](#WebhookClient) - * [.clearOutgoingContexts()](#WebhookClient+clearOutgoingContexts) ⇒ [WebhookClient](#WebhookClient) - * [.clearContext(context)](#WebhookClient+clearContext) ⇒ [WebhookClient](#WebhookClient) - * [.getContext(contextName)](#WebhookClient+getContext) ⇒ Object - * [.setFollowupEvent(event)](#WebhookClient+setFollowupEvent) - * [.conv()](#WebhookClient+conv) ⇒ DialogflowConversation \| null - - - -### 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) - - -### webhookClient.intent : string -Dialogflow intent name or null if no value: https://dialogflow.com/docs/intents - -**Kind**: instance property of [WebhookClient](#WebhookClient) - - -### webhookClient.action : string -Dialogflow action or null if no value: https://dialogflow.com/docs/actions-and-parameters - -**Kind**: instance property of [WebhookClient](#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) - - -### 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) - - -### 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) - - -### 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) - - -### webhookClient.query : string -Original user query as indicated by Dialogflow or null if no value - -**Kind**: instance property of [WebhookClient](#WebhookClient) - - -### webhookClient.locale : string -Original request language code or locale (i.e. "en" or "en-US") - -**Kind**: instance property of [WebhookClient](#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) - - -### webhookClient.consoleMessages : [Array.<RichResponse>](#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) - - -### 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) - - -### webhookClient.add(responses) -Add a response or list of responses to be sent to Dialogflow - -**Kind**: instance method of [WebhookClient](#WebhookClient) - -| Param | Type | Description | -| --- | --- | --- | -| responses | [RichResponse](#RichResponse) \| string \| [Array.<RichResponse>](#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](#WebhookClient) - -| Param | Type | Description | -| --- | --- | --- | -| responses | [RichResponse](#RichResponse) \| string \| [Array.<RichResponse>](#RichResponse) \| Array.<string> | (list) or single responses | - - - -### webhookClient.addResponse_(response) -Private method to add a response to be sent to Dialogflow - -**Kind**: instance method of [WebhookClient](#WebhookClient) - -| Param | Type | Description | -| --- | --- | --- | -| response | [RichResponse](#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](#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](#WebhookClient) -Set a new Dialogflow outgoing context: https://dialogflow.com/docs/contexts - -**Kind**: instance method of [WebhookClient](#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](#WebhookClient) -Clear all existing outgoing contexts: https://dialogflow.com/docs/contexts - -**Kind**: instance method of [WebhookClient](#WebhookClient) -**Example** -```js -const { WebhookClient } = require('dialogflow-webhook'); -const agent = new WebhookClient({request: request, response: response}); -agent.clearOutgoingContexts(); -``` - - -### webhookClient.clearContext(context) ⇒ [WebhookClient](#WebhookClient) -Clear an existing outgoing context: https://dialogflow.com/docs/contexts - -**Kind**: instance method of [WebhookClient](#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](#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](#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](#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); -``` diff --git a/script/generateDocs.js b/generateDocs.js similarity index 53% rename from script/generateDocs.js rename to generateDocs.js index 5ef7b6a..99b0798 100644 --- a/script/generateDocs.js +++ b/generateDocs.js @@ -23,16 +23,28 @@ const jsdoc2md = require('jsdoc-to-markdown'); const inputFiles = ['./src/*.js', './src/rich-responses/*.js']; const outputDir = './docs/'; +const webhookFilename = 'webhook-client.md'; +const webhookClientClassNames = ['WebhookClient', 'V2Agent', 'V1Agent']; +const richResponseFilename = 'rich-responses.md' +const richRepsonseClassNames = [ 'RichResponse', 'Card', 'Suggestion', 'Image', 'Payload', 'Text']; + const templateData = jsdoc2md.getTemplateDataSync({files: inputFiles}); -const classNames = templateData.reduce((classNames, identifier) => { - if (identifier.kind === 'class') { -classNames.push(identifier.name); -}; - return classNames; -}, []); -for (const className of classNames) { +let output = '' +for (const className of webhookClientClassNames) { const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`; - const output = jsdoc2md.renderSync({data: templateData, template: template}); - fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output); + output += jsdoc2md.renderSync({data: templateData, template: template}); + fs.writeFileSync(webhookFilename, output); } + +output = '' +for (const className of richRepsonseClassNames) { + const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`; + output += jsdoc2md.renderSync({data: templateData, template: template}); + fs.writeFileSync(richResponseFilename, output); +} + +exports.rewriteAnchor = function (anchor) { + if (typeof anchor !== 'string') return null; + return anchor.toLowerCase().replace('+', '_'); +}; diff --git a/package.json b/package.json index 2b86394..509ddb8 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "scripts": { "test": "npm run lint && ava", "lint": "eslint --fix \"src/**/*.js\" \"test/*.js\" \"script/*.js\"", - "docs": "node ./script/generateDocs.js", + "docs": "node ./generateDocs.js", "zip": "npm run zip:actions-on-google && npm run zip:multilocale && npm run zip:temperature-converter && npm run zip:quick-start", "zip:actions-on-google": "node ./script/generateZip.js --indexjs ./samples/actions-on-google/functions/index.js --packagejson ./samples/actions-on-google/functions/package.json --agentzip ./samples/actions-on-google/actions-on-google-agent.zip", "zip:multilocale": "node ./script/generateZip.js --indexjs ./samples/multi-lang-and-locale/functions/index.js --packagejson ./samples/multi-lang-and-locale/functions/package.json --agentzip ./samples/multi-lang-and-locale/multilocale-agent.zip", diff --git a/script/generateZip.js b/script/generateZip.js deleted file mode 100644 index 396e364..0000000 --- a/script/generateZip.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2018 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -'use strict'; - -const fs = require('fs'); -const JSZip = require('jszip'); -const program = require('commander'); - -program - .option( - '-i, --indexjs ', - 'Path to index.js file to fill in the inline editor' - ) - .option( - '-p, --packagejson ', - 'Path to package.json file to fill in the inline editor' - ) - .option('-a, --agentzip ', 'Path to exported Dialogflow agent ZIP') - .parse(process.argv); - -const zipData = fs.readFileSync(program.agentzip); -const indexData = fs.readFileSync(program.indexjs); -const packageData = fs.readFileSync(program.packagejson); - -JSZip.loadAsync(zipData).then(function(zip) { - let folder = zip.folder('functions'); - folder.file('functions_index.js', indexData); - folder.file('functions_package.json', packageData); - return zip.generateAsync({type: 'binarystring'}).then(function(blob) { - fs.writeFileSync(program.agentzip, blob, 'binary'); - }); -});