如何使用登录用户ID发送推送通知

问题描述 投票:0回答:1

我有一些用户通过Google登录(https://developers.google.com/actions/identity/google-sign-in)登录到我的Google动作应用中

我想向其中一个用户发送推送通知。

为了首先使推送通知与操作一起使用,我尝试了以下示例:https://github.com/actions-on-google/dialogflow-updates-nodejs/blob/master/functions/index.js,但只有在没有此提交的情况下,我才能使它起作用:https://github.com/actions-on-google/dialogflow-updates-nodejs/commit/c655062047b49e372da37af32376bd06d837fc7f#diff-1e53ef2f51bd446c876676ba83d7c888

效果很好,但我认为const userID = conv.user.id;返回已弃用的匿名用户ID。提交建议使用const userID = conv.arguments.get('UPDATES_USER_ID');返回未定义。

我使用此nodejs代码发送推送通知。

const request = require('request');
const {JWT} = require('google-auth-library');
const serviceAccount = require('./service-account.json');
let jwtClient = new JWT(
  serviceAccount.client_email, null, serviceAccount.private_key,
  ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
  null
);
jwtClient.authorize((authErr, tokens) => {
  let notification = {
    userNotification: {
      title: process.argv[2],
    },
    target: {
      userId: USERID,
      intent: 'tell_latest_status',
      // 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': notification, 'isInSandbox': true
    },
  }, (reqErr, httpResponse, body) => {
    console.log(httpResponse.statusCode + ': ' + httpResponse.statusMessage);
  });
});

我根本无法使它与const userID = conv.arguments.get('UPDATES_USER_ID');一起使用版本,因为正如我所说

[当我按照此处的建议使用conv.user.profile.payload.sub时:https://developers.google.com/actions/identity/user-info,AoG API返回“ SendToConversation响应:目标的无效用户ID”。

有什么方法可以使Google登录功能正常工作?有人做过这项工作吗?我的意思是使用UPDATES_USER_ID字段吗?

我已经在示例存储库中创建了一个问题:https://github.com/actions-on-google/dialogflow-updates-nodejs/issues/15,但我被发送到这里。

谢谢!

push-notification dialogflow actions-on-google google-signin
1个回答
0
投票

[研究为什么有时会得到undefined时,我找到了解决this question的答案。

我已经找到了解决此问题的方法。在获取UPDATES_USER_ID时conv.arguments.get()仅适用于首次尝试。因此,在建造时您的动作必须保存。如果您没有存储或保存,则可以重置您的个人资料,然后重试,您将可以获取。

您可以为操作here重置用户个人资料。

© www.soinside.com 2019 - 2024. All rights reserved.