comparison mod_slack_webhooks/mod_slack_webhooks.lua @ 3147:82689acd1294

mod_slack_webhooks: Forward info about clicked button to hook
author Kim Alvefur <zash@zash.se>
date Sun, 03 Jun 2018 02:02:56 +0200
parents 662423cea3f4
children 8c7b8b2c3237
comparison
equal deleted inserted replaced
3146:662423cea3f4 3147:82689acd1294
21 elseif mod_muc.rooms then 21 elseif mod_muc.rooms then
22 return mod_muc.rooms[room_jid]; -- COMPAT 0.9, 0.10 22 return mod_muc.rooms[room_jid]; -- COMPAT 0.9, 0.10
23 end 23 end
24 end 24 end
25 25
26 local button_ns = "xmpp:prosody.im/community/mod_slack_webhooks#buttons";
26 local routing = module:get_option("outgoing_webhook_routing") or {}; 27 local routing = module:get_option("outgoing_webhook_routing") or {};
27 local listen_path = module:get_option("incoming_webhook_path") or "/webhook"; 28 local listen_path = module:get_option("incoming_webhook_path") or "/webhook";
28 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot"; 29 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot";
29 30
30 function postcallback(_, code) 31 function postcallback(_, code)
57 timestamp = now(), 58 timestamp = now(),
58 text = body, 59 text = body,
59 team_domain = from_host, 60 team_domain = from_host,
60 user_name = from_nick, 61 user_name = from_nick,
61 }; 62 };
63
64 local form = stanza:get_child("x", "jabber:x:form");
65 if form and form.attr.type == "submit" then
66 local callback_id, button_name, button_value;
67 for field in form:childtags("field") do
68 if field.attr.var == "callback_id" then
69 button_name = field:get_child_text("text");
70 elseif field.attr.var == "button_name" then
71 button_name = field:get_child_text("text");
72 elseif field.attr.var ~= "FORM_TYPE" or field:get_child_text("text") ~= button_ns then
73 callback_id, button_name, button_value = nil, nil, nil;
74 break;
75 end
76 end
77 if callback_id and button_name and button_value then
78 json_out.callback_id = callback_id;
79 json_out.actions = {
80 { type = "button", name = button_name, value = button_value }
81 };
82 end
83 end
84
62 local stanzaid = stanza:get_child("id"); 85 local stanzaid = stanza:get_child("id");
63 if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then 86 if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then
64 json_out["bot_id"] = "webhookbot"; 87 json_out["bot_id"] = "webhookbot";
65 end 88 end
66 89
145 end 168 end
146 if button_name then 169 if button_name then
147 message:add_direct_child(dataform.new({ 170 message:add_direct_child(dataform.new({
148 { 171 {
149 type = "hidden", name = "FORM_TYPE", 172 type = "hidden", name = "FORM_TYPE",
150 value = "xmpp:prosody.im/community/mod_slack_webhooks#buttons", 173 value = button_ns,
151 }, 174 },
152 { 175 {
153 type = "hidden", name = "callback_id", 176 type = "hidden", name = "callback_id",
154 value = attachment.callback_id, 177 value = attachment.callback_id,
155 }, 178 },