slack-smart-bot 1.10.0 → 1.12.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 +134 -23
- data/lib/slack/smart-bot/comm/delete.rb +13 -0
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/get_channel_members.rb +7 -3
- data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +1 -1
- data/lib/slack/smart-bot/comm/respond.rb +24 -13
- data/lib/slack/smart-bot/comm/send_msg_user.rb +12 -11
- data/lib/slack/smart-bot/comm/set_status.rb +21 -0
- data/lib/slack/smart-bot/comm.rb +3 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +1 -1
- data/lib/slack/smart-bot/commands/general/add_memo_team.rb +117 -0
- data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
- data/lib/slack/smart-bot/commands/general/add_vacation.rb +51 -0
- data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +20 -11
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +1 -1
- data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +69 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +1 -1
- data/lib/slack/smart-bot/commands/general/delete_team.rb +54 -0
- data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
- 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/remove_vacation.rb +27 -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 +7 -5
- data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +3 -4
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +34 -21
- data/lib/slack/smart-bot/commands/general/see_teams.rb +402 -0
- data/lib/slack/smart-bot/commands/general/see_vacations.rb +58 -0
- data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +136 -0
- data/lib/slack/smart-bot/commands/general/set_memo_status.rb +58 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +1 -1
- data/lib/slack/smart-bot/commands/general/update_team.rb +130 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +442 -13
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +3 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +10 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -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 +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +15 -2
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +416 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/leaderboard.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/suggest_command.rb +6 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +1 -0
- 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 +2 -1
- data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +73 -15
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +117 -28
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +3 -2
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +5 -4
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -2
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +6 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
- data/lib/slack/smart-bot/commands.rb +30 -7
- data/lib/slack/smart-bot/listen.rb +30 -30
- data/lib/slack/smart-bot/process.rb +53 -23
- data/lib/slack/smart-bot/process_first.rb +2 -2
- data/lib/slack/smart-bot/treat_message.rb +23 -17
- data/lib/slack/smart-bot/utils/build_help.rb +1 -1
- data/lib/slack/smart-bot/utils/check_vacations.rb +43 -0
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
- data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_admins_channels.rb +33 -0
- data/lib/slack/smart-bot/utils/get_bots_created.rb +27 -10
- 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 +36 -19
- 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_teams.rb +22 -0
- data/lib/slack/smart-bot/utils/get_vacations.rb +22 -0
- data/lib/slack/smart-bot/utils/has_access.rb +25 -9
- data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +52 -42
- data/lib/slack/smart-bot/utils/save_status.rb +22 -7
- data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
- data/lib/slack/smart-bot/utils/update_admins_channels.rb +25 -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/update_vacations.rb +16 -0
- data/lib/slack/smart-bot/utils.rb +11 -0
- data/lib/slack-smart-bot.rb +50 -12
- data/lib/slack-smart-bot_general_commands.rb +16 -1
- data/whats_new.txt +12 -30
- metadata +78 -21
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -314
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b862b6537e267ad0582f3ca4e60eefa63ef9513a6e2b4d0bf0dd05ac5689ef4
|
4
|
+
data.tar.gz: 1f08183c3eb4e33f63f1b1b4a1fc1e078ceb4835655d03435eca27aa2491f749
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 286cc08cac4c0f4cc7dbb32583a2d1f27d7b41bfa2e53330a407850ed80ce993ec63c036c0b1c88a6113b4261701315bd8b2a34eac91e1a9d156eadd029e50de
|
7
|
+
data.tar.gz: a7b84c3d33cb1eda1a59d2d677b091f3b7aab488824d7ee7ba62af1eaa71a2311bb9decd3f7844baedf2fc569bc9f72b9baad023d50393627d70e40c8ba7be6e
|
data/README.md
CHANGED
@@ -31,8 +31,10 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
|
|
31
31
|
* [Share Messages](#share-messages)
|
32
32
|
* [See Statuses](#see-statuses)
|
33
33
|
* [Routines](#routines)
|
34
|
-
* [
|
34
|
+
* [Control who has access to a command](#control-who-has-access-to-a-command)
|
35
35
|
* [See favorite commands](#see-favorite-commands)
|
36
|
+
* [Teams](#teams)
|
37
|
+
* [Time off management](#time-off-management)
|
36
38
|
* [Tips](#tips)
|
37
39
|
+ [Send a file](#send-a-file)
|
38
40
|
+ [Download a file](#download-a-file)
|
@@ -309,6 +311,10 @@ If you are a Master Admin on a Direct Message with the Smart Bot you can call th
|
|
309
311
|
|
310
312
|
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.
|
311
313
|
|
314
|
+
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.
|
315
|
+
|
316
|
+
To see the full list of available command ids on any channel call: `see command ids`
|
317
|
+
|
312
318
|
#### Cloud Bots
|
313
319
|
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...
|
314
320
|
|
@@ -372,7 +378,7 @@ Running Example:
|
|
372
378
|
>**_Smart-Bot>_** `Session name: *Create10RandomUsers*`
|
373
379
|
>**_Peter>_** `http = NiceHttp.new("https://reqres.in/")`
|
374
380
|
>**_Smart-Bot>_** `#<NiceHttp:0x00007fc6e216e328 @host="reqres.in", @port=443...>`
|
375
|
-
>**_Peter>_** `request
|
381
|
+
>**_Peter>_** `request ||= { path: '/api/users' }`
|
376
382
|
>**_Smart-Bot>_** `{ :path => "/api/users" }`
|
377
383
|
>**_Peter>_** `request.data = { name: '1-10:L', job: 'leader|worker' }`
|
378
384
|
>**_Smart-Bot>_** `{ :name => "1-10:L", :job => "leader|worker" }`
|
@@ -390,8 +396,11 @@ Running Example:
|
|
390
396
|
>**_Smart-Bot>_** `Running REPL Create10RandomUsers`
|
391
397
|
>**_Smart-Bot>_** `Create10RandomUsers: 10 Random Users Created`
|
392
398
|
|
399
|
+
You can run repls and supply parameters to the repl that will be executed on the same session just before the repl. [More info](https://github.com/MarioRuiz/slack-smart-bot/issues/60)
|
400
|
+
Example:
|
401
|
+
>**_Peter>_** ``run repl Create10RandomUsers `request = {path: '/api-dev/users/'}` ``
|
393
402
|
|
394
|
-
Other REPL commands: `see repls`, `run repl SESSION_NAME ENV_VAR=value`, `get repl SESSION_NAME`, `delete repl SESSION_NAME`
|
403
|
+
Other REPL commands: `see repls`, `run repl SESSION_NAME ENV_VAR=value`, `get repl SESSION_NAME`, `delete repl SESSION_NAME`, `kill repl RUN_REPL_ID`
|
395
404
|
|
396
405
|
### Sending notifications
|
397
406
|
You can send notifications from MASTER CHANNEL by using **_`notify MESSAGE`_**. All Bot Channels will be notified.
|
@@ -435,11 +444,11 @@ You can add any announcement on any channel where the SmartBot is a member by us
|
|
435
444
|
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.
|
436
445
|
|
437
446
|
Examples:
|
438
|
-
>**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
|
439
|
-
>**_Peter>_** `add red message Customers db is down :x:`
|
440
|
-
>**_Peter>_** `add yellow statement Don't access the linux server without VPN`
|
441
|
-
>**_Peter>_** `add announcement Party will start at 20:00 :tada:`
|
442
|
-
>**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
|
447
|
+
>**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
|
448
|
+
>**_Peter>_** `add red message Customers db is down :x:`
|
449
|
+
>**_Peter>_** `add yellow statement Don't access the linux server without VPN`
|
450
|
+
>**_Peter>_** `add announcement Party will start at 20:00 :tada:`
|
451
|
+
>**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
|
443
452
|
|
444
453
|
To see the announcements of the channel: **_`see announcements`_**, **_`see COLOR announcements`_**, **_`see EMOJI announcements`_** and to delete a particular announcement: **_`delete announcement ID`_**
|
445
454
|
|
@@ -451,8 +460,8 @@ You can automatically share any new message that is posted on the channel and me
|
|
451
460
|
This command is only available in public channels. The user adding the Share and the SmartBot need to be a member of both channels.
|
452
461
|
|
453
462
|
Examples:
|
454
|
-
>**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
|
455
|
-
>**_Peter>_** `share messages "share post" on #announcements`
|
463
|
+
>**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
|
464
|
+
>**_Peter>_** `share messages "share post" on #announcements`
|
456
465
|
|
457
466
|
To see the shares of the channel: **_`see shares`_** and to delete a particular share: **_`delete share ID`_**
|
458
467
|
|
@@ -462,11 +471,12 @@ To see a list of statuses of the members in the channel you can call `see status
|
|
462
471
|
You need to be a member of the channel to be able to get this info.
|
463
472
|
|
464
473
|
Examples:
|
465
|
-
>**_Peter>_** `see statuses`
|
466
|
-
>**_Peter>_** `who is on vacation?`
|
467
|
-
>**_Peter>_** `who is not on vacation?`
|
468
|
-
>**_Peter>_** `who is on vacation? #SalesChannel`
|
469
|
-
>**_Peter>_** `who is on :working-from-home:`
|
474
|
+
>**_Peter>_** `see statuses`
|
475
|
+
>**_Peter>_** `who is on vacation?`
|
476
|
+
>**_Peter>_** `who is not on vacation?`
|
477
|
+
>**_Peter>_** `who is on vacation? #SalesChannel`
|
478
|
+
>**_Peter>_** `who is on :working-from-home:`
|
479
|
+
>**_Peter>_** `who is available?`
|
470
480
|
|
471
481
|
### Routines
|
472
482
|
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.
|
@@ -495,9 +505,13 @@ Other routine commands:
|
|
495
505
|
* **_`see routines`_**
|
496
506
|
* **_`see result routine NAME`_**
|
497
507
|
|
498
|
-
###
|
508
|
+
### Control who has access to a command
|
499
509
|
|
500
|
-
|
510
|
+
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.
|
511
|
+
|
512
|
+
To see the full list of available command ids on any channel call: `see command ids`
|
513
|
+
|
514
|
+
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:
|
501
515
|
|
502
516
|
```ruby
|
503
517
|
settings = {
|
@@ -513,16 +527,23 @@ settings = {
|
|
513
527
|
```
|
514
528
|
You can use the user name or the user id.
|
515
529
|
|
516
|
-
If you want to change who has access to a
|
530
|
+
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:
|
517
531
|
|
518
532
|
```ruby
|
519
|
-
|
533
|
+
# helpadmin: ----------------------------------------------
|
534
|
+
# helpadmin: `update access`
|
535
|
+
# helpadmin: It will update the privileges to access commands or rules
|
536
|
+
# helpadmin:
|
537
|
+
when /\A\s*update\s+access\s*\z/i
|
538
|
+
save_stats(:update_access)
|
539
|
+
if is_admin?(user.name)
|
540
|
+
config.allow_access.repl = ['marioruiz', 'samcooke']
|
541
|
+
respond "updated on <##{@channel_id}>!"
|
542
|
+
else
|
543
|
+
respond 'Only admins can change the access rules'
|
544
|
+
end
|
520
545
|
```
|
521
546
|
|
522
|
-
These are the commands that are possible to be limited plus all your SmartBot rules:
|
523
|
-
|
524
|
-
`bot_help, bot_rules, bot_status, use_rules, add_shortcut, delete_shortcut, repl, run_repl, get_repl, delete_repl, see_repls, ruby_code, see_shortcuts, create_bot, add_announcement, delete_announcement, see_announcements`
|
525
|
-
|
526
547
|
To check from a rule if the user has access to it:
|
527
548
|
|
528
549
|
```ruby
|
@@ -530,6 +551,22 @@ if has_access?(:your_command_id)
|
|
530
551
|
end
|
531
552
|
```
|
532
553
|
|
554
|
+
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:
|
555
|
+
`allow access COMMAND_ID`
|
556
|
+
`allow access COMMAND_ID @user1 @user99`
|
557
|
+
It will allow the specified command to be used on the channel.
|
558
|
+
If @user specified, only those users will have access to the command
|
559
|
+
Only admins of the channel can use this command.
|
560
|
+
|
561
|
+
`deny access COMMAND_ID`
|
562
|
+
It won't allow the specified command to be used on the channel.
|
563
|
+
Only admins of the channel can use this command
|
564
|
+
|
565
|
+
`see access COMMAND_ID`
|
566
|
+
it will show the access rights for the specified command
|
567
|
+
|
568
|
+
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)`
|
569
|
+
|
533
570
|
### See favorite commands
|
534
571
|
|
535
572
|
It will display the favorite commands in that channel.
|
@@ -540,6 +577,80 @@ Examples:
|
|
540
577
|
>**_`my favourite commands`_**
|
541
578
|
>**_`most used commands`_**
|
542
579
|
|
580
|
+
### Teams
|
581
|
+
|
582
|
+
You can add, update, see, ping and delete teams. When calling `see TEAM_NAME team` the availability of the members will be displayed.
|
583
|
+
`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.
|
584
|
+
|
585
|
+
Examples:
|
586
|
+
>**_`add team devweb members #devweb support #devweb-support : We take care of the website`_**
|
587
|
+
>**_`add team devweb qa @jim dev @johnja @cooke @luisa members #devweb support #devweb-support : We take care of the website`_**
|
588
|
+
>**_`add team sandex manager @sarah members #sandex : We take care of the sand`_**
|
589
|
+
|
590
|
+
By calling `update team` you will update a team with the info supplied.
|
591
|
+
|
592
|
+
Examples:
|
593
|
+
>**_`update team sales : Support for customers`_**
|
594
|
+
>**_`update sales team delete @sarah @peter`_**
|
595
|
+
>**_`update sales team add public #salesff`_**
|
596
|
+
>**_`update sales team add qa @john @ben @ana`_**
|
597
|
+
|
598
|
+
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.
|
599
|
+
|
600
|
+
Examples:
|
601
|
+
>**_`see teams`_**
|
602
|
+
>**_`see Sales team`_**
|
603
|
+
>**_`which teams #salesff`_**
|
604
|
+
>**_`which teams @sarah`_**
|
605
|
+
>**_`which team does @john belongs to?`_**
|
606
|
+
|
607
|
+
By calling `ping team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all available members of the MEMBER_TYPE supplied.
|
608
|
+
If you call `contact team TEAM_NAME TYPE_MEMBER MESSAGE` will send the MESSAGE naming all members of the MEMBER_TYPE supplied.
|
609
|
+
|
610
|
+
Examples:
|
611
|
+
>**_`ping team sales development What's the status on last deployment?`_**
|
612
|
+
>**_`contact team sales qa Please finish testing of dev02 feature before noon`_**
|
613
|
+
|
614
|
+
It is also possible to add notes for the team, even you can specify if those notes are private so only the members of the team can see them or even personal so only you will. You can use different types of notes: memo, note, issue, task, feature, bug, jira, github. Also you can indicate the topic of the note. To be able to add or delete notes you need to be a member of that team.
|
615
|
+
In case of 'jira' type then you can supply an URL or a JQL and it will show all the JIRA issues as memos. To be able to use it you need to specify on the SmartBot settings the credentials for the Basic Authentication on JIRA:
|
616
|
+
`jira: {host: HOST, user: USER, password: PASSWORD}`
|
617
|
+
In case of 'github' type then you can supply an URL filtering the Github issues you want to add as memos. To be able to use it you need to specify on the SmartBot settings the Github token:
|
618
|
+
`github: {token: GITHUB_TOKEN}`
|
619
|
+
|
620
|
+
If you want to change the memo status use the command `set STATUS on memo ID TEAM_NAME team`. For example: `set :runner: on memo 7 Sales team`
|
621
|
+
|
622
|
+
Examples:
|
623
|
+
>**_`add memo to sales team : Add tests for Michigan feature`_**
|
624
|
+
>**_`add private note to sales team : Bills will need to be deployed before Friday`_**
|
625
|
+
>**_`add memo to dev team web : Check last version`_**
|
626
|
+
>**_`add private bug to dev team SRE : Logs should not be accessible from outside VPN`_**
|
627
|
+
>**_`add memo sales team : Add tests for Michigan feature`_**
|
628
|
+
>**_`add memo team sales: Add tests for Michigan feature`_**
|
629
|
+
>**_`add jira to sales team : labels = SalesT AND status != Done`_**
|
630
|
+
>**_`add github to sales team : https://github.com/PeterBale/SalesBoom/issues?q=is%3Aissue+is%3Aopen+`_**
|
631
|
+
>**_`set :runner: on memo 7 team Sales`_**
|
632
|
+
|
633
|
+
Other team commands: **_`delete team TEAM_NAME`_**, **_`delete memo ID from team TEAM_NAME`_**, **_`set STATUS on memo ID TEAM_NAME team`_**
|
634
|
+
|
635
|
+
### Time off management
|
636
|
+
|
637
|
+
You will be able to add or remove vacation and sick periods by using `add vacation/sick from YYYY/MM/DD to YYYY/MM/DD`. The SmartBot will automatically set the users status to 🌴 or 🤒 and the expiration date when the user is on vacation or sick. The SmartBot won't be allowed to change the status of workspace admins or owners.
|
638
|
+
|
639
|
+
The vacation plan will be displayed also with the team when calling `see team NAME` for all team members.
|
640
|
+
|
641
|
+
Also, you can see the vacation plan for the team for a specific period: `vacations team NAME YYYY/MM/DD`
|
642
|
+
|
643
|
+
To be able to use this command you need to allow the 'users.profile:write' scope on your Slack App and an admin user of the workspace needs to install the app. Set the user token on the SmartBot settings:
|
644
|
+
|
645
|
+
```ruby
|
646
|
+
settings = {
|
647
|
+
token: ENV["SLACK_BOT_TOKEN"],
|
648
|
+
user_token: ENV['SLACK_USER_TOKEN']
|
649
|
+
}
|
650
|
+
```
|
651
|
+
|
652
|
+
Other 'time off' commands: **_`remove time off ID`_**, **_`see my time off`_**, **_`see vacations @USER`_**, **_`time off team NAME`_**
|
653
|
+
|
543
654
|
### Tips
|
544
655
|
|
545
656
|
#### Send a file
|
@@ -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")
|
@@ -1,10 +1,14 @@
|
|
1
1
|
#todo: add pagination for case more than 1000 members in the channel
|
2
2
|
def get_channel_members(channel_id)
|
3
3
|
begin
|
4
|
-
if
|
5
|
-
|
4
|
+
if channel_id.nil?
|
5
|
+
return nil
|
6
6
|
else
|
7
|
-
|
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
|
8
12
|
end
|
9
13
|
rescue Exception => stack
|
10
14
|
@logger.warn stack
|
@@ -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
|
@@ -9,7 +9,7 @@ class SlackSmartBot
|
|
9
9
|
else
|
10
10
|
begin
|
11
11
|
resp = client.web_client.users_list(limit: 1000, cursor: cursor)
|
12
|
-
if resp.key?(:members) and resp[:members].is_a(Array) and resp[:members].size > 0
|
12
|
+
if resp.key?(:members) and resp[:members].is_a?(Array) and resp[:members].size > 0
|
13
13
|
users << resp[:members]
|
14
14
|
end
|
15
15
|
cursor = resp.get_values(:next_cursor).values[-1]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class SlackSmartBot
|
2
|
-
def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false)
|
2
|
+
def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false, return_message: false, max_chars_per_message: 4000)
|
3
3
|
result = true
|
4
|
+
resp = nil
|
4
5
|
if (msg.to_s != "" or !msg.to_s.match?(/^A\s*\z/) or !blocks.empty?) and Thread.current[:routine_type].to_s != "bgroutine"
|
5
6
|
if !web_client.is_a?(TrueClass) and !web_client.is_a?(FalseClass)
|
6
7
|
(!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
|
@@ -41,18 +42,27 @@ class SlackSmartBot
|
|
41
42
|
else
|
42
43
|
wait = 0
|
43
44
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
txt
|
45
|
+
msgs = [] # max of max_chars_per_message characters per message
|
46
|
+
if max_chars_per_message.nil?
|
47
|
+
txt = msg
|
48
|
+
else
|
49
|
+
txt = ""
|
50
|
+
msg.split("\n").each do |m|
|
51
|
+
if (m + txt).size > max_chars_per_message
|
52
|
+
unless txt == ""
|
53
|
+
txt[0] = '.' if txt.match?(/\A\s\s\s/) #first line of message in slack don't show spaces at the begining so we force it by changing first char
|
54
|
+
t = txt.chars.each_slice(max_chars_per_message).map(&:join)
|
55
|
+
msgs << t
|
56
|
+
txt = ""
|
57
|
+
end
|
58
|
+
end
|
59
|
+
txt += (m + "\n")
|
60
|
+
txt[0] = '.' if txt.match?(/\A\s\s\s/) #first line of message in slack don't show spaces at the begining so we force it by changing first char
|
51
61
|
end
|
52
|
-
txt += (m + "\n")
|
53
62
|
end
|
54
63
|
msgs << txt
|
55
64
|
msgs.flatten!
|
65
|
+
msgs.delete_if{|e| e.match?(/\A\s*\z/)}
|
56
66
|
if dest.nil?
|
57
67
|
if config[:simulate]
|
58
68
|
open("#{config.path}/buffer_complete.log", "a") { |f|
|
@@ -119,14 +129,14 @@ class SlackSmartBot
|
|
119
129
|
end
|
120
130
|
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
|
121
131
|
msgs.each do |msg|
|
122
|
-
send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
132
|
+
resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
123
133
|
sleep wait
|
124
134
|
end
|
125
135
|
elsif dest[0] == "@"
|
126
136
|
begin
|
127
137
|
user_info = @users.select { |u| u.id == dest[1..-1] or u.name == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
|
128
138
|
msgs.each do |msg|
|
129
|
-
send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
139
|
+
resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
130
140
|
sleep wait
|
131
141
|
end
|
132
142
|
rescue Exception => stack
|
@@ -193,14 +203,14 @@ class SlackSmartBot
|
|
193
203
|
end
|
194
204
|
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
|
195
205
|
blocks.each_slice(40).to_a.each do |blockstmp|
|
196
|
-
send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
|
206
|
+
resp = send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
|
197
207
|
sleep wait
|
198
208
|
end
|
199
209
|
elsif dest[0] == "@"
|
200
210
|
begin
|
201
211
|
user_info = @users.select { |u| u.id == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
|
202
212
|
blocks.each_slice(40).to_a.each do |blockstmp|
|
203
|
-
send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
|
213
|
+
resp = send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
|
204
214
|
sleep wait
|
205
215
|
end
|
206
216
|
rescue Exception => stack
|
@@ -225,6 +235,7 @@ class SlackSmartBot
|
|
225
235
|
if Thread.current.key?(:routine) and Thread.current[:routine]
|
226
236
|
File.write("#{config.path}/routines/#{@channel_id}/#{Thread.current[:routine_name]}_output.txt", msg, mode: "a+")
|
227
237
|
end
|
238
|
+
result = resp if return_message
|
228
239
|
return result
|
229
240
|
end
|
230
241
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
3
|
#to send messages without listening for a response to users
|
4
|
-
def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [])
|
4
|
+
def send_msg_user(id_user, msg='', on_thread=nil, unfurl_links: true, unfurl_media: true, blocks: [], web_client: true)
|
5
|
+
resp = nil
|
5
6
|
unless msg == "" and blocks.empty?
|
6
7
|
begin
|
7
8
|
on_thread = Thread.current[:on_thread] if on_thread.nil?
|
8
|
-
|
9
|
-
web_client = true if !blocks.empty?
|
9
|
+
web_client = true if !blocks.empty? or !unfurl_links or !unfurl_media
|
10
10
|
if id_user[0] == "D"
|
11
11
|
if config[:simulate]
|
12
12
|
open("#{config.path}/buffer_complete.log", "a") { |f|
|
@@ -15,15 +15,15 @@ class SlackSmartBot
|
|
15
15
|
else
|
16
16
|
if web_client
|
17
17
|
if on_thread
|
18
|
-
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
18
|
+
resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
19
19
|
else
|
20
|
-
client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
20
|
+
resp = client.web_client.chat_postMessage(channel: id_user, text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
21
21
|
end
|
22
22
|
else
|
23
23
|
if on_thread
|
24
|
-
client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
24
|
+
resp = client.message(channel: id_user, as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
25
25
|
else
|
26
|
-
client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
26
|
+
resp = client.message(channel: id_user, as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -42,15 +42,15 @@ class SlackSmartBot
|
|
42
42
|
im = client.web_client.conversations_open(users: id_user)
|
43
43
|
if web_client
|
44
44
|
if on_thread
|
45
|
-
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
45
|
+
resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: Thread.current[:thread_ts])
|
46
46
|
else
|
47
|
-
client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
47
|
+
resp = client.web_client.chat_postMessage(channel: im["channel"]["id"], text: msg, blocks: blocks, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
48
48
|
end
|
49
49
|
else
|
50
50
|
if on_thread
|
51
|
-
client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
51
|
+
resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, thread_ts: Thread.current[:thread_ts], unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
52
52
|
else
|
53
|
-
client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
53
|
+
resp = client.message(channel: im["channel"]["id"], as_user: true, text: msg, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -65,6 +65,7 @@ class SlackSmartBot
|
|
65
65
|
@logger.warn stack
|
66
66
|
end
|
67
67
|
end
|
68
|
+
return resp
|
68
69
|
end
|
69
70
|
|
70
71
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def set_status(user_id, status: nil, message: nil, expiration: nil)
|
3
|
+
unless client_user.nil?
|
4
|
+
if expiration.is_a?(String) and expiration.match?(/^\d\d\d\d\/\d\d\/\d\d$/)
|
5
|
+
expiration = Date.parse(expiration, '%Y/%m/%d').to_time.to_i
|
6
|
+
elsif expiration.is_a?(Date)
|
7
|
+
expiration = expiration.to_time.to_i
|
8
|
+
end
|
9
|
+
params = []
|
10
|
+
params << "'status_emoji': '#{status}'" unless status.nil?
|
11
|
+
params << "'status_text': '#{message}'" unless message.nil?
|
12
|
+
params << "'status_expiration': '#{expiration}'" unless expiration.nil?
|
13
|
+
begin
|
14
|
+
resp = client_user.users_profile_set(user: user_id, profile: "{ #{params.join(', ')} }")
|
15
|
+
rescue Exception => exc
|
16
|
+
@logger.fatal exc.inspect
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/slack/smart-bot/comm.rb
CHANGED
@@ -13,3 +13,6 @@ require_relative 'comm/get_users'
|
|
13
13
|
require_relative 'comm/event_hello'
|
14
14
|
require_relative 'comm/get_channel_members'
|
15
15
|
require_relative 'comm/get_channels'
|
16
|
+
require_relative 'comm/delete'
|
17
|
+
require_relative 'comm/get_presence'
|
18
|
+
require_relative 'comm/set_status'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def add_admin(user, admin_user)
|
3
|
+
save_stats(__method__)
|
4
|
+
if Thread.current[:dest][0]=='D'
|
5
|
+
respond "This command cannot be called from a DM"
|
6
|
+
else
|
7
|
+
if Thread.current[:typem] == :on_call
|
8
|
+
channel = Thread.current[:dchannel]
|
9
|
+
elsif Thread.current[:using_channel].to_s==''
|
10
|
+
channel = Thread.current[:dest]
|
11
|
+
else
|
12
|
+
channel = Thread.current[:using_channel]
|
13
|
+
end
|
14
|
+
messages = []
|
15
|
+
admins = config.masters.dup
|
16
|
+
channels = get_channels()
|
17
|
+
channel_found = channels.detect { |c| c.id == channel }
|
18
|
+
if !channel_found.nil? and channel_found.creator.to_s != ''
|
19
|
+
creator_info = @users.select{|u| u.id == channel_found.creator or (u.key?(:enterprise_user) and u.enterprise_user.id == channel_found.creator)}[-1]
|
20
|
+
admins << creator_info.name
|
21
|
+
end
|
22
|
+
if Thread.current[:typem] == :on_bot or Thread.current[:typem] == :on_master
|
23
|
+
admins << config.admins.dup
|
24
|
+
end
|
25
|
+
if @admins_channels.key?(channel) and @admins_channels[channel].size > 0
|
26
|
+
admins << @admins_channels[channel]
|
27
|
+
end
|
28
|
+
admins.flatten!
|
29
|
+
admins.uniq!
|
30
|
+
admins.delete(nil)
|
31
|
+
if admins.include?(user.name)
|
32
|
+
admin_info = @users.select{|u| u.id == admin_user or (u.key?(:enterprise_user) and u.enterprise_user.id == admin_user)}[-1]
|
33
|
+
if admins.include?(admin_info.name)
|
34
|
+
messages << "This user is already an admin of this channel."
|
35
|
+
else
|
36
|
+
@admins_channels[channel] ||= []
|
37
|
+
@admins_channels[channel] << admin_info.name
|
38
|
+
update_admins_channels()
|
39
|
+
messages << "The user is an admin of this channel from now on."
|
40
|
+
admins << admin_info.name
|
41
|
+
end
|
42
|
+
messages << "*Admins*: <@#{admins.join('>, <@')}>"
|
43
|
+
else
|
44
|
+
messages << "Only the creator of the channel, Master admins or admins can add a new admin for this channel."
|
45
|
+
messages << "*Admins*: <@#{admins.join('>, <@')}>"
|
46
|
+
end
|
47
|
+
|
48
|
+
respond messages.join("\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -8,7 +8,7 @@ class SlackSmartBot
|
|
8
8
|
else
|
9
9
|
channel = Thread.current[:dest]
|
10
10
|
end
|
11
|
-
if File.
|
11
|
+
if File.exist?("#{config.path}/announcements/#{channel}.csv") and !@announcements.key?(channel)
|
12
12
|
t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
|
13
13
|
@announcements[channel] = t
|
14
14
|
num = t[:message_id].max + 1
|