Google Action Push Notifications
Learn more about how to send push notifications to your users.
- User Permission
- Notification Object
- Notification Module
- Access Token
- Send the Notification
The Push Notifications feature allows you to send user's notifications, which if tapped, triggers a predefined intent of your Google Action.
Before being able to send out notifications to your user, you have to first have them opt-in to receive notifications for a specific intent. Only then, can you send out notifications for that specific intent to be triggered.
The process to send out notifications has the following four steps:
- Configure your Google Action to support notifications
- Ask the user to opt in
- Prepare the notification you want to send
- Get the access token needed to send out notifications
- Send out the actual notification.
First of all, you have to make the necessary configurations to send out notifications.
You have to specify the intents, which support notifications, by first adding them to the set of intents, which can be triggered by implicit invocations inside your Dialogflow Agent:
After you've done that, you can find the intent as one of your
Actions on your Google Actions
Select the intent and at the bottom of the tab you will find the
User engagement section, where you can enable the push notifications as well as set a content title:
After you've done that, you have to get a service account key for your Google Action as you will need it later on to get the access token needed to send out notifications.
For that, you have to first go the following url (replace the
your-project-id part with your project's id) and enable the
Actions API: https://console.developers.google.com/apis/api/actions.googleapis.com/overview?project=your-project-id.
Now, go over to https://console.developers.google.com/apis/credentials?project=your-project-id, again replace the
your-project-id part, and create a new service account key:
Project Owner as the role and
JSON as the key type:
Now that you got your service account key as well, all the preparation is done.
To ask the user if they want to opt-in to get push notifications for the specified intent, you have to first send the user suggestion chips that invite them to subscribe. If they are interested use the
askForNotification(intent) function to prompt them to opt-in:
The response to the question will be mapped to the Jovo built-in
ON_PERMISSION intent, where you can check wether the permission was granted using
The notification object contains the data you want to send to your user and has to have the following format:
||Specifies the title of the notification||
||Specifies the user who will receive the notification||
||Specifies the intent which will be executed after the user tapped on the notification||
||Specifies the locale||
To access the
$notification module, which contains the methods needed to send out push notifications you have to first install the
googleapis package as a dependency:
The module itself is also not added automatically to the
google-platform-googleassistant plugin, you have to add it manually in your
After you have done both, you can access the
$notification module like this:
To get the access token needed to send the notification, you need the service account key you downloaded earlier. Using key's
private_key attributes you can use
sendAuthRequest(clientEmail, privateKey), which will return you an object containing the access token, or you use
getAccessToken(clientEmail, privateKey) to get only the access token:
Using the access token and the notification object you can send the push notification: