【发布时间】:2021-10-07 14:54:09
【问题描述】:
我正在尝试在 Actions Builder 上构建一个向自身发送推送通知的机器人。我正确配置意图并获取推送令牌并实现文档(https://developers.google.com/assistant/engagement/notifications#exchange_the_key_for_an_access_token_and_send_a_notification)给出的代码。
这是我的代码:
action.handle('SendPushIntent', async (conv) => {
const serviceAccount = require('./service-account.json');
console.log(serviceAccount.client_email); // I verified that service account is the same here as my GCP account.
let client = auth.fromJSON(serviceAccount);
client.scopes = ['https://www.googleapis.com/auth/actions.fulfillment.conversation'];
let notification = {
userNotification: {
title: 'Example',
text: 'Body'
},
target: {
userId: conv.user.params.pushToken, // The push token stored, I verified is not empty, null or undefined
intent: 'PushReceptorIntent',
locale: conv.user.locale,
},
};
client.authorize((err, tokens) => {
if (err) {
throw new Error(`Auth error: ${err}`); // No error here
}
request.post('https://actions.googleapis.com/v2/conversations:send', {
'auth': {
'bearer': tokens.access_token,
},
'json': true,
'body': {'customPushMessage': notification, 'isInSandbox': true},
}, (err, httpResponse, body) => {
if (err) {
throw new Error(`API request error: ${err}`);
}
console.log(`${httpResponse.statusCode}: ` + `${httpResponse.statusMessage}`);
console.log(JSON.stringify(body));
});
});
});
当我尝试发送推送时出现此错误
{"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}}
我已经获得了具有所有者权限的服务帐户密钥并将其提供给我的代码,因为文档需要https://developers.google.com/assistant/engagement/notifications#get_a_service_account_key
这是 Actions API 的图表,只收到 403 作为响应。我不知道出了什么问题。
我已经做了以下步骤:
- 禁用/启用操作 API
- 生成服务帐号
- 已验证服务帐户具有所有者权限
希望你能帮我解决这个问题!
10 月 8 日编辑
为我的服务帐户添加了 Cloud Asset Owner 权限。
【问题讨论】:
标签: google-cloud-platform push-notification action