Setting up webhooks

I’ve been playing with this and I am getting nowhere. Need some help here :slight_smile:

I am trying to deliver new forum posts into a Discord chat channel. The webhook is triggered, but it fails with this error in the response:

{"code": 50006, "message": "Cannot send an empty message"} 

So it looks like for some reason Discourse is sending an empty message to Discord.

Any clues?

Thanks

You can try cloning this repo from critcola

2 Likes

Is the notification web hook plugin available now? I can not find it on Github.

This sample plugin enables the notification web hook. https://github.com/fantasticfears/discourse-webhooks-example

7 Likes

Hi,

is there any way to make a webhook that notifies when a new user is created?

it should be possible using “user event”, but this item notifies for every user and not just the new ones. any idea how to limit it for new sign ups?

p.s.: I also tried new user event webhook limited to “TL0” group, but it doesn’t notify anything.

1 Like

I don’t see how to limit the webhook to just “new user” but the headers have the webhook reason:

X-Discourse-Event-Id: 414
X-Discourse-Event-Type: user
X-Discourse-Event: user_created

Unfortunately, the last time I asked, some services like Zapier can’t filter on the header data.

You might be able to act on last_seen_at, or other keys which would only be empty on their first visit:

  "last_seen_at": null,
  "time_read": 0,
  "stats": [],

Or check out @fantasticfears plugin, see if it works for you:

1 Like

Hey Erick, does this plugin still work? I’ve installed it and enabled the notification events for my web hook. Although users are receiving notifications, I don’t see any events being triggered for the web hook. Please help me figure this out. Thanks!

Hi @fantasticfears,
How can i get user email include in POST payload ? Is there any config to allow include user email ?
Thanks.

{
  "post": {
    "id": 19,
    "name": "user",
    "username": "user",
    "avatar_template": "/letter_avatar_proxy/v2/letter/u/c0e974/{size}.png",
    "created_at": "2018-07-20T06:24:33.205Z",
    "cooked": "<p>Cool, now i have you, haha</p>",
    "post_number": 6,
    "post_type": 1,
    "updated_at": "2018-07-20T06:24:33.205Z",
    "reply_count": 0,
    "reply_to_post_number": null,
    "quote_count": 0,
    "avg_time": null,
    "incoming_link_count": 0,
    "reads": 0,
    "score": 0,
    "topic_id": 11,
    "topic_slug": "this-is-new-topic",
    "topic_title": "This is new topic",
    "display_username": "user",
    "primary_group_name": null,
    "version": 1,
    "user_title": null,
    "moderator": false,
    "admin": true,
    "staff": true,
    "user_id": 1,
    "hidden": false,
    "trust_level": 1,
    "deleted_at": null,
    "user_deleted": false,
    "edit_reason": null,
    "wiki": false,
    "topic_posts_count": 6
  }
}

The post payload will never include the email address. If you want then you can add it in a custom plugin code using add_to_serializer(:web_hook_post, ....) method.

5 Likes

I created webhook for “User Event”.

  1. As I investigated, there are only 3 events:
    user_logged_in - when user logged in
    user_logged_out - when user ogged out
    user_created - when user created but not activated
    No user_activated event or any other.

  2. If I set content type application/json, I get empty $_REQUEST.
    If I set content type application/x-www-form-urlencoded, I get this $_REQUEST:
    Array(
    [{“user”:“id”:33,“username”:“andrey_gmail”,“avatar_template”:"/letter_avatar_proxy/v2/letter/a/ecb155/{size}_png",“name”:“Andrey_Tepaykin”,“email”:“andrey_tepaykin@gmail_com”,“last_posted_at”:null,“last_seen_at”:“2018-09-10T10:44:55_848Z”,“created_at”:“2018-09-10T10:43:56_243Z”,“stats”:] => Array(
    [{“action_type”:13,“count”:1}] =>
    )
    )

Seems bug in request formatter. Why I get so weird request data?

When a user logs in, logs out, is created, approved or updated.

user_activated - no such an event exist. user_approved will be triggered when you enabled must approve users site setting and a user is approved by staff.

Can you see anything related in your /logs?

1 Like

Oh, so it’s impossible to catch when user activate account using activation link?

Nothinh in [Error Logs] related this problem.

Yes, you can create feature request topic for that.

I didn’t received any other reports from users/customers who using application/json content type. Can you please check your end again.

1 Like

Thanks @vinothkannans,

Just wondering that, I can see the “New webhook” button on my dev site, but can’t see on live site. Seem they have same versions. Can you have a look ? Thanks

Dev site info:

Installed v2.1.0.beta2 +75

Latest 2.2.0.beta1

Live site info:

Installed v2.1.0.beta2 +125

Latest 2.2.0.beta1

They don’t have same version v2.1.0.beta2 +125 > v2.1.0.beta2 +75.

4 Likes

Yes you right, it was problem with my backend. I got valid json with
file_get_contents("php://input")
Hope this will help somebody.

1 Like

Would it be possible to add a webhook for when a user is added to a group? We have some groups with access to sensitive material and would like to monitor when users are added.

I’ve enabled ‘send me everything’, and I get other events, but not when a user is added to a group.

8 Likes

Have you solve your problem?

Not with webhooks. Instead I continuously poll using the API:

forum.example.com/groups/{groupname}/members.json

Hi,

I have looked on the forum about Badge earned webhook, and saw there is something that has been made or maybe still in development.
Is there any plugin doing that, I was trying to test badges with a new post webhook but it’s called much more times than needed, calling a webhook on every new post is a bit intensive for my website.