# 用户点赞事件流

**URL:** <https://meta.discourse.org/t/stream-of-user-like-events/96772>\
**Category:** Support\
**Created:** [2018年九月9日 02:29 UTC](https://meta.discourse.org/t/stream-of-user-like-events/96772 "2018-09-09T02:29:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johncmckim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johncmckim/32/110733_2.png) [@johncmckim](https://meta.discourse.org/u/johncmckim)\
**Post date:** [2018年九月9日 02:29 UTC](https://meta.discourse.org/t/stream-of-user-like-events/96772/1 "2018-09-09T02:29:41Z")

</div>

I couldn’t find an answer to this in the docs or after digging into the code. I’m interested in adopting discourse. A key use case for us is to integrate it with our platform’s gamification engine. I want to be able to increment a user’s points on our internal platform when their post or reply is liked.

To do this I’d like to be able to access an event when a user likes a post or reply via a webhook or potentially Kinesis Stream. Open to other ideas how to do this though. Happy to put some dev time into this to build a plugin if required.

Is this a known use case? What internal event would we have to hook into to be able to develop this?

---

<div class="post-metadata">

**Author:** ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)\
**Post date:** [2018年九月9日 02:43 UTC](https://meta.discourse.org/t/stream-of-user-like-events/96772/2 "2018-09-09T02:43:45Z")

</div>

There’s no current event for this. However, you can include one as part of a plugin.

```plaintext
# plugin.rb
class ::PostAction
  module ListenForLikes
    def act(user, post, post_action_type_id, opts = {})
      super(user, post, post_action_type_id, opts).tap do |action|
        DiscourseEvent.trigger(:post_liked, action) if action.persisted? && action.is_like?
      end
    end
  end
  singleton_class.prepend ListenForLikes
end

on :post_liked do |action|
  # do some stuff
end

```

---

<div class="post-metadata">

**Author:** ![johncmckim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johncmckim/32/110733_2.png) [@johncmckim](https://meta.discourse.org/u/johncmckim)\
**Post date:** [2018年九月10日 01:45 UTC](https://meta.discourse.org/t/stream-of-user-like-events/96772/3 "2018-09-10T01:45:55Z")

</div>

Thanks. That’s really useful. I’ve done a quick POC and it definitely looks feasible to set something up for both `:post_liked` and `:post_unliked`.

My next challenge is to work out how I can aggregate likes by tags. But I think I’ll be able to work that out easily by getting all the data into our warehouse and running batch jobs to aggregate.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2018年十月10日 01:53 UTC](https://meta.discourse.org/t/stream-of-user-like-events/96772/4 "2018-10-10T01:53:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
