体验通知是为选择加入的 13岁及以上用户提供的一种方式,使他们通过及时、个性化的通知保持与他们最喜欢的游戏的联系。作为开发者,您可以确定哪些游戏内活动最重要需要通知您的用户,以及定义通知内容。


在收到通知后,用户可以通过加入按钮直接加入体验,并根据您的 启动数据 生成。
有关功能、资格要求、使用指南和相应的引擎 API 的更多信息,请参阅 体验指南。
实施
UserNotification 资源使您能够向用户发送体验通知。使用之前,您必须 生成一个 API 密钥或 配置 OAuth 2.0。本页上的示例使用 API 密钥。
要向用户发送体验通知:
- 形成请求:
- 将 API 密钥复制到 x-api-key 请求头中。
- 将通知字符串资产 ID 复制为 payload.message_id 属性的值。
- 将 payload.type 设置为 "MOMENT"。
- 将 source.universe 设置为宇宙资源 URL "universes/${UniverseID}"。
发送体验通知curl --location 'https://apis.roblox.com/cloud/v2/users/${UserId}/notifications' \--header 'x-api-key: ${ApiKey}' \--header 'Content-Type: application/json' \--data '{"source": {"universe": "universes/${UniverseID}"},"payload": {"message_id": "${AssetID}","type": "MOMENT"}}'
示例响应,其中返回通知 ID 在 id 字段中:
{
"path": "users/505306092/notifications/6ca4d981-36fa-4255-82a1-14d95c116889",
"id": "6ca4d981-36fa-4255-82a1-14d95c116889"
}
使用参数自定义通知
要为每个收件人自定义通知,请在 通知字符串 中包含 参数。然后在调用 API 时自定义参数。例如,您可以将通知字符串定义为:
{userId-friend} 以 {points} 分的优势击败了你的高分!是时候提升等级了?
在脚本中添加 userId-friend 和 points 参数:
使用参数自定义通知curl --location 'https://apis.roblox.com/cloud/v2/users/${UserId}/notifications' \--header 'x-api-key: ${ApiKey}' \--header 'Content-Type: application/json' \--data '{"source": {"universe": "universes/${UniverseID}"},"payload": {"message_id": "${AssetID}","type": "MOMENT","parameters": {"userId-friend": {"int64_value": 3702832553},"points": {"string_value": "5"}}}}'
包括启动和分析数据
为了进一步改善用户体验,您可以在通知中包含 启动数据,这在将用户路由到特定位置或个性化加入体验时非常有用。此外,您还可以包含 分析 数据,以对不同类别的通知的性能进行细分。
包括启动数据和分析数据curl --location 'https://apis.roblox.com/cloud/v2/users/${UserId}/notifications' \--header 'x-api-key: ${ApiKey}' \--header 'Content-Type: application/json' \--data '{"source": {"universe": "universes/${UniverseID}"},"payload": {"message_id": "${AssetID}","type": "MOMENT"},"join_experience": {"launch_data": "Test_Launch_Data"},"analytics_data": {"category": "Test_Analytics_Category"}}'
速率限制和交付
每个用户每天可以从给定的体验中接收 一个 通知,当用户的阈值限制达到时,您会收到透明反馈。
还有许多其他原因可能导致通知未送达。有关更多信息,请参阅引擎指南中的 交付系统。