Blog

Custom greeting Google Assistant app with Dialogflow and Actions on Google

Posted on in 

Let’s have a look into how you can create custom dynamic Welcome messages for your Google Assistant with Dialogflow and Actions on Google.

  1. First open your Dialogflow Console.

  2. Create a new Intent with the following settings: Intent name: [bot-first-greeting]

  3. Events: Choose Google Assistant Welcome

  4. Training Phrases: Empty

  5. Fulfillment: Enable Webhook call for intent Click Save.

  6. For the code I am using Google Cloud functions. Please see also my previous post.

Your Google Cloud Function could like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict'; 
const { dialogflow } = require('actions-on-google'); //npm actions-on-google 2.1.1
const welcomeHandler = (conv) => {
var today = new Date();
var curHr = today.getHours();
var greet = "";
if( curHr < 12 ) {
greet = "Good morning!";
} else if (curHr < 18) {
greet = "Good afternoon!";
} else {
greet = "Good evening!";
}

conv.ask(greet);
};

const app = dialogflow();
app.intent('[bot-first-greeting]', welcomeHandler);
exports.index = app;

Click the Fulfillment menu item, and make sure the URL points to your Google Cloud function. Assuming that you linked the Actions on Google already in the Integrations tab; move back to your Actions on Google simulator, and refresh your app. When you start your Google Assistant app, it will greet you, based on the time of the day.

Obviously, this is a simple example, but this can become more interesting, when loading profile information or previous contexts before starting your app.

Comments