-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.js
More file actions
55 lines (46 loc) · 1.2 KB
/
handler.js
File metadata and controls
55 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
const axios = require("axios");
const querystring = require("querystring");
module.exports.clapper = async event => {
const { text, user_id, response_url } = querystring.parse(event.body);
if (!text) {
return {
statusCode: 200,
body: `You need to submit text in order to use clapper`,
headers: { "X-Slack-No-Retry": 1 }
};
}
const words = text.split(" ");
if (words.length <= 1) {
return {
statusCode: 200,
body: `You need more than one word to use clapper.`,
headers: { "X-Slack-No-Retry": 1 }
};
}
let output = "";
for (let i = 0; i < words.length; i++) {
output += i !== words.length - 1 ? `${words[i]} :clap: ` : words[i];
}
const response = JSON.stringify({
attachments: [
{
text: output
}
],
response_type: "in_channel",
text: `<@${user_id}>`
});
await axios.post(response_url, response).catch(e => console.log(e));
return { statusCode: 200 };
};
module.exports.redirect = async event => {
return {
statusCode: 302,
headers: {
Location:
"https://slack.com/oauth/v2/authorize?client_id=860725329527.956870149255&scope=commands"
},
body: ""
};
};