【发布时间】:2019-04-26 05:24:11
【问题描述】:
我正在尝试为 Google Actions Intent 执行推送通知。
到目前为止,我已按照此处的说明进行操作:https://developers.google.com/actions/assistant/updates/notifications#send_notifications
这是我的结果代码:
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");
这会导致通知服务出现 403。这是因为生成的用户 ID、意图名称或 jwtoken 吗?
【问题讨论】:
-
您是否在用户参与度中为您在操作控制台中的意图启用了您想发送推送通知吗?
-
是的,我已在用户参与度中启用它。
-
你总是得到 403 吗?发送通知时,每个用户每分钟限制 1 个通知。您收到任何错误消息吗?
-
是的。 100% 失败
-
您是否为您的项目启用了 Actions API?转到Google Cloud Platform console 以激活 Actions API,然后选择您在 Actions on Google 控制台上创建的项目。然后,单击启用按钮。
标签: jwt actions-on-google