comparison mod_slack_webhooks/mod_slack_webhooks.lua @ 3071:b6cac9d72255

mod_slack_webhooks: Use the correct MUC API
author Kim Alvefur <zash@zash.se>
date Wed, 30 May 2018 09:10:33 +0200
parents 02fc3b64cbb7
children 0f63e999d0e4
comparison
equal deleted inserted replaced
3070:c271bfa3d625 3071:b6cac9d72255
14 local json = require "util.json" 14 local json = require "util.json"
15 local formdecode = require "net.http".formdecode; 15 local formdecode = require "net.http".formdecode;
16 local xml = require "util.xml"; 16 local xml = require "util.xml";
17 local http = require "net.http"; 17 local http = require "net.http";
18 18
19 local function get_room_by_jid(mod_muc, jid) 19 local function get_room_from_jid(mod_muc, jid)
20 if mod_muc.get_room_by_jid then 20 if mod_muc.get_room_from_jid then
21 return mod_muc.get_room_by_jid(jid); 21 return mod_muc.get_room_from_jid(jid);
22 elseif mod_muc.rooms then 22 elseif mod_muc.rooms then
23 return mod_muc.rooms[jid]; -- COMPAT 0.9, 0.10 23 return mod_muc.rooms[jid]; -- COMPAT 0.9, 0.10
24 end 24 end
25 end 25 end
26 26
35 function check_message(data) 35 function check_message(data)
36 local origin, stanza = data.origin, data.stanza; 36 local origin, stanza = data.origin, data.stanza;
37 local mod_muc = host_session.muc; 37 local mod_muc = host_session.muc;
38 if not mod_muc then return; end 38 if not mod_muc then return; end
39 39
40 local this_room = get_room_by_jid(mod_muc, stanza.attr.to); 40 local this_room = get_room_from_jid(mod_muc, stanza.attr.to);
41 if not this_room then return; end -- no such room 41 if not this_room then return; end -- no such room
42 42
43 local from_room_jid = this_room._jid_nick[stanza.attr.from]; 43 local from_room_jid = this_room._jid_nick[stanza.attr.from];
44 if not from_room_jid then return; end -- no such nick 44 if not from_room_jid then return; end -- no such nick
45 45
74 return function(event, path) 74 return function(event, path)
75 local request = event.request; 75 local request = event.request;
76 local headers = request.headers; 76 local headers = request.headers;
77 local bare_room = jid.join(path, module.host); 77 local bare_room = jid.join(path, module.host);
78 local mod_muc = host_session.muc; 78 local mod_muc = host_session.muc;
79 if not get_room_by_jid(mod_muc, bare_room) then 79 if not get_room_from_jid(mod_muc, bare_room) then
80 module:log("warn", "mod_slack_webhook: invalid JID: %s", bare_room); 80 module:log("warn", "mod_slack_webhook: invalid JID: %s", bare_room);
81 return 404; 81 return 404;
82 end 82 end
83 -- Check secret? 83 -- Check secret?
84 return f(event, path) 84 return f(event, path)
102 end 102 end
103 else 103 else
104 return 422; 104 return 422;
105 end 105 end
106 local bare_room = jid.join(path, module.host); 106 local bare_room = jid.join(path, module.host);
107 local dest_room = get_room_by_jid(mod_muc, bare_room); 107 local dest_room = get_room_from_jid(mod_muc, bare_room);
108 local from_nick = default_from_nick; 108 local from_nick = default_from_nick;
109 if post_body["username"] then 109 if post_body["username"] then
110 from_nick = post_body["username"]; 110 from_nick = post_body["username"];
111 end 111 end
112 local sender = jid.join(path, module.host, from_nick); 112 local sender = jid.join(path, module.host, from_nick);