-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (106 loc) · 3.07 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const { App, ExpressReceiver } = require('@slack/bolt');
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: '/events',
processBeforeResponse: true,
});
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
receiver: expressReceiver,
processBeforeResponse: true
});
app.error(console.error);
app.event('link_shared', async ({ event, client, ack }) => {
try {
console.log(event);
await handleGCPLink({ event, client, ack });
await handleNotionLink({ event, client, ack });
await handleFigmaLink({ event, client, ack });
ack && ack();
}
catch (error) {
console.error(error);
}
});
const handleNotionLink = async ({ event, client, ack }) => {
if (event.links[0].url.includes('notion.so/')) {
const linkPath = event.links[0].url.split('notion.so/').pop();
const newLink = linkPath && `<notion://${linkPath}/>`;
if (newLink) {
try {
await client.chat.postMessage({
channel: event.channel,
thread_ts: event.thread_ts || event.message_ts,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": newLink
}
}
]
});
} catch (e) {
console.error(e);
}
}
}
};
const handleGCPLink = async ({ event, client, ack }) => {
if (event.links[0].url.includes('https://console.cloud.google.com/')) {
const link = event.links[0].url
const newLink = `https://accounts.google.com/AccountChooser/signinchooser?continue=${encodeURIComponent(link)}&flowName=GlifWebSignIn&flowEntry=AccountChooser`;
try {
await client.chat.postMessage({
channel: event.channel,
thread_ts: event.thread_ts || event.message_ts,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": newLink
}
}
]
});
} catch (e) {
console.error(e);
}
}
}
const handleFigmaLink = async ({ event, client, ack }) => {
if (event.links[0].url.includes('https://www.figma.com/')) {
const linkPath = event.links[0].url.split('figma.com/').pop();
const newLink = linkPath && `<figma://${linkPath}/>`;
try {
await client.chat.postMessage({
channel: event.channel,
thread_ts: event.thread_ts || event.message_ts,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": newLink
}
}
]
});
} catch (e) {
console.error(e);
}
}
}
/**
* HTTP Cloud Function (llama)
*
* @param {Object} req Cloud Function request context.
* More info: https://expressjs.com/en/api.html#req
* @param {Object} res Cloud Function response context.
* More info: https://expressjs.com/en/api.html#res
*/
exports.llama = expressReceiver.app;
console.log('⚡️ Llama is running!');