获取通知 Webhook 事件的目标用户

我看到 webhook 现在支持通知功能,这太棒了,正是我们迫切需要的。不过,负载中缺少一个关键信息——通知所针对的用户。在此示例负载中,我们可以看到触发通知的帖子作者,但无法看到应接收通知的用户。

{
  "notification": {
    "id": 119,
    "notification_type": 9,
    "read": false,
    "created_at": "2019-09-18T13:42:21.248Z",
    "post_number": 1,
    "topic_id": 75,
    "fancy_title": "Phallguy should get a notice about this",
    "slug": "phallguy-should-get-a-notice-about-this",
    "data": {
      "topic_title": "Phallguy should get a notice about this",
      "original_post_id": 111,
      "original_post_type": 1,
      "original_username": "Paul_Alexander",
      "revision_number": null,
      "display_username": "Paul_Alexander"
    }
  }
}

我查找了是否有通过通知 ID 获取目标用户的 API,但未找到任何相关文档。请问是否有一种方法可以在通知负载中获取目标用户名或 ID?

背景说明:我们正试图将来自多个系统的通知整合起来,为用户提供统一的通知体验。

1 个赞

@Falco or @blake do you have any thoughts on how I can figure out which user a notification is for when received through the new notification webhook?

Just looked at this briefly to see if there was a quick answer, and you are right, it does not look like we have a get api endpoint for fetching an individual notification by id, but that wouldn’t be very efficient to call every time anyways.

Most likely this will require a code change to the notification serializer to include the user_id/username inside of the notification payload, so that a separate api request wouldn’t be necessary.

2 个赞

We’re using the hosted service at the moment otherwise I’d build my own plugin. Would you folks consider adding the user id/username to then notification payload in the webhook?

Did you check the headers?

I did - hoping to find some extra meta data in there but didn’t find anything user specific.

Request URL: https://XXX
Request method: POST
Accept: */*
Connection: close
Content-Length: 420
Content-Type: application/json
Host: XXX
User-Agent: Discourse/2.4.0.beta4
X-Discourse-Instance: https://XXX
X-Discourse-Event-Id: 11
X-Discourse-Event-Type: notification
X-Discourse-Event: notification_created
X-Discourse-Event-Signature: sha256=XXX

Checking in to see if you folks have any thoughts/updates. The notification webhook without a target user isn’t really of much use.

Hey guys have you had a chance to review the issue? Is there any hope that we can get the target user id in the notification event?

I’ve created a pr that will add the user_id to the notification webhook json payload:

4 个赞

你好 @blake,是否也可以添加用户 external_id?我们使用 Discourse 的 SSO,在我们的系统中并没有 Discourse 用户 ID。

1 个赞

你好,Albert!

我认为这是一个很好的想法,我已经提交了一个 commit,如果启用了 SSO,将会添加用户的外部 ID(external_id)。

希望这能帮到你!它将在你的站点下次部署时加入,预计本周内就会完成。

3 个赞

哇,真快!非常感谢,太感激了 :smiley: 你知道这些更改大概什么时候能部署到托管的 Discourse 服务器上吗?

1 个赞

哦,算了,没看到最后一句 :sweat_smile:。再次感谢!!