comparison mod_slack_webhooks/mod_slack_webhooks.lua @ 4560:724003f24308

Back out 82689acd1294 (non-standard buttons)
author Kim Alvefur <zash@zash.se>
date Fri, 21 May 2021 20:58:10 +0200
parents 284d8c18060e
children c6b740ccf6ec
comparison
equal deleted inserted replaced
4559:33b1b6ff23d8 4560:724003f24308
19 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or 19 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
20 function (room_jid) 20 function (room_jid)
21 return rooms[room_jid]; 21 return rooms[room_jid];
22 end 22 end
23 23
24 local button_ns = "xmpp:prosody.im/community/mod_slack_webhooks#buttons";
25 local routing = module:get_option("outgoing_webhook_routing") or {}; 24 local routing = module:get_option("outgoing_webhook_routing") or {};
26 local listen_path = module:get_option("incoming_webhook_path") or "/webhook"; 25 local listen_path = module:get_option("incoming_webhook_path") or "/webhook";
27 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot"; 26 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot";
28 27
29 function postcallback(_, code) 28 function postcallback(_, code)
54 timestamp = now(), 53 timestamp = now(),
55 text = body, 54 text = body,
56 team_domain = from_host, 55 team_domain = from_host,
57 user_name = from_nick, 56 user_name = from_nick,
58 }; 57 };
59
60 local form = stanza:get_child("x", "jabber:x:form");
61 if form and form.attr.type == "submit" then
62 local callback_id, button_name, button_value;
63 for field in form:childtags("field") do
64 if field.attr.var == "callback_id" then
65 button_name = field:get_child_text("text");
66 elseif field.attr.var == "button_name" then
67 button_name = field:get_child_text("text");
68 elseif field.attr.var ~= "FORM_TYPE" or field:get_child_text("text") ~= button_ns then
69 callback_id, button_name, button_value = nil, nil, nil;
70 break;
71 end
72 end
73 if callback_id and button_name and button_value then
74 json_out.callback_id = callback_id;
75 json_out.actions = {
76 { type = "button", name = button_name, value = button_value }
77 };
78 end
79 end
80
81 local stanzaid = stanza:get_child("id"); 58 local stanzaid = stanza:get_child("id");
82 if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then 59 if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then
83 json_out["bot_id"] = "webhookbot"; 60 json_out["bot_id"] = "webhookbot";
84 end 61 end
85 62
166 end 143 end
167 if button_name then 144 if button_name then
168 message:add_direct_child(dataform.new({ 145 message:add_direct_child(dataform.new({
169 { 146 {
170 type = "hidden", name = "FORM_TYPE", 147 type = "hidden", name = "FORM_TYPE",
171 value = button_ns, 148 value = "xmpp:prosody.im/community/mod_slack_webhooks#buttons",
172 }, 149 },
173 { 150 {
174 type = "hidden", name = "callback_id", 151 type = "hidden", name = "callback_id",
175 value = attachment.callback_id, 152 value = attachment.callback_id,
176 }, 153 },