Mercurial > prosody-modules
annotate mod_slack_webhooks/mod_slack_webhooks.lua @ 3092:0f63e999d0e4
mod_slack_webhooks: Remove unused locals [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 02 Jun 2018 14:58:28 +0200 |
parents | b6cac9d72255 |
children | 7ed0589eff3c |
rev | line source |
---|---|
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
1 -- Allow Slack-style incoming and outgoing hooks to MUC rooms |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
2 -- Based on mod_muc_intercom and mod_post_msg |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
3 -- Copyright 2016-2017 Nathan Whitehorn <nwhitehorn@physics.ucla.edu> |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
4 -- |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
5 -- This file is MIT/X11 licensed. |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
6 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
7 module:depends"http" |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
8 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
9 local host_session = prosody.hosts[module.host]; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
10 local msg = require "util.stanza".message; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
11 local jid = require "util.jid"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
12 local now = require "util.datetime".datetime; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
13 local json = require "util.json" |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
14 local formdecode = require "net.http".formdecode; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
15 local http = require "net.http"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
16 |
3071
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
17 local function get_room_from_jid(mod_muc, jid) |
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
18 if mod_muc.get_room_from_jid then |
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
19 return mod_muc.get_room_from_jid(jid); |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
20 elseif mod_muc.rooms then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
21 return mod_muc.rooms[jid]; -- COMPAT 0.9, 0.10 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
22 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
23 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
24 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
25 local routing = module:get_option("outgoing_webhook_routing") or {}; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
26 local listen_path = module:get_option("incoming_webhook_path") or "/webhook"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
27 local default_from_nick = module:get_option("incoming_webhook_default_nick") or "Bot"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
28 |
3092
0f63e999d0e4
mod_slack_webhooks: Remove unused locals [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3071
diff
changeset
|
29 function postcallback(_, code) |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
30 module:log("debug", "HTTP result %d", code) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
31 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
32 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
33 function check_message(data) |
3092
0f63e999d0e4
mod_slack_webhooks: Remove unused locals [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3071
diff
changeset
|
34 local stanza = data.stanza; |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
35 local mod_muc = host_session.muc; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
36 if not mod_muc then return; end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
37 |
3071
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
38 local this_room = get_room_from_jid(mod_muc, stanza.attr.to); |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
39 if not this_room then return; end -- no such room |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
40 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
41 local from_room_jid = this_room._jid_nick[stanza.attr.from]; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
42 if not from_room_jid then return; end -- no such nick |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
43 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
44 local from_room, from_host, from_nick = jid.split(from_room_jid); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
45 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
46 local body = stanza:get_child("body"); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
47 if not body then return; end -- No body, like topic changes |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
48 body = body and body:get_text(); -- I feel like I want to do `or ""` there :/ |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
49 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
50 if not routing[from_room] then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
51 return; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
52 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
53 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
54 local json_out = {channel_name = from_room, timestamp = now(), text = body, team_domain = from_host, user_name = from_nick}; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
55 local stanzaid = stanza:get_child("id"); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
56 if stanzaid and string.sub(stanzaid,1,string.len("webhookbot"))=="webhookbot" then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
57 json_out["bot_id"] = "webhookbot"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
58 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
59 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
60 json_out = json.encode(json_out) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
61 local url = routing[from_room]; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
62 module:log("debug", "message from %s in %s to %s", from_nick, from_room, url); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
63 local headers = { |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
64 ["Content-Type"] = "application/json", |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
65 }; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
66 http.request(url, { method = "POST", body = json_out, headers = headers }, postcallback) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
67 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
68 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
69 module:hook("message/bare", check_message, 10); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
70 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
71 local function route_post(f) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
72 return function(event, path) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
73 local bare_room = jid.join(path, module.host); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
74 local mod_muc = host_session.muc; |
3071
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
75 if not get_room_from_jid(mod_muc, bare_room) then |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
76 module:log("warn", "mod_slack_webhook: invalid JID: %s", bare_room); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
77 return 404; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
78 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
79 -- Check secret? |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
80 return f(event, path) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
81 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
82 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
83 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
84 local function handle_post(event, path) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
85 local mod_muc = host_session.muc; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
86 local request = event.request; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
87 local headers = request.headers; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
88 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
89 local body_type = headers.content_type; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
90 local message; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
91 local post_body; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
92 if body_type == "application/x-www-form-urlencoded" then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
93 post_body = formdecode(request.body)["payload"]; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
94 elseif body_type == "application/json" then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
95 if not pcall(function() post_body = json.decode(request.body) end) then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
96 return 420; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
97 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
98 else |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
99 return 422; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
100 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
101 local bare_room = jid.join(path, module.host); |
3071
b6cac9d72255
mod_slack_webhooks: Use the correct MUC API
Kim Alvefur <zash@zash.se>
parents:
3000
diff
changeset
|
102 local dest_room = get_room_from_jid(mod_muc, bare_room); |
3000
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
103 local from_nick = default_from_nick; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
104 if post_body["username"] then |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
105 from_nick = post_body["username"]; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
106 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
107 local sender = jid.join(path, module.host, from_nick); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
108 module:log("debug", "message to %s from %s", bare_room, sender); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
109 module:log("debug", "body: %s", post_body["text"]); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
110 message = msg({ to = bare_room, from = sender, type = "groupchat", id="webhookbot" .. now()},post_body["text"]); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
111 dest_room:broadcast_message(message, true); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
112 return 201; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
113 end |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
114 |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
115 module:provides("http", { |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
116 default_path = listen_path; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
117 route = { |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
118 ["POST /*"] = route_post(handle_post); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
119 OPTIONS = function(e) |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
120 local headers = e.response.headers; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
121 headers.allow = "POST"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
122 headers.accept = "application/x-www-form-urlencoded, application/json"; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
123 return 200; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
124 end; |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
125 } |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
126 }); |
02fc3b64cbb7
Initial commit of mod_slack_webhooks.
Nathan Whitehorn <nwhitehorn@physics.ucla.edu>
parents:
diff
changeset
|
127 |