# HG changeset patch # User Kim Alvefur # Date 1621623519 -7200 # Node ID c6b740ccf6ec4090995843d352f3e6fd6e0e6e16 # Parent 724003f24308882d994e14932959d6e74c6951a1 Back out 662423cea3f4 (non-standard buttons) diff -r 724003f24308 -r c6b740ccf6ec mod_slack_webhooks/mod_slack_webhooks.lua --- a/mod_slack_webhooks/mod_slack_webhooks.lua Fri May 21 20:58:10 2021 +0200 +++ b/mod_slack_webhooks/mod_slack_webhooks.lua Fri May 21 20:58:39 2021 +0200 @@ -12,7 +12,6 @@ local json = require "util.json" local formdecode = require "net.http".formdecode; local http = require "net.http"; -local dataform = require "util.dataforms"; local mod_muc = module:depends"muc"; local rooms = rawget(mod_muc, "rooms"); @@ -113,59 +112,6 @@ module:log("debug", "message to %s from %s", bare_room, sender); module:log("debug", "body: %s", post_body["text"]); local message = msg({ to = bare_room, from = sender, type = "groupchat", id="webhookbot" .. now()},post_body["text"]); - - if type(post_body["attachments"]) == "table" then -- Buttons? - -- luacheck: ignore 631 - -- defensive against JSON having whatever data in it, enjoy - - for _, attachment in ipairs(post_body["attachments"]) do - if type(attachment) == "table" and type(attachment.actions) == "table" and type(attachment.callback_id) == "string" then - local buttons = {}; - local button_name; - for _, action in ipairs(attachment.actions) do - if type(attachment.text) == "string" then - buttons.label = attachment.text; - end - if type(action) == "table" and action.type == "button" and type(action.name) == "string" and type(action.value) == "string" then - if not button_name then - button_name = action.name; - end - if button_name == action.name then - local button = { - value = action.value; - }; - if type(action.text) == "string" then - button.label = action.text; - end - table.insert(buttons, button); - end - end - end - if button_name then - message:add_direct_child(dataform.new({ - { - type = "hidden", name = "FORM_TYPE", - value = "xmpp:prosody.im/community/mod_slack_webhooks#buttons", - }, - { - type = "hidden", name = "callback_id", - value = attachment.callback_id, - }, - { - type = "hidden", name = "button_name", - value = button_name, - }, - { - type = "list-single", name = "buttons", - value = "", -- FIXME util.dataforms can't do options without a value - options = buttons; - } - }):form()); - break; - end - end - end - end dest_room:broadcast_message(message, true); return 201; end