Mercurial > prosody-modules
comparison mod_slack_webhooks/mod_slack_webhooks.lua @ 3095:3a6a48b83b4f
mod_slack_webhooks: Reduce scope of variable
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 02 Jun 2018 15:00:27 +0200 |
| parents | 39d714abbc2b |
| children | 420391fd56e5 |
comparison
equal
deleted
inserted
replaced
| 3094:39d714abbc2b | 3095:3a6a48b83b4f |
|---|---|
| 91 local mod_muc = host_session.muc; | 91 local mod_muc = host_session.muc; |
| 92 local request = event.request; | 92 local request = event.request; |
| 93 local headers = request.headers; | 93 local headers = request.headers; |
| 94 | 94 |
| 95 local body_type = headers.content_type; | 95 local body_type = headers.content_type; |
| 96 local message; | |
| 97 local post_body; | 96 local post_body; |
| 98 if body_type == "application/x-www-form-urlencoded" then | 97 if body_type == "application/x-www-form-urlencoded" then |
| 99 post_body = formdecode(request.body)["payload"]; | 98 post_body = formdecode(request.body)["payload"]; |
| 100 elseif body_type == "application/json" then | 99 elseif body_type == "application/json" then |
| 101 if not pcall(function() post_body = json.decode(request.body) end) then | 100 if not pcall(function() post_body = json.decode(request.body) end) then |
| 111 from_nick = post_body["username"]; | 110 from_nick = post_body["username"]; |
| 112 end | 111 end |
| 113 local sender = jid.join(path, module.host, from_nick); | 112 local sender = jid.join(path, module.host, from_nick); |
| 114 module:log("debug", "message to %s from %s", bare_room, sender); | 113 module:log("debug", "message to %s from %s", bare_room, sender); |
| 115 module:log("debug", "body: %s", post_body["text"]); | 114 module:log("debug", "body: %s", post_body["text"]); |
| 116 message = msg({ to = bare_room, from = sender, type = "groupchat", id="webhookbot" .. now()},post_body["text"]); | 115 local message = msg({ to = bare_room, from = sender, type = "groupchat", id="webhookbot" .. now()},post_body["text"]); |
| 117 dest_room:broadcast_message(message, true); | 116 dest_room:broadcast_message(message, true); |
| 118 return 201; | 117 return 201; |
| 119 end | 118 end |
| 120 | 119 |
| 121 module:provides("http", { | 120 module:provides("http", { |
