Stream of user like events

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?

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

# 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
6 Likes

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.

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