5

I'm trying to perform a push notification for Google Actions Intent.

Thus far, I've followed the instructions here: https://developers.google.com/actions/assistant/updates/notifications#send_notifications

This is my resulting code:

const {google} = require('googleapis');
var request = require('request');

const key = require('./bot.json');

module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);

    let jwtClient = new google.auth.JWT(
        key.client_email, null, key.private_key,
       ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
        null
      );

      jwtClient.authorize((err, tokens) => {
        // code to retrieve target userId and intent
        let notif = {
          userNotification: {
            title: [message],
          },
          target: {
              userId:[obtained from permission request],
              intent: [name of intent],
            // Expects a IETF BCP-47 language code (i.e. en-US)
            locale: 'en-US'
          },
        };

        request.post('https://actions.googleapis.com/v2/conversations:send', {
          'auth': {
            'bearer': tokens.access_token,
           },
          'json': true,
          'body': {'customPushMessage': notif},
        }, (err, httpResponse, body) => {
            console.log(body);
           console.log(httpResponse.statusCode + ': ' + httpResponse.statusMessage);
        });
      });
};

//module.exports(console, "Test");

This results in a 403 from the notification service. Is this because of the user id, intent name or jwtoken that was generated?

Irwin
  • 12,551
  • 11
  • 67
  • 97
  • Have you enabled **Would you like to send push notifications** in User Engagement for your intent in your Actions Console ? – Sairaj Sawant Nov 24 '18 at 03:48
  • Yep, I had enabled it in User Engagement. – Irwin Nov 24 '18 at 04:21
  • do you get a 403 all the time? there is a 1 notifications per user per minute limit when sending notifications. do you get any error messages? – Reza Nasiri Nov 25 '18 at 00:07
  • yep. 100% failures – Irwin Nov 25 '18 at 01:29
  • Have you enabled the Actions API for your project? Go to the [Google Cloud Platform console](https://console.developers.google.com/apis/api/actions.googleapis.com/overview) to activate the Actions API, and select the project that you have created on the Actions on Google console. Then, click the Enable button. – Taylor Caldwell Nov 26 '18 at 20:41
  • Hi @TaylorCaldwell, yep, did that too: https://imgur.com/a/yLIdK2X – Irwin Nov 28 '18 at 05:38
  • I have same issue: statusCode":403,"body":{"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}} – Fabio Guerra Dec 05 '18 at 23:28
  • Hey folks, I just confirmed that the feature works with a 200. A couple things I'd check: 1) You're using the same intent in your request as the one you used when requesting permission to send push notifications 2) You are using a key associated with an owner-level service account in your GCP project Otherwise your code looks good – Sachit Mishra Dec 07 '18 at 08:37
  • While sending notification i got this error (node:22520) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'access_to ken' of undefined – Aravindhan Gs Mar 22 '19 at 09:14

1 Answers1

-1

Following are the steps we need to check before sending the push notification

  1. Check your Google permission settings In order to test the Action, you need to enable the necessary permissions.

Go to the ‘Activity Controls' page (https://myaccount.google.com/activitycontrols). Sign in with your Google account, if you have not already done so. Ensure that the following permissions are enabled:

a.Web & App Activity
b.Device Information
c.Voice & Audio Activity

2.Target intent name should be added into the Implicit invocation field. with enabled push notification. 3.use the same email id in your google assistant which you had used for login in GCP.