Architecture and Integration - SilasBerger/coachbot-brain GitHub Wiki

This page describes the overall architecture of the services used.

Chat integration

To be added. Chat integration is set up in the Dialogflow dashboard, to tunnel conversations between Dialogflow and some supported chat clients, such as Facebook Messenger, Telegram, and Google Home. Each of these clients requires addional setup for Dialogflow.

Connecting Dialogflow to webhook

To set up a web hook, open the "Fulfillment" tab in the Dialogflow dashboard, enable Webhook, enter the exact URL of the intended webhook endpoint, and set "Domains" to "Enable webhook for all domains". Note that all webhook requests will be POSTed to a single endpoint, containing all the relevant information, such as parsed intent/action, context objects, etc. Also note that the URL must be publicly available.

To set up a web hook, use some kind of web development framework, that supports RESTful development. In this case, I am using Express.js on Node. Set up the basic project, then add a POST endpoint that matches the URL you entered in the Dialogflow Fulfillment section (for example, if the URL is https://www.myapp.com/chatbot, create a POST endpoint /chatbot). Lastly, enable "use webkook" for all intents that are supposed to use the webhook. If the webhook-generated answer is to be sent to the user, it might be necessary to delete (or not set any) default answers.

The message flow of a single user input is as follows: [user sends message through integration platform] -> [message is transported to Dialogflow] -> [message is interpreted, intention and context are parsed] -> [parsed information is packed into a JSON and POSTed to the webhook URL] -> [webhook performs custom business logic and compiles a response payload, including a speech response] -> [response object is returned to Dialogflow] -> [maybe Dialogflow can take information from response, such as new contexts...?] -> [speech response is forwarded to the user through integration platform]

Currently, the relevant API version is v1.0. This is relevant when reading documentation on webhook request and response payloads.

If using Express.js, install body-parser, the get easy access to the request payload. Some important fields of the request include result.action (what action does the user want to express) and result.contexts (an array of context-relevant information).