Reputation: 403
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 ?
Upvotes: 1
Views: 497
Reputation: 403
So after debugging & by trial and error. I realised that I was trying it out on the IOS mobile phone & due to some reason the api was giving this error because of IOS assistant version. I'm assuming that since they say in their documentation that it's still in beta phase they mightn't have enabled it for ios users.
As soon as I ran a google assistant test build against my android phone I got 200 immediately & notifications worked like a charm.
Upvotes: 1