You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用ActionOnSDK在Google Assistant推送通知中附带自定义数据?

在Google Assistant的Action SDK推送通知中附带自定义数据的实现方法

Hey there! 要在Action SDK发送的推送通知里带上自定义数据其实很简单,只需要在你的通知结构里添加customData字段就行,这个字段支持你传入任意JSON格式的业务数据,等用户点击通知触发对应Intent时,你就能在后端拿到这些信息啦。

具体实现步骤:

  1. 构造包含自定义数据的通知对象
    在你现有的notification对象里,给userNotification新增一个customData属性,把你需要传递的自定义参数放进去——比如提示ID、分类、优先级这类业务相关的信息都可以。

  2. 在Intent中接收并处理自定义数据
    当用户点击推送通知触发tell_latest_tip这个Intent时,Google Assistant会把customData里的内容包含在请求的originalDetectIntentRequest.payload.userNotification.customData路径下,你只需要在Intent的处理逻辑里读取这个路径的数据就可以用啦。

修改后的完整代码示例:

let notification = {
  userNotification: {
    title: 'A new tip is added',
    // 这里添加你的自定义数据,支持任意合法JSON结构
    customData: {
      tipId: 'tip_001',
      category: 'productivity',
      priority: 'high'
    }
  },
  target: {
    userId: 'abcd1234-EFGH_789',
    intent: 'tell_latest_tip',
    locale: 'en-US' // 严格遵循IETF BCP-47语言代码规范
  },
};

request.post('https://actions.googleapis.com/v2/conversations:send', {
  'auth': {
    'bearer': tokens.access_token,
  },
  'json': true,
  'body': {
    'customPushMessage': notification
  }
});

小提示:

  • customData可以是任何合法的JSON结构,但别放敏感信息哦,这些数据会在通知触发时传递到你的Action后端。
  • 你可以在处理tell_latest_tip Intent的代码里打印日志,验证customData是否正确传递,确保数据符合预期。

内容的提问来源于stack exchange,提问作者Ravi Jetani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:01:15