Google Assistant Adapter

This document explains how to use the Google Assistant Adapter adapter.

Installation

In your botfuel project, run :

npm install --save botfuel-module-adapter-assistant

Set-up

Botfuel

Create a new config file in the root directory of your project (e.g. assistant-config.js)

module.exports = {
  adapter: {
    name: 'assistant',
  },
  modules: ['botfuel-module-adapter-assistant']
};

Assistant

In order to make your bot work with the assistant, you need to create an action.json file.

{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "<YOUR_APP_NAME>"
      },
      "intent": {
        "name": "actions.intent.MAIN",
        "trigger": {
          "queryPatterns": [
            "talk to <YOUR_APP_NAME>"
          ]
        }
      }
    }
  ],
  "conversations": {
    "<YOUR_APP_NAME>": {
      "name": "<YOUR_APP_NAME>",
      "url": "<YOUR_BOT_URL>/webhook"
    }
  },
  "locale": "en"
}

Once your have this file, you need to deploy it using the gactions CLI.

gactions update --action_package action.json --project <YOUR_GOOGLE_ACTIONS_PROJECT_ID>

For more information on how to use gactions, visit this link https://developers.google.com/actions/tools/gactions-cli

You can then run your bot with your new config file.

BOTFUEL_APP_TOKEN=<YOUR_APP_TOKEN> BOTFUEL_APP_ID=<YOUR_APP_ID> BOTFUEL_APP_KEY=<YOUR_APP_KEY> npm start assistant-config.js

If you use Windows Powershell, use this command instead:

$Env:BOTFUEL_APP_TOKEN=<YOUR_APP_TOKEN>; $Env:BOTFUEL_APP_ID=<YOUR_APP_ID>; $Env:BOTFUEL_APP_KEY=<YOUR_APP_KEY>; npm start assistant-config.js

Message types supported

The assistant adapter supports the following types of messages:

  • BotImageMessage
  • BotTextMessage
  • CardsMessage
  • QuickRepliesMessage
  • UserTextMessage

Adapt your bot

In order to make your bot compatible with Google Assistant, you need to follow certain rules.

Should I stay or should I go?

Depending on the situation, you may want to close the conversation or let it open. By default, a conversation is closed right after the bot responds, except in certain specific cases like QuickReplies.

You can force your bot to wait for an answer with the question parameter

new BotTextMessage("How are you doing?", {question: true});

Assistant required parameters

Some Google Assistant message types require specific parameters. For example, in addition to the card list, cards require a text and a speech. You can add them as a second parameter of the CardMessage constructor.

new CardsMessage(cards, { speech: 'Hello', text: 'Hello' })

See Module Overview for more information on how to create and use a module.