Software /
code /
prosody-modules
Changeset
5087:438fbebf74ac
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 27 Nov 2022 00:34:00 +0100 |
parents | 5086:dec4b2e31d1c |
children | 5088:e9cf361982d5 |
files | mod_rest/mod_rest.lua |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {