-
Notifications
You must be signed in to change notification settings - Fork 400
/
app.js
64 lines (55 loc) · 1.98 KB
/
app.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
const { App, AwsLambdaReceiver } = require('@slack/bolt');
// Initialize your custom receiver
const awsLambdaReceiver = new AwsLambdaReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
});
// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
receiver: awsLambdaReceiver,
// When using the AwsLambdaReceiver, processBeforeResponse can be omitted.
// If you use other Receivers, such as ExpressReceiver for OAuth flow support
// then processBeforeResponse: true is required. This option will defer sending back
// the acknowledgement until after your handler has run to ensure your function
// isn't terminated early by responding to the HTTP request that triggered it.
// processBeforeResponse: true
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// say() sends a message to the channel where the event was triggered
await say({
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Hey there <@${message.user}>!`,
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Click Me',
},
action_id: 'button_click',
},
},
],
text: `Hey there <@${message.user}>!`,
});
});
// Listens for an action from a button click
app.action('button_click', async ({ body, ack, say }) => {
await ack();
await say(`<@${body.user.id}> clicked the button`);
});
// Listens to incoming messages that contain "goodbye"
app.message('goodbye', async ({ message, say }) => {
// say() sends a message to the channel where the event was triggered
await say(`See ya later, <@${message.user}> :wave:`);
});
// Handle the Lambda function event
module.exports.handler = async (event, context, callback) => {
const handler = await awsLambdaReceiver.start();
return handler(event, context, callback);
};