-
Notifications
You must be signed in to change notification settings - Fork 28
/
handler.js
33 lines (29 loc) · 949 Bytes
/
handler.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
// This example uses a Slack incoming webhook (https://api.slack.com/incoming-webhooks)
// Create a Slack app and webhook and update this endpoint
const endpoint = "https://hooks.slack.com/services/REDACTED"
async function onTrack(event, settings) {
if (!event.email) {
throw new InvalidEventPayload("email is required")
}
const hash = crypto.createHash('md5').update(event.email).digest("hex");
const res = await fetch(endpoint, {
body: JSON.stringify({
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `${event.email} ${event.event.toLowerCase()} for a *${event.properties.plan}* plan`
},
"accessory": {
"type": "image",
"image_url": `https://www.gravatar.com/avatar/${hash}`,
"alt_text": event.email,
}
}
]
}),
method: "post",
})
return await res.text()
}