This repository was archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_features.js
197 lines (173 loc) · 7.63 KB
/
slack_features.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const { SlackDialog } = require('botbuilder-adapter-slack');
module.exports = function(controller) {
controller.ready(async () => {
if (process.env.MYTEAM) {
let bot = await controller.spawn(process.env.MYTEAM);
await bot.startConversationInChannel(process.env.MYCHAN,process.env.MYUSER);
bot.say('I AM AWOKEN.');
}
});
controller.on('direct_message', async(bot, message) => {
await bot.reply(message,'I heard a private message');
});
controller.hears('dm me', 'message', async(bot, message) => {
await bot.startPrivateConversation(message.user);
await bot.say(`Let's talk in private.`);
});
controller.on('direct_mention', async(bot, message) => {
await bot.reply(message, `I heard a direct mention that said "${ message.text }"`);
});
controller.on('mention', async(bot, message) => {
await bot.reply(message, `You mentioned me when you said "${ message.text }"`);
});
controller.hears('ephemeral', 'message,direct_message', async(bot, message) => {
await bot.replyEphemeral(message,'This is an ephemeral reply sent using bot.replyEphemeral()!');
});
controller.hears('threaded', 'message,direct_message', async(bot, message) => {
await bot.replyInThread(message,'This is a reply in a thread!');
await bot.startConversationInThread(message.channel, message.user, message.incoming_message.channelData.ts);
await bot.say('And this should also be in that thread!');
});
controller.hears('blocks', 'message', async(bot, message) => {
await bot.reply(message,{
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
},
"accessory": {
"type": "image",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Farmhouse",
"emoji": true
},
"value": "Farmhouse"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Kin Khao",
"emoji": true
},
"value": "Kin Khao"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Ler Ros",
"emoji": true
},
"value": "Ler Ros"
}
]
}
]
});
});
controller.on('block_actions', async (bot, message) => {
await bot.reply(message, `Sounds like your choice is ${ message.incoming_message.channelData.actions[0].value }`)
});
controller.on('slash_command', async(bot, message) => {
if (message.text === 'plain') {
await bot.reply(message, 'This is a plain reply');
} else if (message.text === 'public') {
await bot.replyPublic(message, 'This is a public reply');
} else if (message.text === 'private') {
await bot.replyPrivate(message, 'This is a private reply');
}
// set http status
bot.httpBody({text:'You can send an immediate response using bot.httpBody()'});
});
controller.on('interactive_message', async (bot, message) => {
console.log('INTERACTIVE MESSAGE', message);
switch(message.actions[0].name) {
case 'replace':
await bot.replyInteractive(message,'[ A previous message was successfully replaced with this less exciting one. ]');
break;
case 'dialog':
await bot.replyWithDialog(message, new SlackDialog('this is a dialog', '123', 'Submit', [
{
type: 'text',
label: 'Field 1',
name: 'field1',
},
{
type: 'text',
label: 'Field 2',
name: 'field2',
}
]).notifyOnCancel(true).state('foo').asObject());
break;
default:
await bot.reply(message, 'Got a button click!');
}
});
controller.on('dialog_submission', async (bot, message) => {
await bot.reply(message, 'Got a dialog submission');
// Return an error to Slack
bot.dialogError([
{
"name": "field1",
"error": "there was an error in field1"
}
])
});
controller.on('dialog_cancellation', async (bot, message) => {
await bot.reply(message, 'Got a dialog cancellation');
});
}