Here is the setup I'm following: I've followed what mentioned in https://developers.google.com/actions/assistant/updates:
{ code: 400,
message: 'Unauthorized push.',
status: 'INVALID_ARGUMENT' } } '400: Bad Request'
This is the code for sending notification: I've hardcoded the userId, this is the userId i get in fulfillment of backend from the last step intent that is after asking user for permission.
const google = require('googleapis');
const key = require("./service-account-key.json");
var jwtClient = new google.auth.JWT(
key.client_email, null, key.private_key,
['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
null
);
jwtClient.authorize(function (err, tokens) {
var notif = {
userNotification: {
title: "This is a test reply",
},
target: {
userId: 'ABwppHE75K2ZVr00a7EcCT_4hv00fck7aFtdR7PmO_w3U3j9w1b3uCjyCoStVAHSgv5LL3Swup9RmkZ-',
intent: 'doctor_reply'
}
}
console.log(JSON.stringify(tokens) + "\n" + JSON.stringify(notif));
request.post('https://actions.googleapis.com/v2/conversations:send', {
'auth': {
'bearer': tokens.access_token
},
'json': true,
'body': { 'customPushMessage': notif, 'isInSandbox': true}
}, function(err,httpResponse,body) {
console.log("notification sent");
console.log(err, body, httpResponse.statusCode + ': ' + httpResponse.statusMessage)
});
});
Have anyone faced a similar issue ?