slack-smart-bot 1.14.2 → 1.15.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 +222 -37
- data/img/chat_gpt.png +0 -0
- data/img/chat_gpt_session.png +0 -0
- data/img/chat_gpt_share.png +0 -0
- data/img/command_add_sc.png +0 -0
- data/img/command_bot_help_echo.png +0 -0
- data/img/command_loop.png +0 -0
- data/img/command_my_timeoff.png +0 -0
- data/img/command_recap.png +0 -0
- data/img/command_repl1.png +0 -0
- data/img/command_repl2.png +0 -0
- data/img/command_ruby.png +0 -0
- data/img/command_run_repl.png +0 -0
- data/img/command_see_announcements.png +0 -0
- data/img/command_see_statuses.png +0 -0
- data/img/command_see_team.png +0 -0
- data/img/command_summarize.png +0 -0
- data/img/commands_inline.png +0 -0
- data/img/commands_on_demand.png +0 -0
- data/img/commands_on_external_call.png +0 -0
- data/img/image_editing.png +0 -0
- data/img/image_generation.png +0 -0
- data/img/image_variations.png +0 -0
- data/img/openai-300.png +0 -0
- data/img/openai.png +0 -0
- data/img/slack-300.png +0 -0
- data/img/slack.png +0 -0
- data/img/smart-bot-150.png +0 -0
- data/img/smart-bot-profile-pic-2.png +0 -0
- data/img/smart-bot-profile-pic.png +0 -0
- data/img/smart-bot.png +0 -0
- data/img/whisper.png +0 -0
- data/lib/slack/smart-bot/ai/open_ai/connect.rb +165 -43
- data/lib/slack/smart-bot/ai/open_ai/models.rb +61 -9
- data/lib/slack/smart-bot/ai/open_ai/send_gpt_chat.rb +67 -11
- data/lib/slack/smart-bot/ai/open_ai/send_image_edit.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/send_image_generation.rb +4 -4
- data/lib/slack/smart-bot/ai/open_ai/send_image_variation.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/whisper_transcribe.rb +4 -3
- data/lib/slack/smart-bot/comm/ask.rb +20 -8
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -1
- data/lib/slack/smart-bot/comm/get_channel_members.rb +2 -1
- data/lib/slack/smart-bot/comm/get_presence.rb +1 -0
- data/lib/slack/smart-bot/comm/get_smartbot_team_info.rb +10 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +45 -6
- data/lib/slack/smart-bot/comm/get_users.rb +8 -1
- data/lib/slack/smart-bot/comm/respond.rb +225 -196
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +10 -9
- data/lib/slack/smart-bot/comm/unreact.rb +2 -2
- data/lib/slack/smart-bot/comm.rb +1 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +16 -6
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +3 -3
- data/lib/slack/smart-bot/commands/general/add_vacation.rb +28 -12
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb +272 -23
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_add_collaborator.rb +42 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_copy_session.rb +89 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_delete_session.rb +45 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_get_prompts.rb +41 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_list_sessions.rb +81 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_share_session.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_use_model.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_edit_image.rb +14 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_generate_image.rb +15 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_models.rb +29 -17
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_variations_image.rb +16 -13
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_whisper.rb +13 -7
- data/lib/slack/smart-bot/commands/general/allow_access.rb +8 -4
- data/lib/slack/smart-bot/commands/general/bot_help.rb +24 -10
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +9 -5
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +2 -1
- data/lib/slack/smart-bot/commands/general/delete_share.rb +2 -1
- data/lib/slack/smart-bot/commands/general/deny_access.rb +1 -1
- data/lib/slack/smart-bot/commands/general/get_smartbot_readme.rb +15 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +10 -4
- data/lib/slack/smart-bot/commands/general/personal_settings.rb +26 -8
- data/lib/slack/smart-bot/commands/general/poster.rb +26 -2
- data/lib/slack/smart-bot/commands/general/public_holidays.rb +14 -24
- data/lib/slack/smart-bot/commands/general/recap.rb +399 -0
- data/lib/slack/smart-bot/commands/general/remove_admin.rb +19 -9
- data/lib/slack/smart-bot/commands/general/remove_vacation.rb +23 -6
- data/lib/slack/smart-bot/commands/general/see_access.rb +2 -1
- data/lib/slack/smart-bot/commands/general/see_admins.rb +8 -4
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +5 -5
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +4 -4
- data/lib/slack/smart-bot/commands/general/see_shares.rb +1 -1
- data/lib/slack/smart-bot/commands/general/see_vacations.rb +34 -17
- data/lib/slack/smart-bot/commands/general/set_public_holidays.rb +4 -2
- data/lib/slack/smart-bot/commands/general/share_messages.rb +3 -3
- data/lib/slack/smart-bot/commands/general/summarize.rb +191 -0
- data/lib/slack/smart-bot/commands/general/teams/add_team.rb +4 -8
- data/lib/slack/smart-bot/commands/general/teams/delete_team.rb +3 -3
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team.rb +34 -29
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team_comment.rb +1 -1
- data/lib/slack/smart-bot/commands/general/teams/memos/delete_memo_team.rb +6 -4
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memo_team.rb +26 -15
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memos_team.rb +33 -24
- data/lib/slack/smart-bot/commands/general/teams/memos/set_memo_status.rb +4 -4
- data/lib/slack/smart-bot/commands/general/teams/ping_team.rb +10 -8
- data/lib/slack/smart-bot/commands/general/teams/see_teams.rb +73 -61
- data/lib/slack/smart-bot/commands/general/teams/see_vacations_team.rb +28 -13
- data/lib/slack/smart-bot/commands/general/teams/update_team.rb +9 -9
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +1152 -839
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +18 -17
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +11 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +5 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/admin_master/update_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +21 -20
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +40 -7
- data/lib/slack/smart-bot/commands/on_bot/general/bot_status.rb +6 -2
- data/lib/slack/smart-bot/commands/on_bot/general/stop_using_rules.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/general/use_rules.rb +4 -3
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -4
- data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +109 -53
- data/lib/slack/smart-bot/commands/on_bot/repl_client.rb +35 -29
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -2
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +22 -12
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +12 -7
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -2
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +3 -3
- data/lib/slack/smart-bot/commands.rb +10 -0
- data/lib/slack/smart-bot/config.rb +126 -0
- data/lib/slack/smart-bot/listen.rb +12 -11
- data/lib/slack/smart-bot/process.rb +62 -55
- data/lib/slack/smart-bot/process_first.rb +106 -65
- data/lib/slack/smart-bot/treat_message.rb +79 -47
- data/lib/slack/smart-bot/utils/answer.rb +11 -3
- data/lib/slack/smart-bot/utils/answer_delete.rb +11 -3
- data/lib/slack/smart-bot/utils/check_vacations.rb +21 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +13 -13
- data/lib/slack/smart-bot/utils/display_calendar.rb +42 -8
- data/lib/slack/smart-bot/utils/encryption/decrypt.rb +16 -9
- data/lib/slack/smart-bot/utils/encryption/encrypt.rb +14 -11
- data/lib/slack/smart-bot/utils/find_user.rb +71 -0
- data/lib/slack/smart-bot/utils/get_access_channels.rb +22 -3
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +3 -4
- data/lib/slack/smart-bot/utils/get_command_ids.rb +5 -5
- data/lib/slack/smart-bot/utils/get_countries_candelarific.rb +18 -0
- data/lib/slack/smart-bot/utils/get_help.rb +21 -19
- data/lib/slack/smart-bot/utils/get_openai_sessions.rb +47 -0
- data/lib/slack/smart-bot/utils/get_personal_settings.rb +29 -3
- data/lib/slack/smart-bot/utils/get_rules_imported.rb +27 -6
- data/lib/slack/smart-bot/utils/get_shares.rb +1 -1
- data/lib/slack/smart-bot/utils/get_team_members.rb +4 -4
- data/lib/slack/smart-bot/utils/get_vacations.rb +15 -7
- data/lib/slack/smart-bot/utils/has_access.rb +10 -4
- data/lib/slack/smart-bot/utils/is_admin.rb +25 -17
- data/lib/slack/smart-bot/utils/local_time.rb +29 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +5 -3
- data/lib/slack/smart-bot/utils/update_access_channels.rb +19 -3
- data/lib/slack/smart-bot/utils/update_openai_sessions.rb +42 -0
- data/lib/slack/smart-bot/utils/update_personal_settings.rb +11 -3
- data/lib/slack/smart-bot/utils/update_rules_imported.rb +18 -3
- data/lib/slack/smart-bot/utils/update_vacations.rb +5 -2
- data/lib/slack/smart-bot/utils/upgrade_to_use_team_ids.rb +276 -0
- data/lib/slack/smart-bot/utils.rb +6 -1
- data/lib/slack-smart-bot.rb +182 -76
- data/lib/slack-smart-bot_general_commands.rb +10 -9
- data/whats_new.txt +30 -13
- metadata +148 -20
@@ -10,19 +10,19 @@ class SlackSmartBot
|
|
10
10
|
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
11
11
|
# helpadmin: command_id: :exit_bot
|
12
12
|
# helpadmin:
|
13
|
-
def exit_bot(command,
|
13
|
+
def exit_bot(command, user, dest, display_name, silent: false)
|
14
14
|
save_stats(__method__)
|
15
15
|
if config.on_master_bot
|
16
|
-
if config.
|
16
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") #master admin user
|
17
17
|
if answer.empty?
|
18
|
-
ask("are you sure?", command,
|
18
|
+
ask("are you sure?", command, user, dest)
|
19
19
|
else
|
20
20
|
case answer
|
21
21
|
when /yes/i, /yep/i, /sure/i
|
22
22
|
react :runner
|
23
23
|
@bots_created.each { |key, value|
|
24
24
|
value[:thread] = ""
|
25
|
-
send_msg_channel(key, "Bot has been closed by #{
|
25
|
+
send_msg_channel(key, "Bot has been closed by #{user.name}") unless silent
|
26
26
|
save_status :off, :exited, "The admin closed SmartBot on *##{value.channel_name}*"
|
27
27
|
sleep 0.5
|
28
28
|
}
|
@@ -30,10 +30,15 @@ class SlackSmartBot
|
|
30
30
|
sleep 0.5
|
31
31
|
file = File.open("#{config.path}/config_tmp.status", "w")
|
32
32
|
config.exit_bot = true
|
33
|
-
|
33
|
+
@config_log.exit_bot = true
|
34
|
+
file.write @config_log.inspect
|
34
35
|
file.close
|
35
36
|
@status = :exit
|
36
37
|
respond "Game over!", dest
|
38
|
+
@listening[:threads].each do |thread_ts, channel_thread|
|
39
|
+
unreact :running, thread_ts, channel: channel_thread
|
40
|
+
respond "ChatGPT session closed since SmartBot is going to be closed", channel_thread, thread_ts: thread_ts
|
41
|
+
end
|
37
42
|
if config.simulate
|
38
43
|
sleep 2
|
39
44
|
@status = :off
|
@@ -49,10 +54,10 @@ class SlackSmartBot
|
|
49
54
|
exit!
|
50
55
|
end
|
51
56
|
when /no/i, /nope/i, /cancel/i
|
52
|
-
answer_delete(
|
57
|
+
answer_delete(user)
|
53
58
|
respond "Thanks, I'm happy to be alive", dest
|
54
59
|
else
|
55
|
-
ask("I don't understand, are you sure do you want me to close? (yes or no)", command,
|
60
|
+
ask("I don't understand, are you sure do you want me to close? (yes or no)", command, user, dest)
|
56
61
|
end
|
57
62
|
end
|
58
63
|
else
|
@@ -10,10 +10,10 @@ class SlackSmartBot
|
|
10
10
|
# helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#sending-notifications|more info>
|
11
11
|
# helpmaster: command_id: :notify_message
|
12
12
|
# helpmaster:
|
13
|
-
def notify_message(dest,
|
13
|
+
def notify_message(dest, user, where, message)
|
14
14
|
save_stats(__method__)
|
15
15
|
if config.on_master_bot
|
16
|
-
if config.
|
16
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") #master admin user
|
17
17
|
if where.nil? #not all and not channel
|
18
18
|
@bots_created.each do |k, v|
|
19
19
|
respond message, k
|
@@ -12,7 +12,7 @@ class SlackSmartBot
|
|
12
12
|
def publish_announcements(user)
|
13
13
|
save_stats(__method__)
|
14
14
|
if config.on_master_bot
|
15
|
-
if config.
|
15
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") #master admin user
|
16
16
|
channels = Dir.entries("#{config.path}/announcements/")
|
17
17
|
channels.select! {|i| i[/\.csv$/]}
|
18
18
|
channels.each do |channel|
|
@@ -13,10 +13,10 @@ class SlackSmartBot
|
|
13
13
|
# helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
14
14
|
# helpmaster: command_id: :set_general_message
|
15
15
|
# helpmaster:
|
16
|
-
def set_general_message(
|
16
|
+
def set_general_message(user, status, message)
|
17
17
|
save_stats(__method__)
|
18
18
|
if config.on_master_bot
|
19
|
-
if config.
|
19
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") #master admin user
|
20
20
|
if status == 'on'
|
21
21
|
config.general_message = message
|
22
22
|
respond "General message has been set."
|
@@ -24,11 +24,11 @@ class SlackSmartBot
|
|
24
24
|
config.general_message = ''
|
25
25
|
respond "General message won't be displayed anymore."
|
26
26
|
end
|
27
|
-
|
27
|
+
@config_log.general_message = config.general_message
|
28
28
|
file = File.open("#{config.path}/config_tmp.status", "w")
|
29
|
-
file.write
|
29
|
+
file.write @config_log.inspect
|
30
30
|
file.close
|
31
|
-
|
31
|
+
|
32
32
|
else
|
33
33
|
respond 'Only master admins on master channel can use this command.'
|
34
34
|
end
|
@@ -16,10 +16,10 @@ class SlackSmartBot
|
|
16
16
|
# helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
17
17
|
# helpmaster: command_id: :set_maintenance
|
18
18
|
# helpmaster:
|
19
|
-
def set_maintenance(
|
19
|
+
def set_maintenance(user, status, message)
|
20
20
|
save_stats(__method__)
|
21
21
|
if config.on_master_bot
|
22
|
-
if config.
|
22
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") #master admin user
|
23
23
|
if message == ''
|
24
24
|
config.on_maintenance_message = "Sorry I'm on maintenance so I cannot attend your request."
|
25
25
|
else
|
@@ -35,11 +35,11 @@ class SlackSmartBot
|
|
35
35
|
respond "From now on I won't be on maintenance. Everything is back to normal!"
|
36
36
|
save_status :on, :maintenance_off, config.on_maintenance_message
|
37
37
|
end
|
38
|
-
|
38
|
+
@config_log.on_maintenance = config.on_maintenance
|
39
39
|
file = File.open("#{config.path}/config_tmp.status", "w")
|
40
|
-
file.write
|
40
|
+
file.write @config_log.inspect
|
41
41
|
file.close
|
42
|
-
|
42
|
+
|
43
43
|
else
|
44
44
|
respond 'Only master admins on master channel can use this command.'
|
45
45
|
end
|
@@ -58,13 +58,13 @@ class SlackSmartBot
|
|
58
58
|
default_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_rules.rb")
|
59
59
|
default_general_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_rules.rb")
|
60
60
|
default_general_commands = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_commands.rb")
|
61
|
-
|
61
|
+
|
62
62
|
File.delete(config.path + rules_file) if File.exist?(config.path + rules_file)
|
63
63
|
FileUtils.copy_file(default_rules, config.path + rules_file) unless File.exist?(config.path + rules_file)
|
64
64
|
FileUtils.copy_file(default_general_rules, config.path + general_rules_file) unless File.exist?(config.path + general_rules_file)
|
65
65
|
FileUtils.copy_file(default_general_commands, config.path + general_commands_file) unless File.exist?(config.path + general_commands_file)
|
66
66
|
admin_users = Array.new()
|
67
|
-
creator_info =
|
67
|
+
creator_info = find_user(channel_found.creator)
|
68
68
|
if creator_info.nil? or creator_info.empty? or creator_info.user.nil?
|
69
69
|
admin_users = [from] + config.masters
|
70
70
|
else
|
@@ -72,7 +72,7 @@ class SlackSmartBot
|
|
72
72
|
end
|
73
73
|
admin_users.uniq!
|
74
74
|
@logger.info "BOT_SILENT=#{silent} ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
|
75
|
-
|
75
|
+
|
76
76
|
if cloud
|
77
77
|
respond "Copy the bot folder to your cloud location and run `ruby #{config.file} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on&`", dest
|
78
78
|
else
|
@@ -80,11 +80,21 @@ require_relative "commands/general/personal_settings"
|
|
80
80
|
require_relative "commands/general/teams/memos/add_memo_team_comment"
|
81
81
|
require_relative "commands/general/teams/memos/see_memo_team"
|
82
82
|
require_relative 'commands/general/ai/open_ai/open_ai_chat'
|
83
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_get_prompts'
|
84
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_delete_session'
|
85
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_share_session'
|
86
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_list_sessions'
|
87
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_add_collaborator'
|
88
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_use_model'
|
89
|
+
require_relative 'commands/general/ai/open_ai/open_ai_chat_copy_session'
|
83
90
|
require_relative 'commands/general/ai/open_ai/open_ai_generate_image'
|
84
91
|
require_relative 'commands/general/ai/open_ai/open_ai_variations_image'
|
85
92
|
require_relative 'commands/general/ai/open_ai/open_ai_edit_image'
|
86
93
|
require_relative 'commands/general/ai/open_ai/open_ai_models'
|
87
94
|
require_relative 'commands/general/ai/open_ai/open_ai_whisper'
|
95
|
+
require_relative 'commands/general/recap'
|
96
|
+
require_relative 'commands/general/summarize'
|
97
|
+
require_relative 'commands/general/get_smartbot_readme'
|
88
98
|
|
89
99
|
class SlackSmartBot
|
90
100
|
include SlackSmartBot::Commands::General::AI::OpenAI
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
class SlackSmartBot
|
4
|
+
|
5
|
+
class Config < OpenStruct
|
6
|
+
# token [String] (default: ""): The API Slack token.
|
7
|
+
# user_token [String] (default: ""): The Slack User token.
|
8
|
+
# granular_token [String] (default: ""): The Slack granular token.
|
9
|
+
# path [String] (default: "."): Path to the folder where the bot is running
|
10
|
+
# silent [Boolean] (default: false): If true the bot will not send any message to the chat when starting or stopping
|
11
|
+
# testing [Boolean] (default: false): Whether the bot is running in testing mode.
|
12
|
+
# simulate [Boolean] (default: false): Whether the bot is running in simulation mode.
|
13
|
+
# stats [Boolean] (default: false): Whether the bot should collect and log statistics.
|
14
|
+
# allow_access [Hash] (default: {}): The access control settings for the bot.
|
15
|
+
# on_maintenance [Boolean] (default: false): Whether the bot is on maintenance mode.
|
16
|
+
# on_maintenance_message [String] (default: "Sorry I'm on maintenance so I cannot attend your request."): The message to send when the bot is on maintenance mode.
|
17
|
+
# general_message [String] (default: ""): The general message added to be sent on every message the bot sends.
|
18
|
+
# logrtm [Boolean] (default: false): Whether the bot should log all messages received and sent (RTM).
|
19
|
+
# status_channel [String] (default: "smartbot-status"): The channel where the bot will send status messages.
|
20
|
+
# stats_channel [String] (default: "smartbot-stats"): The channel where the bot is allowed to send statistics.
|
21
|
+
# jira [Hash] (default: { host: "", user: "", password: "" }): The settings for Jira.
|
22
|
+
# github [Hash] (default: , host: "https://api.github.com" }): The settings for GitHub.
|
23
|
+
# public_holidays [Hash] (default: { api_key: "", host: "https://calendarific.com", default_calendar: '' }): The settings for public holidays.
|
24
|
+
# encrypt [Boolean] (default: true): Whether the bot should encrypt the data.
|
25
|
+
# encryption [Hash] (default: { key: "", iv: "" }): The settings for encryption. If not provided the bot will generate a new key and iv.
|
26
|
+
# recover_encrypted [Boolean] (default: false): Whether the bot should recover the encrypted data in case now encrypt is set to false but data is still encrypted. This is used for testing purposes.
|
27
|
+
# ai [Hash] (default: { open_ai: { access_token: "", host: "" }): The settings for OpenAI.
|
28
|
+
# ai.open_ai.chat_gpt [Hash] (default: {access_token: "", host: "", model: "gpt-3.5-turbo", smartbot_model: "gpt-3.5-turbo", api_type: :openai, api_version: "", fixed_user: ''}): The settings for OpenAI ChatGPT.
|
29
|
+
# ai.open_ai.dall_e [Hash] (default: {access_token: "", host: "", model: "", api_type: :openai, image_size: "256x256"}): The settings for OpenAI DALL-E.
|
30
|
+
# ai.open_ai.whisper [Hash] (default: {access_token: "", host: "", model: "whisper-1", api_type: :openai}): The settings for OpenAI Whisper.
|
31
|
+
# ai.open_ai.models [Hash] (default: {access_token: "", host: "", url: "", api_type: :openai, api_version: ""}): The settings for OpenAI Models.
|
32
|
+
# file [String] (default: ""): The file to load the bot from.
|
33
|
+
# masters [Array] (default: []): The list of master users.
|
34
|
+
# team_id_masters [Array] (default: []): The list of master team_id + user ids.
|
35
|
+
# master_channel [String] (default: ""): The Smartbot master channel.
|
36
|
+
# channel [String] (default: ""): The Smartbot channel.
|
37
|
+
# status_init [Symbol] (default: :on): The initial status of the bot.
|
38
|
+
# rules_file [String] (default: ""): The file to load the rules from.
|
39
|
+
# admins [Array] (default: []): The list of admin users.
|
40
|
+
# team_id_admins [Array] (default: []): The list of admin team_id + user ids.
|
41
|
+
# start_bots [Boolean] (default: true): Whether the bot should start the bots when starting.
|
42
|
+
# ldap [Hash] (default: { host: "", port: 389, auth: {user: '', password: ''}, treebase: "dc=ds,dc=eng,dc=YOURCOMPANY,dc=com" }): The settings for LDAP. @ldap connection will be created. It will populate the sso_user_name key to 'user' searching by Slack mail specified in profile.
|
43
|
+
# authorizations [Hash] (default: {}): The authorizations for services. for example: { confluence: {host: 'confluence.example.com', authorization: 'Bearer Adjjj3dddfj'}}
|
44
|
+
def initialize(*args)
|
45
|
+
super
|
46
|
+
self.token ||= ""
|
47
|
+
self.user_token ||= ""
|
48
|
+
self.granular_token ||= ""
|
49
|
+
|
50
|
+
self.path ||= "."
|
51
|
+
self.file ||= ""
|
52
|
+
self.rules_file ||= ""
|
53
|
+
|
54
|
+
self.start_bots ||= true
|
55
|
+
self.status_init ||= :on
|
56
|
+
self.silent ||= false
|
57
|
+
self.testing ||= false
|
58
|
+
self.simulate ||= false
|
59
|
+
self.logrtm ||= false
|
60
|
+
|
61
|
+
self.masters ||= []
|
62
|
+
self.team_id_masters ||= []
|
63
|
+
self.admins ||= []
|
64
|
+
self.team_id_admins ||= []
|
65
|
+
|
66
|
+
self.stats ||= false
|
67
|
+
self.allow_access ||= {}
|
68
|
+
|
69
|
+
self.on_maintenance ||= false
|
70
|
+
self.on_maintenance_message ||= "Sorry I'm on maintenance so I cannot attend your request."
|
71
|
+
self.general_message ||= ""
|
72
|
+
|
73
|
+
self.master_channel ||= "" # smartbot master channel
|
74
|
+
self.channel ||= "" # smartbot channel
|
75
|
+
self.status_channel ||= "smartbot-status"
|
76
|
+
self.stats_channel ||= "smartbot-stats"
|
77
|
+
|
78
|
+
self.jira ||= { host: "", user: "", password: "" }
|
79
|
+
self.github ||= { token: "", host: "https://api.github.com" }
|
80
|
+
self.public_holidays ||= { api_key: "", host: "https://calendarific.com", default_calendar: ""}
|
81
|
+
|
82
|
+
self.encrypt ||= true
|
83
|
+
self.encryption ||= { key: "", iv: "" }
|
84
|
+
self.recover_encrypted ||= false
|
85
|
+
|
86
|
+
self.ai ||= { open_ai: { testing: false, access_token: "", host: "", chat_gpt: {}, dall_e: {}, whisper: {}, models: {} } }
|
87
|
+
self.ai[:open_ai][:host] = "https://#{self.ai[:open_ai][:host]}" unless self.ai[:open_ai][:host].empty? || self.ai[:open_ai][:host].start_with?("http")
|
88
|
+
self.ai[:open_ai][:chat_gpt] ||= {}
|
89
|
+
self.ai[:open_ai][:dall_e] ||= {}
|
90
|
+
self.ai[:open_ai][:whisper] ||= {}
|
91
|
+
self.ai[:open_ai][:models] ||= {}
|
92
|
+
|
93
|
+
self.ai[:open_ai][:chat_gpt][:access_token] ||= self.ai[:open_ai][:access_token]
|
94
|
+
self.ai[:open_ai][:dall_e][:access_token] ||= self.ai[:open_ai][:access_token]
|
95
|
+
self.ai[:open_ai][:whisper][:access_token] ||= self.ai[:open_ai][:access_token]
|
96
|
+
self.ai[:open_ai][:models][:access_token] ||= self.ai[:open_ai][:access_token]
|
97
|
+
|
98
|
+
self.ai[:open_ai][:chat_gpt][:host] ||= self.ai[:open_ai][:host]
|
99
|
+
self.ai[:open_ai][:dall_e][:host] ||= self.ai[:open_ai][:host]
|
100
|
+
self.ai[:open_ai][:whisper][:host] ||= self.ai[:open_ai][:host]
|
101
|
+
self.ai[:open_ai][:models][:host] ||= self.ai[:open_ai][:host]
|
102
|
+
|
103
|
+
self.ai[:open_ai][:chat_gpt][:model] ||= "gpt-3.5-turbo"
|
104
|
+
self.ai[:open_ai][:chat_gpt][:smartbot_model] ||= self.ai[:open_ai][:chat_gpt][:model]
|
105
|
+
self.ai[:open_ai][:dall_e][:model] ||= ""
|
106
|
+
self.ai[:open_ai][:whisper][:model] ||= "whisper-1"
|
107
|
+
|
108
|
+
self.ai[:open_ai][:chat_gpt][:api_type] ||= :openai
|
109
|
+
self.ai[:open_ai][:dall_e][:api_type] ||= :openai
|
110
|
+
self.ai[:open_ai][:whisper][:api_type] ||= :openai
|
111
|
+
self.ai[:open_ai][:models][:api_type] ||= self.ai[:open_ai][:chat_gpt][:api_type]
|
112
|
+
|
113
|
+
self.ai[:open_ai][:chat_gpt][:api_version] ||= ""
|
114
|
+
self.ai[:open_ai][:chat_gpt][:fixed_user] ||= ""
|
115
|
+
self.ai[:open_ai][:models][:api_version] ||= self.ai[:open_ai][:chat_gpt][:api_version]
|
116
|
+
|
117
|
+
self.ai[:open_ai][:dall_e][:image_size] ||= "256x256"
|
118
|
+
|
119
|
+
self.ai[:open_ai][:models][:url] ||= ""
|
120
|
+
|
121
|
+
self.ldap ||= { host: "", port: 389, auth: { user: '', password: '' }, treebase: "dc=ds,dc=eng,dc=YOURCOMPANY,dc=com" }
|
122
|
+
|
123
|
+
self.authorizations ||= {}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,46 +1,47 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def listen_simulate
|
3
3
|
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
|
4
|
-
@pings
|
4
|
+
@pings ||= []
|
5
5
|
@last_activity_check = Time.now
|
6
6
|
get_bots_created()
|
7
7
|
@buffer_complete = [] unless defined?(@buffer_complete)
|
8
8
|
b = File.read("#{config.path}/buffer_complete.log", encoding: "UTF-8")
|
9
|
-
result = b.scan(/^\|(\w+)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
|
9
|
+
result = b.scan(/^\|(\w+)\|(\w*)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
|
10
10
|
result.delete(nil)
|
11
11
|
new_messages = result[@buffer_complete.size..-1]
|
12
12
|
unless new_messages.nil? or new_messages.empty?
|
13
13
|
@buffer_complete = result
|
14
14
|
new_messages.each do |message|
|
15
15
|
channel = message[0].strip
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
thread_ts = message[1].strip
|
17
|
+
user = message[2].strip
|
18
|
+
user_name = message[3].strip
|
19
|
+
command = message[4].to_s.strip
|
19
20
|
# take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
|
20
21
|
@logger.info "treat message: #{message}" if config.testing
|
21
22
|
if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
|
22
23
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
23
24
|
if cmd.to_s != ""
|
24
25
|
cmd = "^#{cmd}"
|
25
|
-
treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
|
26
|
+
treat_message({ channel: channel, thread_ts: thread_ts, ts: thread_ts, user: user, text: cmd, user_name: user_name }, false)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
elsif command.match?(/^\s*\-!/)
|
29
30
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
30
31
|
if cmd.to_s != ""
|
31
32
|
cmd = "!#{cmd}"
|
32
|
-
treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
|
33
|
+
treat_message({ channel: channel, thread_ts: thread_ts, ts: thread_ts, user: user, text: cmd, user_name: user_name }, false)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
else
|
36
|
-
treat_message({ channel: channel, user: user, text: command, user_name: user_name })
|
37
|
+
treat_message({ channel: channel, thread_ts: thread_ts, ts: thread_ts, user: user, text: command, user_name: user_name })
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
def listen
|
43
|
-
@pings
|
44
|
+
@pings ||= []
|
44
45
|
@last_activity_check = Time.now
|
45
46
|
get_bots_created()
|
46
47
|
|
@@ -72,7 +73,7 @@ class SlackSmartBot
|
|
72
73
|
started = false
|
73
74
|
while restarts < 200 and !started
|
74
75
|
begin
|
75
|
-
@logger.info "Bot starting: #{
|
76
|
+
@logger.info "Bot starting: #{@config_log.inspect}"
|
76
77
|
client.start!
|
77
78
|
rescue Slack::RealTime::Client::ClientAlreadyStartedError
|
78
79
|
@logger.info "ClientAlreadyStarted so we continue with execution"
|
@@ -84,7 +85,7 @@ class SlackSmartBot
|
|
84
85
|
@logger.info "*" * 50
|
85
86
|
@logger.fatal "Rescued on starting: #{e.inspect}"
|
86
87
|
@logger.info "Waiting 60 seconds to retry. restarts: #{restarts}"
|
87
|
-
puts "#{Time.now}: Not able to start client. Waiting 60 seconds to retry: #{
|
88
|
+
puts "#{Time.now}: Not able to start client. Waiting 60 seconds to retry: #{@config_log.inspect}"
|
88
89
|
sleep 60
|
89
90
|
else
|
90
91
|
exit!
|