Event Hooks for Discourse


(J Phani Mahesh) #1

Do we have event hooks on discourse?

####IDEA:
A publish/subscribe mechanism (redis can be leveraged here), where the discourse framework publishes events like topic/post create, close, archive, etc.

And a horde of pluggable hooks can subscribe to these events and abide by the condition zero of WTFPL.

Very much like web-hooks on github repositories, or like {pre,post}-{commit,recieve,applypatch,...} hooks for git repositories.


Is it possible to add a user action event listener?
List of project ideas for Google Summer of Code 2016
(Robin Ward) #2

We don’t really have any now but it’s something we’ve wanted to do for a long time.

A good first start would be to outline what hooks we should support and what kind of data should be in their payloads.


Webhooks/Push Notifications
(J Phani Mahesh) #3

Events, I can think of user_{registered,activated}, topic_created, reply_posted, post_liked, flag_raised, message_sent, topic_{pinned, unpinned, archived, closed, invisible-d}, auto_close_set, trust_level_changed

Payloads should be dependent on the action. For instance, topic_created should have topic id, title, content, OP.

Now since if we have huge traffic and lots of hooks both of which are not unlikely, a YAML frontmatter section or something in the hook should indicate what data it would like to receive. This data is communicated to discourse during the hook initialization, and we send out the least possible data needed.

To explain further, I can have a hundred hooks on topic_created that deal only with OP, title and id. We figure out that no hook uses content, so we do not send it in our broadcasts. Everytime a hook is registered or unregistered, we update the fields that need to be sent.

P.S : If I have a hundred hooks on same event and that too acting on just three fields then I am very likely organising things in a bad way, but that was just an example.


Webhook for Discourse events
(Chase Sterling) #4

Being able to set up some external webhooks to be notified (ala github), would be pretty nice. I’d like to tie this in with notifico to get some nice IRC announces whenever we get new forum topics.


(Jeff Atwood) #5

Yeah, a generic webhooks setup would be pretty sweet – and I think simple too.


(uda) #6

This is great and useful, and it should go both ways, incoming webhooks should be supported as well.
So when someone pushes to github / gitlab / bitbucket the forum members get notified.


(Jordan Magnuson) #7

Yes please.

This is one of the biggest features I need to make Discourse an option for our site. We have a social site with a global notification system tied to all kinds of user activity throughout the site (a la Facebook – see screenshot), and need to be able to include forum notifications in with the rest (replies to a topic you started, etc.).

So we need Discourse to send webhooks that we can turn into messages for this kind of system.


(Ryan Fox) #8

I just posted a plugin for doing webhooks: Webhooks plugin

I’d be interested in hearing if this is also useful for you.


(Colin Curtin) #9

Yes please!

Our use case: We run Discourse as a forum for our clients to discuss everything related to the college bookstore industry, as well as talking to us about features and our plans for the future.

Currently we have a system-like user subscribed to all the topics that will send an email to our Zendesk so that at least one of us will keep an eye on the forum and respond quickly if they need us.

A webhook here is a better solution, as we already have our on internal “IFTTT”-alike service.

That way, we could also push messages to our Flowdock!


(Sam Saffron) #10

What is the minimal viable solution you are looking for here to scratch your itch?


(Colin Curtin) #11

IF: there is a new topic or reply anywhere on discourse
THEN: HTTP POST its API addressable id to a URL that I can specify

That way I can get its contents through the API and do whatever with it.

I think github really does it right, for future direction:
https://github.com/discourse/discourse/settings/hooks (assuming you’re an admin on discourse github repo)
Webhooks | GitHub Developer Guide


SSO Sync moderators and admins
(Kane York) #12

Let’s just POST over the whole output of a PostSerializer, which will include post ID, topic ID, post number, cooked, raw, etc…


(Sam Saffron) #13

Sure, do you want to make it happen: a simple site setting will do here, must be sent using a bg job.


(cpk) #14

It would be great to fire events when a user receives new notifications. This way apps built with the Discourse API could receive real time notifications. Im thinking about writing this myself using ActiveRecord::Observer as a plugin.

Is there an existing way to do this? EDIT: Think I just answered my own question.

Is there a way to pass in a user?

EDIT: Another idea is to poll the notifications endpoint IE: http://community.mysite.com/notifications/history.json?user=userName would that be a better solution? Thanks.


(Geoff Bowers) #15

I’m just looking for something to push things into a slack channel. A simple JSON packet that gets pushed to an end point on post creation would be ideal.

I manage 5 small forums (2 of which are private) and I’d love to be notified of any post. At the moment the best I can seem to work out is polling the RSS feed for latest on the public forums; but that misses new posts, and doesn’t work for private forums.


(Kane York) #16

You can poll /latest.json with cookie or api key authentication to get every post.


(Alaincoletta) #17

Hi Sam, we’d like to have a Slack integration to notify us in our #support channel when someone posts a new question.


(Tom Newsom) #18

Keep an eye on this in-progress plugin:


(Jeff Atwood) #19

Simply configure Slack to use the existing RSS feeds for all topics, or topics in a specific category on the relevant URL.


(Erlend Sogge Heggen) #20

Continued here: