changeset 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
files mod_slack_webhooks/mod_slack_webhooks.lua
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_slack_webhooks/mod_slack_webhooks.lua	Sun Jun 03 02:02:51 2018 +0200
+++ b/mod_slack_webhooks/mod_slack_webhooks.lua	Sun Jun 03 02:02:56 2018 +0200
@@ -23,6 +23,7 @@
 	end
 end
 
+local button_ns = "xmpp:prosody.im/community/mod_slack_webhooks#buttons";
 local routing = module:get_option("outgoing_webhook_routing") or {};
 local listen_path = module:get_option("incoming_webhook_path") or "/webhook";
 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot";
@@ -59,6 +60,28 @@
 		team_domain = from_host,
 		user_name = from_nick,
 	};
+
+	local form = stanza:get_child("x", "jabber:x:form");
+	if form and form.attr.type == "submit" then
+		local callback_id, button_name, button_value;
+		for field in form:childtags("field") do
+			if field.attr.var == "callback_id" then
+				button_name = field:get_child_text("text");
+			elseif field.attr.var == "button_name" then
+				button_name = field:get_child_text("text");
+			elseif field.attr.var ~= "FORM_TYPE" or field:get_child_text("text") ~= button_ns then
+				callback_id, button_name, button_value = nil, nil, nil;
+				break;
+			end
+		end
+		if callback_id and button_name and button_value then
+			json_out.callback_id = callback_id;
+			json_out.actions = {
+				{ type = "button", name = button_name, value = button_value }
+			};
+		end
+	end
+
 	local stanzaid = stanza:get_child("id");
 	if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then
 		json_out["bot_id"] = "webhookbot";
@@ -147,7 +170,7 @@
 					message:add_direct_child(dataform.new({
 						{
 							type = "hidden", name = "FORM_TYPE",
-							value = "xmpp:prosody.im/community/mod_slack_webhooks#buttons",
+							value = button_ns,
 						},
 						{
 							type = "hidden", name = "callback_id",