Webhooks plugin

(Ryan Fox) #1

I made a super-simple webhooks plugin, which sends HTTP requests for chosen DiscourseEvents that are triggered. Right now, there aren’t many events that are triggered, and only topic_created and post_created seem like they’d be useful for this. Hopefully, more events will be sprinkled around the main code in the future.

Event Hooks for Discourse
Uninitialized constant User::View
Extending File Upload
Intense API use floods staff log?
Uninitialized constant User::View
(cpk) #2

Would it be difficult to listen for new Notifications for a user? How would you potentially go about this? Thanks for the plugin btw.

(Ryan Fox) #3

The plugin listens to DiscourseEvent.trigger. There aren’t a whole lot of uses of it yet though: Search · DiscourseEvent.trigger path:/lib path:/app · GitHub

Adding it yourself wouldn’t be too difficult if you find where notifications are created. Or maybe you can get one of the Discourse devs to do it for you.

(Pugwash) #4

One possible use-case for webhooks would be syncing new users on Discourse with a 3rd party application or CRM system. I’m not sure about the internals for Discourse, but if you were able to set a trigger against a new user that would be very useful.

One step further you could link this to Zapier, making it trivial to sync to a few hundred other SaaS apps.

(Kevin Sweeney) #5

Hero. This is precisely what I need.

I also need a user_created hook, but I’m playing with that and will be be creating a pull request for that (and more?) soon.

(Jesse Perry) #6

I’ve been using this plugin for a few months and it’s worked perfectly. Thanks for bringing it into existence @rcfox!

(Kevin Sweeney) #7

I’m trying to setup a user created event hook, but when I do so, it breaks some tests related to post creation. The new event seems to be causing topic_created to fire multiple times while preventing post_created from firing.

in /app/models/user.rb

after_create do
  DiscourseEvent.trigger(:user_created, self)

Relevant test output


  1) PostCreator new topic success triggers extensibility events
     Failure/Error: creator.create
       unexpected invocation: DiscourseEvent.trigger(:topic_created, #<Topic:0x7fcbdc666ae8>, {:title => 'hello world topic', :raw => 'my name is fred', :archetype_id => 1}, #<User:0x7fcbdd907c10>)
       unsatisfied expectations:
       - expected exactly once, not yet invoked: DiscourseEvent.trigger(:post_created, anything, anything, #<User:0x7fcbdd907c10>)
       - expected exactly once, invoked twice: DiscourseEvent.trigger(:topic_created, anything, anything, #<User:0x7fcbdd907c10>)
       satisfied expectations:
       - expected at least once, invoked 4 times: DiscourseEvent.trigger(:markdown_context, anything)
       - expected exactly once, invoked once: DiscourseEvent.trigger(:after_trigger_post_process, anything)
       - expected exactly once, invoked once: DiscourseEvent.trigger(:before_create_topic, anything, anything)
       - expected exactly once, invoked once: DiscourseEvent.trigger(:after_validate_topic, anything, anything)
       - expected exactly once, invoked once: DiscourseEvent.trigger(:validate_post, anything)
       - expected exactly once, invoked once: DiscourseEvent.trigger(:before_create_post, anything)
     # ./lib/post_creator.rb:220:in `trigger_after_events'
     # ./lib/post_creator.rb:150:in `create'
     # ./spec/components/post_creator_spec.rb:82:in `block (4 levels) in <top (required)>'

(Anton) #8

Anyone tried to integrate it with Zapier?

(Aj Koft ModifyWordpressCourse) #9

Im looking for it too, cheers

(Robert) #10

I checked the repo to find events for

  • user profile changed (more precisely, new mail address confirmed)
  • group membership changed (either triggered for every user or once for the group)

I couldn’t find it. Did I miss something?