Draft backup posts trigger the post_created webhook

AI-generated summary

simon questions whether it’s intentional for automatically created draft backup posts to trigger the post_created and post_edited webhook events. They provide a payload example from a development site, noting that they might have misconfigured something. They suggest filtering these requests in the webhook receiving code, but consider them unnecessary for most use cases. Additionally, they propose limiting topic and post event webhooks to regular topics, which would help in their case where they want to receive webhooks for regular topics but not private messages (PMs). A possible solution would be to add all the site’s categories to the WebHook “Triggered Categories” input.

Is it intentional for the automatically created draft backup posts to trigger the post_created and post_edited webhook events?

Here’s an example of the payload I’m seeing. Note that I’m testing this on a development site. It’s possible I’ve misconfigured something.

Draft post post_created payload
// Headers
Request URL: http://localhost:5173/api/discoursePostEvent
Request method: POST
Accept: */*
Connection: close
Content-Length: 1366
Content-Type: application/json
Host: localhost
User-Agent: Discourse/3.3.0.beta2-dev
X-Discourse-Instance: http://127.0.0.1:4200
X-Discourse-Event-Id: 3001
X-Discourse-Event-Type: post
X-Discourse-Event: post_created
X-Discourse-Event-Signature: sha256=ba23c86e4f40cc1c05442796227a53eb34a3498750447eeb5ce4e8e9f85ca13a

// Payload
{
  "post": {
    "id": 1070,
    "username": "scossar",
    "avatar_template": "/user_avatar/127.0.0.1/scossar/{size}/57_2.png",
    "created_at": "2024-05-21T17:48:15.497Z",
    "cooked": "<pre><code>Triggering the post event webhook.\n</code></pre>\n<pre><code class=\"lang-plaintext\">seq: 0\nkey: topic_536\n</code></pre>",
    "post_number": 18,
    "post_type": 1,
    "updated_at": "2024-05-21T17:48:15.497Z",
    "reply_count": 0,
    "reply_to_post_number": null,
    "quote_count": 0,
    "incoming_link_count": 0,
    "reads": 0,
    "score": 0,
    "topic_id": 474,
    "topic_slug": "backup-drafts-from-ongoing-topics",
    "topic_title": "Backup Drafts from ongoing topics",
    "category_id": null,
    "primary_group_name": null,
    "flair_name": null,
    "flair_group_id": null,
    "version": 1,
    "user_title": null,
    "bookmarked": false,
    "raw": "    Triggering the post event webhook.\n\n```text\nseq: 0\nkey: topic_536\n```",
    "moderator": false,
    "admin": true,
    "staff": true,
    "user_id": 7,
    "hidden": false,
    "trust_level": 1,
    "deleted_at": null,
    "user_deleted": false,
    "edit_reason": null,
    "wiki": false,
    "reviewable_id": null,
    "reviewable_score_count": 0,
    "reviewable_score_pending_count": 0,
    "event": null,
    "reactions": [],
    "current_user_reaction": null,
    "reaction_users_count": 0,
    "current_user_used_main_reaction": false,
    "can_accept_answer": true,
    "can_unaccept_answer": false,
    "accepted_answer": false,
    "topic_accepted_answer": false,
    "topic_posts_count": 18,
    "topic_filtered_posts_count": 18,
    "topic_archetype": "private_message"
  }
}

The requests can be filtered out in the webhook receiving code, but they seem unnecessary for most use cases.

Somewhat related, it would be great if it was possible to limit topic and post event webhooks to regular topics.

For my case, where I want to receive webhooks for all events related to regular topics and don’t want to receive webhooks for PMs, I guess the solution for both issues would be to add all the site’s categories to the WebHook “Triggered Categories” input.

1 Like