# HG changeset patch # User Kim Alvefur # Date 1669505640 -3600 # Node ID 438fbebf74acb7b5023990eb240c77e7f0c4522e # Parent dec4b2e31d1c92fcd10b6c8d0d250d59521c5a15 mod_rest: Wrap webhook setup in a function for future reuse The goal is to allow binding a session to a webhook via API to allow e.g. bots to set up handling of incoming messages. diff -r dec4b2e31d1c -r 438fbebf74ac mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Sun Nov 27 00:10:38 2022 +0100 +++ b/mod_rest/mod_rest.lua Sun Nov 27 00:34:00 2022 +0100 @@ -461,9 +461,7 @@ }; }); --- Forward stanzas from XMPP to HTTP and return any reply -local rest_url = module:get_option_string("rest_callback_url", nil); -if rest_url then +function new_webhook(rest_url, send_type) local function get_url() return rest_url; end if rest_url:find("%b{}") then local httputil = require "util.http"; @@ -473,7 +471,6 @@ return render_url(rest_url, { kind = stanza.name, type = at.type, to = at.to, from = at.from }); end end - local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml"); if send_type == "json" then send_type = "application/json"; end @@ -601,6 +598,16 @@ return true; end + return handle_stanza; +end + +-- Forward stanzas from XMPP to HTTP and return any reply +local rest_url = module:get_option_string("rest_callback_url", nil); +if rest_url then + local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml"); + + local handle_stanza = new_webhook(rest_url, send_type); + local send_kinds = module:get_option_set("rest_callback_stanzas", { "message", "presence", "iq" }); local event_presets = {