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.
Would it be difficult to listen for new Notifications for a user? How would you potentially go about this? Thanks for the plugin btw.
The plugin listens to DiscourseEvent.trigger. There aren’t a whole lot of uses of it yet though: https://github.com/discourse/discourse/search?q=DiscourseEvent.trigger+path%3A%2Flib+path%3A%2Fapp&type=Code
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.
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.
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.
I’ve been using this plugin for a few months and it’s worked perfectly. Thanks for bringing it into existence @rcfox!
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)
end
Relevant test output
Failures:
1) PostCreator new topic success triggers extensibility events
Failure/Error: creator.create
Mocha::ExpectationError:
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)>'
Anyone tried to integrate it with Zapier?
Im looking for it too, cheers
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?
This plugin could be nice to integrate with #auto
I believe Discourse supports webhooks directly now, so this plugin isn’t needed anymore.
It sure does. Webhooks are documented here: Configure webhooks that trigger on Discourse events to integrate with external services.