How to add Google Assistant Channel to Bot Framework

Oussama Tekaya
satoripop
Published in
3 min readOct 16, 2018

--

Bot Framework natively supports several discussion channels which allows you to distribute your bot on almost all messaging platforms. On top of that, the bot framework offers Direct Line as support for unsupported native channels.

We will see in this blog post how to use DirectLine and a node js middleware to create a connection between Google Assistant (deployed today on smartphones and Google Home speakers) and Bot Framework.

Create a new Actions on Google (AoG) project

In order to use the Google Assistant channel, you must first create a new AoG project.

● Go to AoG Console

● Click on Create Project, choose More Options and click on Actions SDK

● Copy the following command


gactions update — action_package PACKAGE_NAME — project aog-with-bot-framework

Note that aog-with-bot-framework is the identifier of the project generated automatically during its creation and that you can find it in the parameters

Next steps will be outside the console:

● Download Google Actions CLI from here

● Create project configuration files for as many languages as you have. The file structure is as follows :

{
"actions": [{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": " MAIN_CONVERSATION"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"talk to INVOCATION_NAME"
]
}
}
}],
"conversations": {
" MAIN_CONVERSATION": {
"name": "MAIN_CONVERSATION",
"url": "FULLFILLMENT_URL "
}
},
"locale": "LOCALE"
}

● MAIN_CONVERSATION : Conversation Name

● INVOCATION_NAME : How our project will be invoked

● FULLFILLMENT_URL : Node JS Middleware URL (more details later )

● LOCALE : project language (EN, FR etc.)

As mentioned, there will be as many files as supported languages (For a project that supports English and French, we will have the files action.en.js and action.fr.js)

After configuring the files, we run the following command:

gactions update — action_package action.en.js — action_package action.fr.js — project aog-with-bot-framework

Note the two configuration json files

Create the chatbot

The chatbot itself does not require any specific manipulation. You just have to create a chatbot using Visual Studio (if you use C#) and deploy it on Azure. You will just need to activate the DirectLine channel and copy the key that will be generated.

Deploying Node JS Middleware

In order for our project to be able to chat with our chatbot, it will be necessary to use the bot-framework-actions-on-google middleware which allows to connect Actions on Google with the DirectLine channel and which is available here.

So, the idea is to create a simple node js application that exposes an endpoint that will be called by our actions on google project and that sends the request to the DirectLine channel.

The following code snippet is all we need :

const express = require(“express”);
const actionsOnGoogleAdapter = require(“bot-framework-actions-on-google”);

const app = express();

app.use(actionsOnGoogleAdapter(<DIRECT_LINE_SECRET>).router);

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`ActionsOnGoogle demo listening on port ${PORT}!`));

● DIRECT_LINE_SECRET : The generated DirectLine key

Then, you will have to deploy the application, copy its URL and paste it into the json file of the AoG project at the parameter FULLFILLMENT_URL. Assuming you have already deployed your project, do not forget to update it by running again the command

gactions update — action_package action.en.js — action_package action.fr.js — project aog-with-bot-framework

And voila. You can now test your bot from the AoG console simulator.

--

--