# Webhook for Discourse events

**URL:** https://meta.discourse.org/t/webhook-for-discourse-events/39808
**Category:** Feature
**Tags:** rfc
**Created:** [February 18, 2016, 4:06pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808 "2016-02-18T16:06:42Z")
**Posts on this page:** 14
**Page:** 1

<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: [February 18, 2016, 4:06pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/1 "2016-02-18T16:06:43Z")

</div>

I’m writing up the specs for this in order to facilitate [GSoC 2016 application](https://meta.discourse.org/t/list-of-project-ideas-for-google-summer-of-code-2016/38791)

## Specs

1. A single page at “/admin/webhook” for admins to manage their webhooks
2. Admins will need to provide a Payload URL which the webhook service will POST the event payload to.
3. Webhook will POST all events to the Payload URL by default. We should allow admins to select individual events which they require.
4. A Webhook can be activated and deactivated.
5. Logs of the POST request as well as the response should be kept and made visible for admins.

For a start, I think the following events suggested by @phanimahesh is pretty reasonable.

> [@phanimahesh](#):
>
> 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

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [February 18, 2016, 5:23pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/2 "2016-02-18T17:23:11Z")

</div>

I would love to see this in action! It’s been something I’ve wanted in Discourse for years now.

---

<div class="post-metadata">

### Author: ![ccdw](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ccdw/32/51564_2.png) [@ccdw](https://meta.discourse.org/u/ccdw)
#### Post date: [February 19, 2016, 9:39am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/3 "2016-02-19T09:39:31Z")

</div>

Are you saying that forum users will be able to subscribe to one or more published events? Or am I misunderstanding this?

---

<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: [February 19, 2016, 9:41am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/4 "2016-02-19T09:41:46Z")

</div>

Renamed `users` to `admins`.

---

<div class="post-metadata">

### Author: ![ccdw](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ccdw/32/51564_2.png) [@ccdw](https://meta.discourse.org/u/ccdw)
#### Post date: [February 19, 2016, 9:43am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/5 "2016-02-19T09:43:19Z")

</div>

Thanks 😄

Now I need to go away and redigest this again. Sounds great tho’

---

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [February 19, 2016, 10:08am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/6 "2016-02-19T10:08:55Z")

</div>

We use a webhooks plugin for our slack integration over at Loomio, which seems like it might be a nice reference for someone looking to implement this.

[https://github.com/loomio/loomio\_webhooks](https://github.com/loomio/loomio_webhooks)

---

<div class="post-metadata">

### Author: ![adrapereira](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adrapereira/32/51755_2.png) [@adrapereira](https://meta.discourse.org/u/adrapereira)
#### Post date: [March 6, 2016, 7:28pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/7 "2016-03-06T19:28:08Z")

</div>

I’m writing a proposal for this project to apply for GSOC 16 and would like your help since I’m not completely familiarized with Discourse and its code.

The settings page will be close the one GitHub has, admins will be able to create webhooks by defining the payload URL and the events that trigger the webhook. After a webhook is created, there will be options to enable/disable, edit or remove it.

I’m thinking that each payload will have two sections: the first defines the payload with some fields like the timestamp and action that triggered the event; the second section contains the fields specific to each action.

Regarding the second section, we can use the existing serializers for the object(s) in question (user, topic, post, etc.) or we can choose carefully which fields will be sent.

Just to start the discussion, I’ve made a quick list of the proposed fields of each payload:

## User

### user\_registered and user\_activated

`username, email, name, trust_level`

### trust\_level\_changed

`username, old_trust_level, new_trust_level`

### message\_sent

`sender_username, receiver_username, msg_title, msg_content`

Do we want the message content to be sent?

Another option is to define the required information of a user and use it whenever we’re referring to a user. For example, instead of `sender_username` we would have `sender_info` which has {ID, name, username, email, trust\_level, …}.

## Topic

### Topic\_created

`ID, title, content, creator_username, categories`

### Topic\_liked

`ID, title, username, number_of_likes`

### Topic\_{pinned,unpinned,archived,closed,invisibled,_bookmarked_}

`ID, title, username`

## Post

### Post\_liked

`post_ID, topic_ID, username, number_of_likes`

### Reply\_posted

`post_ID, topic_ID, username, content`

## Other

### Auto\_close\_set

I don’t know what this one means…

### Flag\_raised

`post_id, topic_id, reason`

* * *

This is what I had in mind, please let me know if you had another idea 😉

---

<div class="post-metadata">

### Author: ![r3trosteve](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/r3trosteve/32/116161_2.png) [@r3trosteve](https://meta.discourse.org/u/r3trosteve)
#### Post date: [July 18, 2016, 11:47pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/8 "2016-07-18T23:47:21Z")

</div>

I’d like to add:

Badge Awarded

---

<div class="post-metadata">

### Author: ![shri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shri/32/197750_2.png) [@shri](https://meta.discourse.org/u/shri)
#### Post date: [July 18, 2016, 11:50pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/9 "2016-07-18T23:50:21Z")

</div>

Could something like this be used for SES / email bounce webhooks too?

---

<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: [July 18, 2016, 11:56pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/10 "2016-07-18T23:56:10Z")

</div>

No, those Web hooks are from discourse to outside world. You want the opposite.

There are already bounces webhooks on core for three different providers, tough. Maybe try to craft a PR for ses?

---

<div class="post-metadata">

### Author: ![shri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shri/32/197750_2.png) [@shri](https://meta.discourse.org/u/shri)
#### Post date: [July 18, 2016, 11:57pm UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/11 "2016-07-18T23:57:43Z")

</div>

Got it. Thanks. Still trying to figure out the terminology and where bits and pieces of the code are. 🙂

Right now it is easier for me to do it externally in PHP/SQL. PR - One of these days…

---

<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: [July 19, 2016, 4:22am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/12 "2016-07-19T04:22:13Z")

</div>

By the way, @fantasticfears has been working on getting webhooks in as part of GSOC 🙂

The progress can be found at [https://github.com/discourse/discourse/tree/gsoc\_webhooks](https://github.com/discourse/discourse/tree/gsoc_webhooks)

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [October 22, 2016, 11:48am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/13 "2016-10-22T11:48:35Z")

</div>

Completed:

> [@Configure webhooks that trigger on Discourse events to integrate with external services](https://meta.discourse.org/t/setting-up-webhooks/49045):
>
> A webhook is a way to notify external services about changes on the internet. It’s easier to setup, manage and develop than a Discourse plugin. Though, it does require you to program a little bit or understand its technical details. In this #howto, I’ll set up webhook to power a Github bot for referencing pull request brought in a forum. We’ll want to see a new comment on Github pull request when a new post has a link to it. It’s a very simple process: Publish a new post. A webhook event happ…

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [October 22, 2016, 11:48am UTC](https://meta.discourse.org/t/webhook-for-discourse-events/39808/14 "2016-10-22T11:48:40Z")

</div>


