slack-smart-bot 1.9.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +184 -16
- data/lib/slack/smart-bot/comm/ask.rb +55 -49
- data/lib/slack/smart-bot/comm/delete.rb +13 -0
- data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
- data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
- data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +19 -2
- data/lib/slack/smart-bot/comm/respond.rb +224 -53
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
- data/lib/slack/smart-bot/comm/unreact.rb +22 -18
- data/lib/slack/smart-bot/comm.rb +4 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
- data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
- data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
- data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
- data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
- data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
- data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +115 -0
- data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
- data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +34 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
- data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
- data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
- data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
- data/lib/slack/smart-bot/commands.rb +36 -5
- data/lib/slack/smart-bot/listen.rb +31 -33
- data/lib/slack/smart-bot/process.rb +234 -73
- data/lib/slack/smart-bot/process_first.rb +119 -38
- data/lib/slack/smart-bot/treat_message.rb +310 -237
- data/lib/slack/smart-bot/utils/build_help.rb +2 -2
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
- data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
- data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
- data/lib/slack/smart-bot/utils/get_help.rb +79 -73
- data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
- data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
- data/lib/slack/smart-bot/utils/has_access.rb +28 -0
- data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
- data/lib/slack/smart-bot/utils/save_status.rb +67 -0
- data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
- data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
- data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
- data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
- data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
- data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
- data/lib/slack/smart-bot/utils.rb +11 -0
- data/lib/slack-smart-bot.rb +72 -12
- data/lib/slack-smart-bot_general_commands.rb +61 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +43 -17
- data/whats_new.txt +20 -15
- metadata +76 -9
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5ea9ccfc9d1c52925f5bdd6ef89c35158c19f8fafad8f5af99d9a6b8456b43
|
4
|
+
data.tar.gz: 6c3853c8977a29f85cba5013b06b8178ca6f0b4783ff323fd0fa96d7ad92ad5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d795ac13cfe68983064894f6fff8e7667cb939a78c9e2a044630aca021a4bd11c2be8a8cf6944fceebe8ea1b4ff5ca2d7455c4eb121edcd28ad8b89605ad4dc
|
7
|
+
data.tar.gz: e81573197080798f5cae34521b44744de6912895ba55049611f806059b171f69c5fe2d3bb30e790d1d158b2a06b71c449afcb61f96602fcdd070c240a9298f89
|
data/README.md
CHANGED
@@ -27,8 +27,13 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
|
|
27
27
|
+ [REPL](#repl)
|
28
28
|
* [Sending notifications](#sending-notifications)
|
29
29
|
* [Shortcuts](#shortcuts)
|
30
|
+
* [Announcements](#announcements)
|
31
|
+
* [Share Messages](#share-messages)
|
32
|
+
* [See Statuses](#see-statuses)
|
30
33
|
* [Routines](#routines)
|
31
|
-
* [
|
34
|
+
* [Control who has access to a command](#control-who-has-access-to-a-command)
|
35
|
+
* [See favorite commands](#see-favorite-commands)
|
36
|
+
* [Teams](#teams)
|
32
37
|
* [Tips](#tips)
|
33
38
|
+ [Send a file](#send-a-file)
|
34
39
|
+ [Download a file](#download-a-file)
|
@@ -81,7 +86,9 @@ You can get one by any of these options:
|
|
81
86
|
- *[Legacy API Token](https://api.slack.com/custom-integrations/legacy-tokens)*.
|
82
87
|
|
83
88
|
|
84
|
-
*Remember to invite the smart bot to the channels where they will be accessible before creating the bot*
|
89
|
+
*Remember to invite the smart bot to the channels where they will be accessible before creating the bot*
|
90
|
+
|
91
|
+
SmartBot will notify about SmartBot status changes or any SmartBot incident if defined the status_channel in settings file and the channel exists. By default: smartbot-status
|
85
92
|
|
86
93
|
## Usage
|
87
94
|
|
@@ -158,6 +165,21 @@ def rules(user, command, processed, dest)
|
|
158
165
|
|
159
166
|
unreact :runner
|
160
167
|
|
168
|
+
# Example sending blocks. More info: https://api.slack.com/block-kit
|
169
|
+
# help: It will return the info about who is the admin
|
170
|
+
when /\AWho is the admin\?\z/i
|
171
|
+
my_blocks = [
|
172
|
+
{ type: "context",
|
173
|
+
elements:
|
174
|
+
[
|
175
|
+
{ type: "plain_text", :text=>"\tAdmin: " },
|
176
|
+
{ type: "image", image_url: "https://avatars.slack-edge.com/2021-03-23/182815_e54abb1dd_24.jpg", alt_text: "mario" },
|
177
|
+
{ type: "mrkdwn", text: " *Mario Ruiz* (marior) " }
|
178
|
+
]
|
179
|
+
}
|
180
|
+
]
|
181
|
+
respond blocks: my_blocks
|
182
|
+
|
161
183
|
else
|
162
184
|
unless processed
|
163
185
|
dont_understand()
|
@@ -168,6 +190,7 @@ end
|
|
168
190
|
|
169
191
|
Also you can add general rules that will be available on all Smart Bot channels to `./rules/general_rules.rb`
|
170
192
|
|
193
|
+
If you have commands that want to make them available everywhere the Smart Bot is a member then add those commands to `./rules/general_commands.rb`.
|
171
194
|
|
172
195
|
### How to access the Smart Bot
|
173
196
|
You can access the bot directly on the MASTER CHANNEL, on a secondary channel where the bot is running and directly by opening a private chat with the bot, in this case the conversation will be just between you and the bot.
|
@@ -184,7 +207,7 @@ To run a command on demand:
|
|
184
207
|
**_`!THE_COMMAND`_**
|
185
208
|
**_`@NAME_OF_BOT THE_COMMAND`_**
|
186
209
|
**_`NAME_OF_BOT THE_COMMAND`_**
|
187
|
-
To run a command on demand and add the
|
210
|
+
To run a command on demand and add the response on a thread:
|
188
211
|
**_`^THE_COMMAND`_**
|
189
212
|
**_`!!THE_COMMAND`_**
|
190
213
|
|
@@ -203,14 +226,18 @@ Examples run a command on demand:
|
|
203
226
|
>**_Peter>_** `^echo Example`
|
204
227
|
>. . . . . . . . .**_Smart-Bot>_** `Example`
|
205
228
|
|
206
|
-
Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME. You can supply more than one channel then all the bots will respond.
|
229
|
+
Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME. You can supply more than one channel then all the bots will respond. In case you are in a private conversation with the Smart Bot (DM) then you can use directly: **_`#CHANNEL_NAME COMMAND`_** or **_`on #CHANNEL_NAME COMMAND`_**
|
207
230
|
|
208
|
-
|
231
|
+
Examples:
|
209
232
|
>**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
|
210
233
|
>**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
211
234
|
>**_Peter>_** `@smart-bot on #the_channel ^ruby puts Time.now`
|
212
235
|
>. . . . . . . . .**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
213
236
|
|
237
|
+
Examples on DM:
|
238
|
+
>**_Peter>_** `#sales show report from India`
|
239
|
+
>**_Peter>_** `on #sales notify clients`
|
240
|
+
|
214
241
|
If you want the Smart Bot just listen to part of the message you send, add the commands you want using '`' and start the line with '-!', '-!!' or '-^'
|
215
242
|
|
216
243
|
Examples:
|
@@ -222,6 +249,13 @@ Examples:
|
|
222
249
|
>. . . . . . . . .**_Smart-Bot>_** `a`
|
223
250
|
>. . . . . . . . .**_Smart-Bot>_** `b`
|
224
251
|
|
252
|
+
|
253
|
+
All the commands specified on `./rules/general_commands.rb` will be accessible from any channel where the Smart Bot is present, without the necessity to call it with !, !!, ^ or on demand.
|
254
|
+
|
255
|
+
Examples:
|
256
|
+
>**_Peter>_** `Thanks smartbot`
|
257
|
+
>**_Smart-Bot>_** `You're very welcome`
|
258
|
+
|
225
259
|
### Bot Help
|
226
260
|
To get a full list of all commands and rules for a specific Smart Bot: **_`bot help`_**. It will show only the specific available commands for the user requesting. By default it will display only a short version of the bot help, call **_`bot help expanded`_** to get a expanded version of all commands.
|
227
261
|
|
@@ -229,6 +263,8 @@ If you want to search just for a specific command: **_`bot help COMMAND`_** It w
|
|
229
263
|
|
230
264
|
To show only the specific rules of the Smart Bot defined on the rules file: **_`bot rules`_** or **_`bot rules COMMAND`_**
|
231
265
|
|
266
|
+
Also you can call `suggest command` or `random command` and SmartBot will return the help content for a random command.
|
267
|
+
|
232
268
|
Example:
|
233
269
|
>**_Peter>_** `bot help echo`
|
234
270
|
>**_Smart-Bot>_** `echo SOMETHING`
|
@@ -266,12 +302,18 @@ To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
|
|
266
302
|
|
267
303
|
If you need it you can set the SmartBot on maintenance mode by running: **_`set maintenance on`_**. A message to be displayed can be added if not the default message will be used. Run **_`set maintenance off`_** when you want the SmartBot to be running in normal conditions again.
|
268
304
|
|
305
|
+
To display a general message after every command use: `set general message MESSAGE`. Use `set general message off` to stop displaying it.
|
306
|
+
|
269
307
|
To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
|
270
308
|
|
271
|
-
If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. As a normal user you will get your own stats when calling **_`bot stats`_**. Take a look at `bot help bot stats` for more info.
|
309
|
+
If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. As a normal user you will get your own stats when calling **_`bot stats`_**. Take a look at `bot help bot stats` for more info. Also you can call **_`leaderboard`_** to get some useful information about the use of the SmartBot.
|
272
310
|
|
273
311
|
You can also get the bot logs of the bot channel you are using by calling `get bot logs`. You need to be a Master Admin user on a DM with the Smart Bot.
|
274
312
|
|
313
|
+
You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.
|
314
|
+
|
315
|
+
To see the full list of available command ids on any channel call: `see command ids`
|
316
|
+
|
275
317
|
#### Cloud Bots
|
276
318
|
If you want to create a bot that will be running on a different machine: **_`create cloud bot on CHANNEL`_**. Even though the cloud bots are running on different machines, the management can be done through the MASTER CHANNEL. The new cloud bot will be managed by your Master Bot like the others, closing, pausing...
|
277
319
|
|
@@ -298,7 +340,7 @@ Example:
|
|
298
340
|
>**_Peter>_** `!ruby require 'json'; res=[]; 20.times {res.push rand(100)}; my_json={result: res}; puts my_json.to_json`
|
299
341
|
>**_Smart-Bot>_** `{"result":[63,66,35,83,44,40,72,25,59,73,75,54,56,91,19,6,68,1,25,3]}`
|
300
342
|
|
301
|
-
Also it is possible to attach a Ruby file and the Smart Bot will run and post the output. You need to select Ruby as file format.
|
343
|
+
Also it is possible to attach a Ruby file and the Smart Bot will run and post the output. You need to select Ruby as file format. Or if you prefer it you can call the `ruby` command and on the same message supply a code block.
|
302
344
|
|
303
345
|
#### REPL
|
304
346
|
Easily starts a REPL session so you will be able to create a script directly from the slack conversation. You will be able to share the REPL so they can run it or see the content.
|
@@ -392,19 +434,64 @@ Example:
|
|
392
434
|
|
393
435
|
To see available shortcuts: **_`see shortcuts`_** and to delete a particular shortcut: **_`delete shortcut NAME`_**
|
394
436
|
|
437
|
+
### Announcements
|
438
|
+
You can add any announcement on any channel where the SmartBot is a member by using **_`add COLOR announcement MESSAGE`_** or **_`add EMOJI announcement MESSAGE`_**.
|
439
|
+
|
440
|
+
It will store the message on the announcement list labeled with the color/emoji specified, white by default. Possible colors white, green, yellow and red. Aliases for announcement: statement, declaration, message.
|
441
|
+
|
442
|
+
Examples:
|
443
|
+
>**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
|
444
|
+
>**_Peter>_** `add red message Customers db is down :x:`
|
445
|
+
>**_Peter>_** `add yellow statement Don't access the linux server without VPN`
|
446
|
+
>**_Peter>_** `add announcement Party will start at 20:00 :tada:`
|
447
|
+
>**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
|
448
|
+
|
449
|
+
To see the announcements of the channel: **_`see announcements`_**, **_`see COLOR announcements`_**, **_`see EMOJI announcements`_** and to delete a particular announcement: **_`delete announcement ID`_**
|
450
|
+
|
451
|
+
If you are a master admin and you are on master channel then you can call **_`publish announcements`_** that will publish the announcements on all channels. The messages stored on a DM won't be published. This is very convenient to be called from a *Routine* for example every weekday at 09:00.
|
452
|
+
|
453
|
+
### Share messages
|
454
|
+
You can automatically share any new message that is posted on the channel and meet the specified criteria by using **_`share messages /REGEXP/ on #CHANNEL`_** or **_`share messages "TEXT" on #CHANNEL`_**.
|
455
|
+
|
456
|
+
This command is only available in public channels. The user adding the Share and the SmartBot need to be a member of both channels.
|
457
|
+
|
458
|
+
Examples:
|
459
|
+
>**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
|
460
|
+
>**_Peter>_** `share messages "share post" on #announcements`
|
461
|
+
|
462
|
+
To see the shares of the channel: **_`see shares`_** and to delete a particular share: **_`delete share ID`_**
|
463
|
+
|
464
|
+
### See statuses
|
465
|
+
To see a list of statuses of the members in the channel you can call `see statuses`, `who is on vacation?`, `who is not on vacation?`, `who is on EMOJI`, `who is on EMOJI #CHANNEL`
|
466
|
+
|
467
|
+
You need to be a member of the channel to be able to get this info.
|
468
|
+
|
469
|
+
Examples:
|
470
|
+
>**_Peter>_** `see statuses`
|
471
|
+
>**_Peter>_** `who is on vacation?`
|
472
|
+
>**_Peter>_** `who is not on vacation?`
|
473
|
+
>**_Peter>_** `who is on vacation? #SalesChannel`
|
474
|
+
>**_Peter>_** `who is on :working-from-home:`
|
475
|
+
>**_Peter>_** `who is available?`
|
476
|
+
|
395
477
|
### Routines
|
396
478
|
To add specific commands to be run automatically every certain amount of time or a specific time: **_`add routine NAME every NUMBER PERIOD COMMAND`_** or **_`add routine NAME at TIME COMMAND`_**. Also just before the command you can supply the channel where you want to publish the results, if not channel supplied then it would be the SmartBot Channel or on the DM if the command is run from there. Remember the SmartBot needs to have access to the channel where you want to publish.
|
397
479
|
|
480
|
+
In case you create a *bgroutine* instead of a normal *routine* then the results of the run won't be published.
|
481
|
+
|
398
482
|
If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
|
399
483
|
|
484
|
+
To see the last result of the execution you can call `see result routine NAME`
|
485
|
+
|
400
486
|
Examples:
|
401
487
|
>**_`add routine run_tests every 3h !run tests on customers`_**
|
402
|
-
>**_`add
|
403
|
-
>**_`add silent
|
488
|
+
>**_`add bgroutine clean_db at 17:05 !clean customers temp db`_**
|
489
|
+
>**_`add silent bgroutine clean_db at 17:05 !clean customers temp db`_**
|
404
490
|
>**_`add routine clean_custdb on Mondays at 05:00 !clean customers db`_**
|
405
491
|
>**_`add routine clean_custdb on Tuesdays at 09:00 #SREChannel !clean customers db`_**
|
492
|
+
>**_`add silent routine suggestions on weekdays at 09:00 suggest command`_**
|
406
493
|
|
407
|
-
Also instead of adding a Command to be executed, you can attach a file, then the routine will be created and the attached file will be executed on the criteria specified. Only Master Admins are allowed to
|
494
|
+
Also instead of adding a Command to be executed, you can attach a file, then the routine will be created and the attached file will be executed on the criteria specified. Also you can supply a script adding \`\`\`the code\`\`\` and specifying on the routine name the extension that will have. Only Master Admins are allowed to add files or scripts.
|
408
495
|
|
409
496
|
Other routine commands:
|
410
497
|
* **_`pause routine NAME`_**
|
@@ -412,10 +499,15 @@ Other routine commands:
|
|
412
499
|
* **_`remove routine NAME`_**
|
413
500
|
* **_`run routine NAME`_**
|
414
501
|
* **_`see routines`_**
|
502
|
+
* **_`see result routine NAME`_**
|
415
503
|
|
416
|
-
###
|
504
|
+
### Control who has access to a command
|
417
505
|
|
418
|
-
|
506
|
+
You can add, remove and list admins of any channel by using: `add admin @user`, `remove admin @user` and `see admins`. You need to be the creator of the channel, a Master admin or an admin.
|
507
|
+
|
508
|
+
To see the full list of available command ids on any channel call: `see command ids`
|
509
|
+
|
510
|
+
If you want to define who has access to certain commands in all SmartBot instances, you can specify it on the settings when starting the Smart Bot:
|
419
511
|
|
420
512
|
```ruby
|
421
513
|
settings = {
|
@@ -431,15 +523,91 @@ settings = {
|
|
431
523
|
```
|
432
524
|
You can use the user name or the user id.
|
433
525
|
|
434
|
-
If you want to change who has access to a
|
526
|
+
If you want to change who has access to a specific command without restarting the Smart Bot you can do it on the rules file, for example:
|
435
527
|
|
436
528
|
```ruby
|
437
|
-
|
529
|
+
# helpadmin: ----------------------------------------------
|
530
|
+
# helpadmin: `update access`
|
531
|
+
# helpadmin: It will update the privileges to access commands or rules
|
532
|
+
# helpadmin:
|
533
|
+
when /\A\s*update\s+access\s*\z/i
|
534
|
+
save_stats(:update_access)
|
535
|
+
if is_admin?(user.name)
|
536
|
+
config.allow_access.repl = ['marioruiz', 'samcooke']
|
537
|
+
respond "updated on <##{@channel_id}>!"
|
538
|
+
else
|
539
|
+
respond 'Only admins can change the access rules'
|
540
|
+
end
|
438
541
|
```
|
439
542
|
|
440
|
-
|
543
|
+
To check from a rule if the user has access to it:
|
544
|
+
|
545
|
+
```ruby
|
546
|
+
if has_access?(:your_command_id)
|
547
|
+
end
|
548
|
+
```
|
549
|
+
|
550
|
+
Also you can allow or deny access for specific commands and users on any specific channel all you need is the Smartbot to be a member of the channel and use these commands on Slack:
|
551
|
+
`allow access COMMAND_ID`
|
552
|
+
`allow access COMMAND_ID @user1 @user99`
|
553
|
+
It will allow the specified command to be used on the channel.
|
554
|
+
If @user specified, only those users will have access to the command
|
555
|
+
Only admins of the channel can use this command.
|
556
|
+
|
557
|
+
`deny access COMMAND_ID`
|
558
|
+
It won't allow the specified command to be used on the channel.
|
559
|
+
Only admins of the channel can use this command
|
560
|
+
|
561
|
+
`see access COMMAND_ID`
|
562
|
+
it will show the access rights for the specified command
|
563
|
+
|
564
|
+
The authorization is controlled by `save_stats` so it will be check out when calling `save_stats` or by calling `has_access?(:your_command_id)`
|
565
|
+
|
566
|
+
### See favorite commands
|
567
|
+
|
568
|
+
It will display the favorite commands in that channel.
|
569
|
+
|
570
|
+
Examples:
|
571
|
+
>**_`see favorite commands`_**
|
572
|
+
>**_`favorite commands`_**
|
573
|
+
>**_`my favourite commands`_**
|
574
|
+
>**_`most used commands`_**
|
575
|
+
|
576
|
+
### Teams
|
577
|
+
|
578
|
+
You can add, update, see, ping and delete teams. When calling `see TEAM_NAME team` the availability of the members will be displayed.
|
579
|
+
`add team TEAM_NAME PROPERTIES` will add a team with the info supplied. In case it is supplied a channel with type 'members' the members of that channel would be considered members of the team.
|
580
|
+
|
581
|
+
Examples:
|
582
|
+
>**_`add team devweb members #devweb support #devweb-support : We take care of the website`_**
|
583
|
+
>**_`add team devweb qa @jim dev @johnja @cooke @luisa members #devweb support #devweb-support : We take care of the website`_**
|
584
|
+
>**_`add team sandex manager @sarah members #sandex : We take care of the sand`_**
|
585
|
+
|
586
|
+
By calling `update team` you will update a team with the info supplied.
|
587
|
+
|
588
|
+
Examples:
|
589
|
+
>**_`update team sales : Support for customers`_**
|
590
|
+
>**_`update sales team delete @sarah @peter`_**
|
591
|
+
>**_`update sales team add public #salesff`_**
|
592
|
+
>**_`update sales team add qa @john @ben @ana`_**
|
593
|
+
|
594
|
+
It is possible to search teams by user, info, channel or team name. In case calling `see team TEAM_NAME` or `TEAM_NAME team` it will show also the availavility of the members: on vacation, in a meeting, sick leave, away or available.
|
595
|
+
|
596
|
+
Examples:
|
597
|
+
>**_`see teams`_**
|
598
|
+
>**_`see Sales team`_**
|
599
|
+
>**_`which teams #salesff`_**
|
600
|
+
>**_`which teams @sarah`_**
|
601
|
+
>**_`which team does @john belongs to?`_**
|
602
|
+
|
603
|
+
By calling `ping team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all available members of the MEMBER_TYPE supplied.
|
604
|
+
If you call `contact team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all members of the MEMBER_TYPE supplied.
|
605
|
+
|
606
|
+
Examples:
|
607
|
+
>**_`ping team sales development What's the status on last deployment?`_**
|
608
|
+
>**_`contact team sales qa Please finish testing of dev02 feature before noon`_**
|
441
609
|
|
442
|
-
|
610
|
+
Other team commands: **_`delete team TEAM_NAME`_**
|
443
611
|
|
444
612
|
|
445
613
|
### Tips
|
@@ -3,61 +3,67 @@ class SlackSmartBot
|
|
3
3
|
#context: previous message
|
4
4
|
#to: user that should answer
|
5
5
|
def ask(question, context = nil, to = nil, dest = nil)
|
6
|
-
|
7
|
-
dest
|
8
|
-
|
9
|
-
|
10
|
-
to
|
11
|
-
|
12
|
-
if context.nil?
|
13
|
-
context = Thread.current[:command]
|
14
|
-
end
|
15
|
-
message = "#{to}: #{question}"
|
16
|
-
if dest.nil?
|
17
|
-
if config[:simulate]
|
18
|
-
open("#{config.path}/buffer_complete.log", "a") { |f|
|
19
|
-
f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
|
20
|
-
}
|
21
|
-
else
|
22
|
-
if Thread.current[:on_thread]
|
23
|
-
client.message(channel: @channel_id, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
|
24
|
-
else
|
25
|
-
client.message(channel: @channel_id, text: message, as_user: true)
|
26
|
-
end
|
6
|
+
begin
|
7
|
+
if dest.nil? and Thread.current.key?(:dest)
|
8
|
+
dest = Thread.current[:dest]
|
9
|
+
end
|
10
|
+
if to.nil?
|
11
|
+
to = Thread.current[:user].name
|
27
12
|
end
|
28
|
-
if
|
29
|
-
|
30
|
-
f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
|
31
|
-
}
|
13
|
+
if context.nil?
|
14
|
+
context = Thread.current[:command]
|
32
15
|
end
|
33
|
-
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
16
|
+
message = "#{to}: #{question}"
|
17
|
+
if dest.nil?
|
18
|
+
if config[:simulate]
|
19
|
+
open("#{config.path}/buffer_complete.log", "a") { |f|
|
20
|
+
f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
|
21
|
+
}
|
22
|
+
else
|
23
|
+
if Thread.current[:on_thread]
|
24
|
+
client.message(channel: @channel_id, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
|
25
|
+
else
|
26
|
+
client.message(channel: @channel_id, text: message, as_user: true)
|
27
|
+
end
|
43
28
|
end
|
29
|
+
if config[:testing] and config.on_master_bot and !@buffered
|
30
|
+
@buffered = true
|
31
|
+
open("#{config.path}/buffer.log", "a") { |f|
|
32
|
+
f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
elsif dest[0] == "C" or dest[0] == "G" # channel
|
36
|
+
if config[:simulate]
|
37
|
+
open("#{config.path}/buffer_complete.log", "a") { |f|
|
38
|
+
f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
|
39
|
+
}
|
40
|
+
else
|
41
|
+
if Thread.current[:on_thread]
|
42
|
+
client.message(channel: dest, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
|
43
|
+
else
|
44
|
+
client.message(channel: dest, text: message, as_user: true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if config[:testing] and config.on_master_bot and !@buffered
|
48
|
+
@buffered = true
|
49
|
+
open("#{config.path}/buffer.log", "a") { |f|
|
50
|
+
f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
elsif dest[0] == "D" #private message
|
54
|
+
send_msg_user(dest, message)
|
44
55
|
end
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
if Thread.current[:on_thread]
|
57
|
+
qdest = Thread.current[:thread_ts]
|
58
|
+
else
|
59
|
+
qdest = dest
|
49
60
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
qdest = dest
|
61
|
+
@answer[to] = {} unless @answer.key?(to)
|
62
|
+
@answer[to][qdest] = context
|
63
|
+
@questions[to] = context # to be backwards compatible #todo remove it when 2.0
|
64
|
+
rescue Exception => stack
|
65
|
+
@logger.warn stack
|
57
66
|
end
|
58
|
-
@answer[to] = {} unless @answer.key?(to)
|
59
|
-
@answer[to][qdest] = context
|
60
|
-
@questions[to] = context # to be backwards compatible #todo remove it when 2.0
|
61
67
|
end
|
62
68
|
|
63
69
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def delete(channel, ts)
|
3
|
+
result = true
|
4
|
+
begin
|
5
|
+
resp = client.web_client.chat_delete(channel: channel, as_user: true, ts: ts)
|
6
|
+
result = resp.ok.to_s == 'true'
|
7
|
+
rescue Exception => exc
|
8
|
+
result = false
|
9
|
+
@logger.fatal exc.inspect
|
10
|
+
end
|
11
|
+
return result
|
12
|
+
end
|
13
|
+
end
|
@@ -11,8 +11,8 @@ class SlackSmartBot
|
|
11
11
|
get_bots_created()
|
12
12
|
end
|
13
13
|
text = get_help(rules_file, dest, user.name, typem==:on_extended, true)
|
14
|
-
|
15
|
-
ff = text.scan(
|
14
|
+
|
15
|
+
ff = text.scan(/^\s*`\s*([^`]+)\s*`\s*$/i).flatten
|
16
16
|
ff.delete("!THE_COMMAND")
|
17
17
|
ff.delete("@NAME_OF_BOT THE_COMMAND")
|
18
18
|
ff.delete("NAME_OF_BOT THE_COMMAND")
|
@@ -50,7 +50,7 @@ class SlackSmartBot
|
|
50
50
|
end
|
51
51
|
else
|
52
52
|
message = ''
|
53
|
-
message = "\nTake in consideration when on external calls, not all the commands are
|
53
|
+
message = "\nTake in consideration when on external calls, not all the commands are available." if typem==:on_call
|
54
54
|
if res_final.empty?
|
55
55
|
resp = answer.sample
|
56
56
|
respond "#{user.profile.display_name}, #{resp}#{message}", dest
|
@@ -3,11 +3,13 @@ class SlackSmartBot
|
|
3
3
|
unless config.simulate
|
4
4
|
m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
|
5
5
|
puts m
|
6
|
+
save_status :on, :connected, m
|
7
|
+
|
6
8
|
@logger.info m
|
7
9
|
config.nick = client.self.name
|
8
10
|
config.nick_id = client.self.id
|
9
11
|
end
|
10
|
-
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
|
12
|
+
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "@#{config[:nick]}", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
|
11
13
|
|
12
14
|
gems_remote = `gem list slack-smart-bot --remote`
|
13
15
|
version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
|
@@ -16,13 +18,15 @@ class SlackSmartBot
|
|
16
18
|
version_message = ". There is a new available version: #{version_remote}."
|
17
19
|
end
|
18
20
|
if (!config[:silent] or ENV['BOT_SILENT'].to_s == 'false') and !config.simulate
|
19
|
-
ENV['BOT_SILENT']
|
20
|
-
|
21
|
+
unless ENV['BOT_SILENT']=='true'
|
22
|
+
respond "Smart Bot started v#{VERSION}#{version_message}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
|
23
|
+
end
|
24
|
+
ENV['BOT_SILENT'] = 'true' if config[:silent] and ENV['BOT_SILENT'].to_s != 'true'
|
21
25
|
end
|
22
26
|
@routines.each do |ch, rout|
|
23
27
|
rout.each do |k, v|
|
24
28
|
if !v[:running] and v[:channel_name] == config.channel
|
25
|
-
create_routine_thread(k)
|
29
|
+
create_routine_thread(k, v)
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -1,8 +1,17 @@
|
|
1
|
+
#todo: add pagination for case more than 1000 members in the channel
|
1
2
|
def get_channel_members(channel_id)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
begin
|
4
|
+
if channel_id.nil?
|
5
|
+
return nil
|
6
|
+
else
|
7
|
+
if config.simulate and config.key?(:client)
|
8
|
+
client.web_client.conversations_members[channel_id.to_sym].members
|
9
|
+
else
|
10
|
+
client.web_client.conversations_members(channel: channel_id, limit: 1000).members
|
11
|
+
end
|
12
|
+
end
|
13
|
+
rescue Exception => stack
|
14
|
+
@logger.warn stack
|
6
15
|
end
|
7
16
|
|
8
17
|
end
|
@@ -1,20 +1,35 @@
|
|
1
|
-
def get_channels(bot_is_in: false)
|
1
|
+
def get_channels(bot_is_in: false, types: 'private_channel,public_channel')
|
2
|
+
begin
|
2
3
|
if config.simulate and config.key?(:client)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
if bot_is_in
|
5
|
+
client.web_client.conversations_members.reject { |r, v| !v.members.include?(config.nick_id) }.values
|
6
|
+
else
|
7
|
+
client.web_client.conversations_members.values
|
8
|
+
end
|
8
9
|
else
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
if bot_is_in
|
11
|
+
client.web_client.users_conversations(exclude_archived: true, limit: 1000, types: "im, public_channel,private_channel").channels
|
12
|
+
else
|
13
|
+
resp = client.web_client.conversations_list(types: types, limit: "600", exclude_archived: "true")
|
14
|
+
channels = resp.channels
|
15
|
+
begin
|
16
|
+
while resp.response_metadata.next_cursor.to_s != ""
|
17
|
+
resp = client.web_client.conversations_list(
|
18
|
+
cursor: resp.response_metadata.next_cursor.to_s,
|
19
|
+
types: types,
|
20
|
+
limit: "600",
|
21
|
+
exclude_archived: "true",
|
22
|
+
)
|
23
|
+
channels += resp.channels
|
24
|
+
end
|
25
|
+
rescue Exception => stack
|
26
|
+
@logger.warn stack
|
18
27
|
end
|
28
|
+
return channels
|
29
|
+
end
|
19
30
|
end
|
20
|
-
|
31
|
+
rescue Exception => stack
|
32
|
+
@logger.warn stack
|
33
|
+
return []
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def get_presence(user)
|
4
|
+
begin
|
5
|
+
if user.to_s.length>0
|
6
|
+
if config.simulate and config.key?(:client)
|
7
|
+
if user[0]=='@' #name
|
8
|
+
client.web_client.users_get_presence.select{|k, v| v[:name] == user[1..-1]}.values[-1]
|
9
|
+
else #id
|
10
|
+
client.web_client.users_get_presence[user.to_sym]
|
11
|
+
end
|
12
|
+
else
|
13
|
+
client.web_client.users_getPresence(user: user)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
rescue Exception => stack
|
17
|
+
@logger.warn stack
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,16 +1,20 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
3
|
def get_user_info(user)
|
4
|
-
|
5
|
-
if
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
begin
|
5
|
+
if user.to_s.length>0
|
6
|
+
if config.simulate and config.key?(:client)
|
7
|
+
if user[0]=='@' #name
|
8
|
+
client.web_client.users_info.select{|k, v| v[:user][:name] == user[1..-1]}.values[-1]
|
9
|
+
else #id
|
10
|
+
client.web_client.users_info[user.to_sym]
|
11
|
+
end
|
12
|
+
else
|
13
|
+
client.web_client.users_info(user: user)
|
10
14
|
end
|
11
|
-
else
|
12
|
-
client.web_client.users_info(user: user)
|
13
15
|
end
|
16
|
+
rescue Exception => stack
|
17
|
+
@logger.warn stack
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|