-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-lab-4.js
90 lines (82 loc) · 2.21 KB
/
app-lab-4.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
const { App } = require('@slack/bolt')
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
});
(async () => {
// Start your app
await app.start(process.env.PORT || 3000)
console.log('⚡️Hello World.. Bolt app is running!')
})()
// A slash command that shows an ephemeral message
app.command('/weather-gen', async ({ command, context, ack }) => {
ack()
app.client.chat.postEphemeral({
token: context.botToken,
channel: command.channel_id,
user: command.user_id,
text: "Hello World",
blocks: [
{
type: 'section',
block_id: 'block1',
text: {
type: 'mrkdwn',
text: 'Which city would you like a weather report for? :sunny::snowman_without_snow::umbrella:'
},
accessory: {
type: 'external_select',
placeholder: {
type: 'plain_text',
text: 'Select an item'
},
action_id: 'choose_city',
min_query_length: 3
}
}
]
})
})
// responds with options
app.options({ action_id: 'choose_city' }, async ({ ack }) => {
// Get information specific to a team or channel
const results = [
{ label: 'New York City', value: 'NYC' },
{ label: 'London', value: 'LON' },
{ label: 'San Francisco', value: 'SF' }
]
if (results) {
const options = []
// Collect information in options array to send in Slack ack response
await results.forEach(result => {
options.push({
text: {
type: 'plain_text',
text: result.label
},
value: result.value
})
})
console.log(options)
ack({
options
})
} else {
ack()
}
})
// prompt weather condition based on selection
app.action('choose_city', async ({ ack, say, action }) => {
ack()
const selectedCity = action.selected_option.value
if (selectedCity === 'NYC') {
say(`You selected the option ${action.selected_option.text.text} --> "It's 80 degrees right now in New York!`)
}
if (selectedCity === 'LON') {
say(`You selected the option ${action.selected_option.text.text} --> "It's 60 degrees right now in London!`)
}
if (selectedCity === 'SF') {
say(`You selected the option ${action.selected_option.text.text} --> "It's 70 degrees right now in San Francisco!`)
}
})