# Webhooks feedback

**URL:** https://meta.discourse.org/t/webhooks-feedback/49046
**Category:** Development
**Created:** [August 23, 2016, 5:37am UTC](https://meta.discourse.org/t/webhooks-feedback/49046 "2016-08-23T05:37:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [August 23, 2016, 5:37am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/1 "2016-08-23T05:37:11Z")

</div>

Webhook is merged to master. See [Setting up webhooks](https://meta.discourse.org/t/setting-up-webhooks/49045) for instructions.

Webhooks is my GSoC projects which ends in Aug 23. It’s fully operating but I would keep improving it on more event types as well as payload improvement. I would like to hear comments about how you like to use it. The question like I need X in the payload and I need more information in the payload is generally welcomed.

This topic works as a progress report and feedback topic. Please leave your comments and questions.

## Code

Code is merged to the core.

Demo bot: [GitHub - erickguan/discourse-webhook-github-issue · GitHub](https://github.com/fantasticfears/discourse-webhook-github-issue)

## Highlights

If you are looking for instruction for webhooks, take a look at [this](https://meta.discourse.org/t/setting-up-webhooks/49045) #howto.

### Event type and event name

For example, `post_created` and `post_destroyed` are two events for plugin authors. Webhooks also take advantage of that. Once such event happens internally, a webhook may be also triggered. Let’s assume a webhook enables post event.  
So, `post_created` or `post_destroyed` happend. The webhook triggered. `X-Discourse-Event-Type: post` with post json is sent to you.

~~Do you need event name in the webhook? And how does that helps your application?~~

_Poll ([view on site](https://meta.discourse.org/t/webhooks-feedback/49046/1))_

`X-Discourse-Event` shows the exact internal event now.

### Event payload serialization

For example, the payload of post event is the exact same as Ember application gets. But the operator is our system user so that `can_edit?` is also sent to you which I believe there aren’t anything useful to your application.

Do you want me to omit those fields? Or what else information do you need?

_Poll ([view on site](https://meta.discourse.org/t/webhooks-feedback/49046/1))_

### Webhook event list

In our event delivery list, new event is not updated unless you refresh the page. And recent status is updated in the webhook list. ~~Do you think it’s necessary to notice those changes in real time? How does that helps?~~

_Poll ([view on site](https://meta.discourse.org/t/webhooks-feedback/49046/1))_

A blue notice shows the incoming event if available.

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 23, 2016, 8:34am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/2 "2016-08-23T08:34:45Z")

</div>

Full disclosure: I didn’t checkout and live-test this branch.

Awesome work, I am looking forward to use this feature. Some early feedback/questions:

- Why isn’t this a plugin (is it too deeply integrated in the core)? I am not really comfortable with testing a custom branch as it means a full manual install until it gets merged (a beta/unstable plugin would be much more lightweight).
- Some ideas for other hooks (that don’t seem to exist now after reading the docs):
  - `edit-post` which also triggers when a post gets edited.
  - `watch-first-post` which is like `edit-post` but for every first post in a topic.

- Filters on top of hooks which match against the payload json to restrict the trigger. Agreed, this can be implemented on the remote side of the webhook but sometimes it could save a lot of bandwith. This could be paired with an output filter which selects the wanted json fields (or produces some other structure based on the initial payload). This could be implemented with [mongodb-style json querying](https://docs.mongodb.com/manual/tutorial/query-documents/#read-operations-query-argument).

I just looked at the commits and discovered the existence of `DiscourseEvent`. Is there any documented list of such events or am I supposed to grep the source code for `DiscourseEvent.trigger`? 🦃  
_Edit:_ So I grepped and there are not so much such events. I don’t really understand “post validation” but the `validate_post` event might be relevent for my `edit-post` hook proposition.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [August 23, 2016, 8:54am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/3 "2016-08-23T08:54:57Z")

</div>

> [@Lapinot](#):
>
> Why isn’t this a plugin (is it too deeply integrated in the core)? I am not really comfortable with testing a custom branch as it means a full manual install until it gets merged (a beta/unstable plugin would be much more lightweight).

It is going to be merged into core but we didn’t want to ship it in version 1.6 so we developed the feature on another branch first. I’ll be merging it to core this coming week.

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [August 23, 2016, 1:14pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/4 "2016-08-23T13:14:54Z")

</div>

> [@Lapinot](#):
>
> watch-first-post which is like edit-post but for every first post in a topic.

`watch-first-post` sounds like a different type of thing. What types of application do you want to build? `validate_post` happens just before persistent it

> [@Lapinot](#):
>
> Is there any documented list of such events or am I supposed to grep the source code for DiscourseEvent.trigger?

Unfortunately no. Those hooks are set for plugin authors and continue to grow. So, just search or propose something you need in the exact place.

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 23, 2016, 2:03pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/5 "2016-08-23T14:03:57Z")

</div>

Actually I wasn’t really clear, I meant “like `edit-post` but for the first post of every topic”. My usecase for this one is to extract the first posts of some specially formatted topics to publish them on a static generated website (and stay in sync if it gets updated):

> [@Wiki sync plugin](https://meta.discourse.org/t/wiki-sync-plugin/48946):
>
> Hi everyone, I had an idea of a simple plugin that I am going to write but I may need some help/advices. The idea is just to sync up the posts in wiki mode with some external version control (a git server). This is really simple if there is a server-side discourse hook like after-edit-post or something similar but I can’t find it. My use case is that I don’t like CMSs but I need a collaboratively built website (kinda like a wiki) so I would like to have a automatically run static site generator…

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [August 24, 2016, 2:29am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/6 "2016-08-24T02:29:18Z")

</div>

I get it. Now you would have to use Post Event and check its `post_number`.

As of customized payload, I am not sure it’s worth it. A filter is harder to learn than just throw others away. If there is a way to get `edit-post` for first post, I guess it doesn’t matter how large the payload it is as it happens less than you notice.

---

<div class="post-metadata">

### Author: ![Lapinot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lapinot/32/60809_2.png) [@Lapinot](https://meta.discourse.org/u/Lapinot)
#### Post date: [August 24, 2016, 1:09pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/7 "2016-08-24T13:09:08Z")

</div>

> [@fantasticfears](#):
>
> As of customized payload, I am not sure it’s worth it.

Yeah, I do agree, but just filtering may be really handy: if I set up the `post` webhook here on meta, I will maybe get a call every couple minutes (maybe more I don’t know), a lot more than say the edition on the first post of a topic starting with `[news]`. And this query language isn’t complicated, for this example the filter query would be something like:

```plaintext
{'post': {'post_number': 1, 'topic_title': {'$regex':'^\[news\]'}}}

```

And here is a sample implementation in python as bonus 🐍 (I’ll try to do it in ruby to make a pr or something).

> <https://gist.github.com/Lapin0t/3862ada8bb5f0bf58e101096a6e06c81>

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 5, 2016, 10:47am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/8 "2016-09-05T10:47:35Z")

</div>

Ok webhooks feature has been merged into core 🙂

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [September 5, 2016, 10:48am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/9 "2016-09-05T10:48:20Z")

</div>

Is there a webhook for “new user account created and email was just confirmed?” If not, can we make sure we add one?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 5, 2016, 10:50am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/10 "2016-09-05T10:50:03Z")

</div>

Not yet. Right now webhooks are only triggered for create/destroy/edit events on topics and posts.

@fantasticfears can you have a look to see if it is easy to add one? 🙂

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [August 30, 2016, 4:41am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/11 "2016-08-30T04:41:38Z")

</div>

Some feedback 🙂

### Events page for webhook

1. Is it possible to have message bus publish the events so that we get live updates instead of having to refresh the page?
2. ![](https://global.discourse-cdn.com/meta/original/3X/c/b/cba2f3f118ca5f11775475267dd471b8dfc81faa.png) We should probably add headers to explain what each column mean.
3. The ping button needs to be disabled until the previous ping event completes. Otherwise, I can spam pings at the hook.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 5, 2016, 10:52am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/12 "2016-09-05T10:52:06Z")

</div>

Another thing I noticed is that there is no differentiation between creation, revision and deletion in the web hook header.

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [September 6, 2016, 10:53am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/13 "2016-09-06T10:53:22Z")

</div>

Sure, I will start working on them.

---

<div class="post-metadata">

### Author: ![Semaphorism](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/semaphorism/32/61600_2.png) [@Semaphorism](https://meta.discourse.org/u/Semaphorism)
#### Post date: [September 13, 2016, 6:07pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/14 "2016-09-13T18:07:08Z")

</div>

I have a question, the webhooks say you can’t have localhost events, I am trying it on [http://127.0.0.1:1245](http://127.0.0.1:1245), and it says this message

[quote]It seems you are trying to set up the webhook to a local url. Event  
delivered to a local address may cause side-effect or unexpected  
behaviours. Continue?[/quote]

Is it possible to allow that? I am trying to setup a webhook to a local nodejs server for a project, but the requests don’t appear to go through to localhost, is there a way to do so? I don’t want to have to write a plugin for this.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [September 13, 2016, 8:34pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/15 "2016-09-13T20:34:37Z")

</div>

Yep, that’s what the warning was talking about.

You need to give your server’s external IP, or the docker link’s host IP (172.[1,2,3]\*.\*.\*) as the webhook destination - I’d recommend the external IP.

Of course, then you need to watch for other people sending garbage to the server…

---

<div class="post-metadata">

### Author: ![Semaphorism](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/semaphorism/32/61600_2.png) [@Semaphorism](https://meta.discourse.org/u/Semaphorism)
#### Post date: [September 13, 2016, 8:47pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/16 "2016-09-13T20:47:56Z")

</div>

Ahh thanks 🙂  
I can always setup a IP tables rule to deny outside access to it anyway, or just whitelist the IP on the node server itself. That does work using the external IP of the server as well!

---

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [September 21, 2016, 9:25pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/17 "2016-09-21T21:25:48Z")

</div>

Great work on this! I’ve set one up to talk to a PHP script I’m working on, but I’m having trouble differentiating the event data. I have the webhook configured to trigger on post and topic events, but the payload doesn’t contain the event names you mentioned in your topic on [setting up webhooks](https://meta.discourse.org/t/setting-up-webhooks/49045).

Also, I noticed that the post event trigger says in Discourse that it fires when posts are edited and deleted, but this wasn’t the case on my website. This is not important for my use case, just thought I’d let you know.

---

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [September 22, 2016, 12:10am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/18 "2016-09-22T00:10:50Z")

</div>

Oh! I just realized that the event name is sent in the `X-Discourse-Event` header. Perfect.

---

<div class="post-metadata">

### Author: ![Bala\_V](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@Bala\_V](https://meta.discourse.org/u/Bala_V)
#### Post date: [September 22, 2016, 10:28am UTC](https://meta.discourse.org/t/webhooks-feedback/49046/19 "2016-09-22T10:28:07Z")

</div>

> [@Lapinot](#):
>
> As of customized payload, I am not sure it’s worth it.

I don’t agree with this. We are integrating discourse with a healthcare mobile app. One of the main features is to notify all the contributors of a specific topic whenever there is an “event” on it. With more than 50K users in the platform, the payload size is really huge. Specifically, this is due to the “actions\_summary” field in the payload. If there is a way to filter it out, the payload size reduces drastically and becomes manageable.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [September 22, 2016, 1:57pm UTC](https://meta.discourse.org/t/webhooks-feedback/49046/20 "2016-09-22T13:57:30Z")

</div>

But are you sending this hook to 50k endpoints? Or to another system that parses and then send the notifications? Couldn’t this system filter the fields?

[Next page](https://meta.discourse.org/t/webhooks-feedback/49046.md?page=2)
