Here is what I did eventually:
Since I need standard notifications for topic creation and deletion, I figured out Discourse already enqueues those, as part of the standard webhook feature. So there’s no need to do it myself.
What remains to be done, as @pfaffman suggested, is to add the webhook to the database. However, the proposed code fails silently, probably because of missing and/or incorrect parameters.
Here is my full working code:
#customization:plugin.rb
# Add our webhook automatically, so that admin doesn't have to do it manually
after_initialize do
# Delete our previously installed webhook (reserved id = 1000)
WebHook.where(id: 1000).destroy_all
# Create the webhook (reserved id = 1000)
hook = WebHook.new(
id: 1000, # Our reserved id
payload_url: 'https://hfzeoihifzh/',
content_type: 1, # 1 = 'application/json'
secret: "min12characters",
active: true,
verify_certificate: true,
web_hook_event_type_ids: [1] # 1 = topic events
)
hook.save
end