slack-ruby-client 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{integtest.yml → integration_test.yml} +6 -5
  3. data/.github/workflows/{rubocop.yml → lint.yml} +5 -4
  4. data/.github/workflows/{danger.yml → pr_lint.yml} +8 -6
  5. data/.github/workflows/test.yml +4 -2
  6. data/.gitignore +0 -1
  7. data/.rubocop.yml +4 -0
  8. data/.rubocop_todo.yml +8 -14
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +14 -0
  11. data/CONTRIBUTING.md +5 -4
  12. data/Gemfile +1 -6
  13. data/README.md +60 -63
  14. data/RELEASING.md +1 -1
  15. data/UPGRADING.md +28 -0
  16. data/bin/commands/admin_audit_anomaly_allow.rb +23 -0
  17. data/bin/commands/admin_conversations.rb +12 -11
  18. data/bin/commands/admin_users.rb +1 -1
  19. data/bin/commands/admin_users_session.rb +1 -1
  20. data/bin/commands/apps_connections.rb +2 -2
  21. data/bin/commands/bookmarks.rb +1 -0
  22. data/bin/commands/chat.rb +9 -6
  23. data/bin/commands/conversations.rb +8 -6
  24. data/bin/commands/files.rb +24 -0
  25. data/bin/commands/rtm.rb +0 -15
  26. data/bin/commands/views.rb +4 -2
  27. data/bin/commands.rb +1 -0
  28. data/bin/slack +1 -1
  29. data/lib/slack/real_time/api/message.rb +3 -2
  30. data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
  31. data/lib/slack/real_time/api/typing.rb +2 -1
  32. data/lib/slack/real_time/client.rb +8 -26
  33. data/lib/slack/real_time/config.rb +3 -3
  34. data/lib/slack/real_time/models/channel.rb +4 -0
  35. data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
  36. data/lib/slack/real_time/models.rb +2 -1
  37. data/lib/slack/real_time/stores/base.rb +25 -9
  38. data/lib/slack/real_time/stores/starter.rb +323 -309
  39. data/lib/slack/real_time/stores/store.rb +265 -198
  40. data/lib/slack/real_time/stores.rb +1 -7
  41. data/lib/slack/version.rb +1 -1
  42. data/lib/slack/web/api/endpoints/admin_analytics.rb +1 -1
  43. data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
  44. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +1 -1
  45. data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
  46. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
  47. data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
  48. data/lib/slack/web/api/endpoints/admin_conversations.rb +30 -28
  49. data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
  50. data/lib/slack/web/api/endpoints/admin_emoji.rb +7 -7
  51. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
  52. data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
  53. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
  54. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
  55. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
  56. data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
  57. data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
  58. data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
  59. data/lib/slack/web/api/endpoints/apps.rb +2 -2
  60. data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
  61. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
  62. data/lib/slack/web/api/endpoints/apps_manifest.rb +6 -6
  63. data/lib/slack/web/api/endpoints/bookmarks.rb +10 -8
  64. data/lib/slack/web/api/endpoints/bots.rb +1 -1
  65. data/lib/slack/web/api/endpoints/calls.rb +5 -5
  66. data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
  67. data/lib/slack/web/api/endpoints/chat.rb +36 -30
  68. data/lib/slack/web/api/endpoints/conversations.rb +37 -33
  69. data/lib/slack/web/api/endpoints/dialog.rb +2 -2
  70. data/lib/slack/web/api/endpoints/dnd.rb +1 -1
  71. data/lib/slack/web/api/endpoints/files.rb +45 -8
  72. data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
  73. data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
  74. data/lib/slack/web/api/endpoints/migration.rb +1 -1
  75. data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
  76. data/lib/slack/web/api/endpoints/pins.rb +3 -3
  77. data/lib/slack/web/api/endpoints/reactions.rb +4 -4
  78. data/lib/slack/web/api/endpoints/reminders.rb +5 -5
  79. data/lib/slack/web/api/endpoints/rtm.rb +0 -23
  80. data/lib/slack/web/api/endpoints/search.rb +3 -3
  81. data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
  82. data/lib/slack/web/api/endpoints/usergroups.rb +4 -4
  83. data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
  84. data/lib/slack/web/api/endpoints/users.rb +4 -4
  85. data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
  86. data/lib/slack/web/api/endpoints/views.rb +16 -11
  87. data/lib/slack/web/api/endpoints/workflows.rb +4 -4
  88. data/lib/slack/web/api/endpoints.rb +2 -0
  89. data/lib/slack/web/api/errors.rb +56 -6
  90. data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
  91. data/lib/slack/web/api/mixins/users.id.rb +1 -1
  92. data/lib/slack/web/api/mixins/users.search.rb +2 -1
  93. data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
  94. data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
  95. data/lib/slack/web/api/patches/views.view-json.patch +55 -0
  96. data/lib/slack/web/api/templates/method.erb +1 -1
  97. data/lib/slack/web/config.rb +2 -2
  98. data/lib/tasks/real_time.rake +44 -22
  99. data/lib/tasks/web.rake +9 -2
  100. data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
  101. data/spec/slack/events/config_spec.rb +2 -0
  102. data/spec/slack/events/request_spec.rb +4 -0
  103. data/spec/slack/messages/formatting_spec.rb +10 -0
  104. data/spec/slack/real_time/api/message_spec.rb +1 -1
  105. data/spec/slack/real_time/api/ping_spec.rb +1 -1
  106. data/spec/slack/real_time/api/typing_spec.rb +1 -1
  107. data/spec/slack/real_time/client_spec.rb +73 -111
  108. data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
  109. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
  110. data/spec/slack/real_time/event_handlers/im_spec.rb +28 -25
  111. data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
  112. data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +24 -20
  113. data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
  114. data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
  115. data/spec/slack/real_time/stores/store_spec.rb +50 -0
  116. data/spec/slack/slack_spec.rb +1 -0
  117. data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
  118. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +17 -1
  119. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +2 -0
  120. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +13 -4
  121. data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
  122. data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
  123. data/spec/slack/web/api/mixins/users_spec.rb +2 -0
  124. data/spec/slack/web/api/pagination/cursor_spec.rb +4 -0
  125. data/spec/slack/web/client_spec.rb +14 -4
  126. data/spec/support/real_time/loaded_client.rb +120 -0
  127. metadata +18 -35
  128. data/bin/commands/admin_conversations_whitelist.rb +0 -37
  129. data/bin/commands/apps_permissions.rb +0 -23
  130. data/bin/commands/apps_permissions_resources.rb +0 -15
  131. data/bin/commands/apps_permissions_scopes.rb +0 -13
  132. data/bin/commands/apps_permissions_users.rb +0 -26
  133. data/bin/commands/channels.rb +0 -23
  134. data/bin/commands/groups.rb +0 -14
  135. data/bin/commands/im.rb +0 -6
  136. data/bin/commands/mpim.rb +0 -6
  137. data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
  138. data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
  139. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
  140. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
  141. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
  142. data/lib/slack/web/api/endpoints/channels.rb +0 -25
  143. data/lib/slack/web/api/endpoints/groups.rb +0 -13
  144. data/lib/slack/web/api/endpoints/im.rb +0 -13
  145. data/lib/slack/web/api/endpoints/mpim.rb +0 -13
  146. data/lib/slack/web/api/endpoints/presence.rb +0 -23
  147. data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
  148. data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
  149. data/spec/fixtures/slack/web/rtm_start.yml +0 -815
  150. data/spec/slack/real_time/rtm_start_spec.rb +0 -14
  151. data/spec/slack/real_time/store_spec.rb +0 -12
data/bin/commands/chat.rb CHANGED
@@ -83,12 +83,13 @@ command 'chat' do |g|
83
83
  c.flag 'attachments', desc: 'A JSON-based array of structured attachments, presented as a URL-encoded string.'
84
84
  c.flag 'blocks', desc: 'A JSON-based array of structured blocks, presented as a URL-encoded string.'
85
85
  c.flag 'text', desc: 'The formatted text of the message to be published. If blocks are included, this will become the fallback text used in notifications.'
86
- c.flag 'as_user', desc: 'Pass true to post the message as the authed user, instead of as a bot. Defaults to false. See authorship below.'
86
+ c.flag 'as_user', desc: 'Set to true to post the message as the authed user, instead of as a bot. Defaults to false. Cannot be used by new Slack apps. See authorship below.'
87
87
  c.flag 'icon_emoji', desc: 'Emoji to use as the icon for this message. Overrides icon_url. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.'
88
88
  c.flag 'icon_url', desc: 'URL to an image to use as the icon for this message. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.'
89
- c.flag 'link_names', desc: 'Find and link channel names and usernames.'
89
+ c.flag 'link_names', desc: 'Find and link user groups. No longer supports linking individual users; use syntax shown in Mentioning Users instead.'
90
+ c.flag 'metadata', desc: 'JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.'
90
91
  c.flag 'mrkdwn', desc: 'Disable Slack markup parsing by setting to false. Enabled by default.'
91
- c.flag 'parse', desc: 'Change how messages are treated. Defaults to none. See below.'
92
+ c.flag 'parse', desc: 'Change how messages are treated. See below.'
92
93
  c.flag 'reply_broadcast', desc: 'Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to false.'
93
94
  c.flag 'thread_ts', desc: "Provide another message's ts value to make this message a reply. Avoid using a reply's ts value; use its parent instead."
94
95
  c.flag 'unfurl_links', desc: 'Pass true to enable unfurling of primarily text-based content.'
@@ -105,11 +106,12 @@ command 'chat' do |g|
105
106
  c.flag 'channel', desc: 'Channel, private group, or DM channel to send message to. Can be an encoded ID, or a name. See below for more details.'
106
107
  c.flag 'post_at', desc: 'Unix EPOCH timestamp of time in future to send the message.'
107
108
  c.flag 'text', desc: 'How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.'
108
- c.flag 'as_user', desc: 'Pass true to post the message as the authed user, instead of as a bot. Defaults to false. See chat.postMessage.'
109
+ c.flag 'as_user', desc: 'Set to true to post the message as the authed user, instead of as a bot. Defaults to false. Cannot be used by new Slack apps. See chat.postMessage.'
109
110
  c.flag 'attachments', desc: 'A JSON-based array of structured attachments, presented as a URL-encoded string.'
110
111
  c.flag 'blocks', desc: 'A JSON-based array of structured blocks, presented as a URL-encoded string.'
111
- c.flag 'link_names', desc: 'Find and link channel names and usernames.'
112
- c.flag 'parse', desc: 'Change how messages are treated. Defaults to none. See chat.postMessage.'
112
+ c.flag 'link_names', desc: 'Find and link user groups. No longer supports linking individual users; use syntax shown in Mentioning Users instead.'
113
+ c.flag 'metadata', desc: 'JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.'
114
+ c.flag 'parse', desc: 'Change how messages are treated. See chat.postMessage.'
113
115
  c.flag 'reply_broadcast', desc: 'Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to false.'
114
116
  c.flag 'thread_ts', desc: "Provide another message's ts value to make this message a reply. Avoid using a reply's ts value; use its parent instead."
115
117
  c.flag 'unfurl_links', desc: 'Pass true to enable unfurling of primarily text-based content.'
@@ -146,6 +148,7 @@ command 'chat' do |g|
146
148
  c.flag 'blocks', desc: "A JSON-based array of structured blocks, presented as a URL-encoded string. If you don't include this field, the message's previous blocks will be retained. To remove previous blocks, include an empty array for this field."
147
149
  c.flag 'file_ids', desc: 'Array of new file ids that will be sent with this message.'
148
150
  c.flag 'link_names', desc: 'Find and link channel names and usernames. Defaults to none. If you do not specify a value for this field, the original value set for the message will be overwritten with the default, none.'
151
+ c.flag 'metadata', desc: "JSON object with event_type and event_payload fields, presented as a URL-encoded string. If you don't include this field, the message's previous metadata will be retained. To remove previous metadata, include an empty object for this field. Metadata you post to Slack is accessible to any app or user who is a member of that workspace."
149
152
  c.flag 'parse', desc: 'Change how messages are treated. Defaults to client, unlike chat.postMessage. Accepts either none or full. If you do not specify a value for this field, the original value set for the message will be overwritten with the default, client.'
150
153
  c.flag 'reply_broadcast', desc: 'Broadcast an existing thread reply to make it visible to everyone in the channel or conversation.'
151
154
  c.flag 'text', desc: "New text for the message, using the default formatting rules. It's not required when presenting blocks or attachments."
@@ -71,10 +71,11 @@ command 'conversations' do |g|
71
71
  g.command 'history' do |c|
72
72
  c.flag 'channel', desc: 'Conversation ID to fetch history for.'
73
73
  c.flag 'cursor', desc: "Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first 'page' of the collection. See pagination for more detail."
74
- c.flag 'inclusive', desc: 'Include messages with latest or oldest timestamp in results only when either timestamp is specified.'
75
- c.flag 'latest', desc: 'End of time range of messages to include in results. Default is the current time.'
74
+ c.flag 'include_all_metadata', desc: 'Return all metadata associated with this message.'
75
+ c.flag 'inclusive', desc: 'Include messages with oldest or latest timestamps in results. Ignored unless either timestamp is specified.'
76
+ c.flag 'latest', desc: 'Only messages before this Unix timestamp will be included in results. Default is the current time.'
76
77
  c.flag 'limit', desc: "The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached."
77
- c.flag 'oldest', desc: 'Start of time range of messages to include in results.'
78
+ c.flag 'oldest', desc: 'Only messages after this Unix timestamp will be included in results.'
78
79
  c.action do |_global_options, options, _args|
79
80
  puts JSON.dump($client.conversations_history(options))
80
81
  end
@@ -213,10 +214,11 @@ command 'conversations' do |g|
213
214
  c.flag 'channel', desc: 'Conversation ID to fetch thread from.'
214
215
  c.flag 'ts', desc: "Unique identifier of either a thread's parent message or a message in the thread. ts must be the timestamp of an existing message with 0 or more replies. If there are no replies then just the single message referenced by ts will return - it is just an ordinary, unthreaded message."
215
216
  c.flag 'cursor', desc: "Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first 'page' of the collection. See pagination for more detail."
216
- c.flag 'inclusive', desc: 'Include messages with latest or oldest timestamp in results only when either timestamp is specified.'
217
- c.flag 'latest', desc: 'End of time range of messages to include in results.'
217
+ c.flag 'include_all_metadata', desc: 'Return all metadata associated with this message.'
218
+ c.flag 'inclusive', desc: 'Include messages with oldest or latest timestamps in results. Ignored unless either timestamp is specified.'
219
+ c.flag 'latest', desc: 'Only messages before this Unix timestamp will be included in results.'
218
220
  c.flag 'limit', desc: "The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached."
219
- c.flag 'oldest', desc: 'Start of time range of messages to include in results.'
221
+ c.flag 'oldest', desc: 'Only messages after this Unix timestamp will be included in results.'
220
222
  c.action do |_global_options, options, _args|
221
223
  puts JSON.dump($client.conversations_replies(options))
222
224
  end
@@ -3,6 +3,18 @@
3
3
 
4
4
  desc 'Files methods.'
5
5
  command 'files' do |g|
6
+ g.desc 'Finishes an upload started with files.getUploadURLExternal'
7
+ g.long_desc %( Finishes an upload started with files.getUploadURLExternal )
8
+ g.command 'completeUploadExternal' do |c|
9
+ c.flag 'files', desc: 'Array of file ids and their corresponding (optional) titles.'
10
+ c.flag 'channel_id', desc: 'Channel ID where the file will be shared. If not specified the file will be private.'
11
+ c.flag 'initial_comment', desc: 'The message text introducing the file in specified channels.'
12
+ c.flag 'thread_ts', desc: "Provide another message's ts value to upload this file as a reply. Never use a reply's ts value; use its parent instead."
13
+ c.action do |_global_options, options, _args|
14
+ puts JSON.dump($client.files_completeUploadExternal(options))
15
+ end
16
+ end
17
+
6
18
  g.desc 'Deletes a file.'
7
19
  g.long_desc %( Deletes a file. )
8
20
  g.command 'delete' do |c|
@@ -23,6 +35,18 @@ command 'files' do |g|
23
35
  end
24
36
  end
25
37
 
38
+ g.desc 'Gets a URL for an edge external file upload'
39
+ g.long_desc %( Gets a URL for an edge external file upload )
40
+ g.command 'getUploadURLExternal' do |c|
41
+ c.flag 'filename', desc: 'Name of the file being uploaded.'
42
+ c.flag 'length', desc: 'Size in bytes of the file being uploaded.'
43
+ c.flag 'alt_txt', desc: 'Description of image for screen-reader.'
44
+ c.flag 'snippet_type', desc: 'Syntax type of the snippet being uploaded.'
45
+ c.action do |_global_options, options, _args|
46
+ puts JSON.dump($client.files_getUploadURLExternal(options))
47
+ end
48
+ end
49
+
26
50
  g.desc 'Gets information about a file.'
27
51
  g.long_desc %( Gets information about a file. )
28
52
  g.command 'info' do |c|
data/bin/commands/rtm.rb CHANGED
@@ -12,19 +12,4 @@ command 'rtm' do |g|
12
12
  puts JSON.dump($client.rtm_connect(options))
13
13
  end
14
14
  end
15
-
16
- g.desc 'Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead.'
17
- g.long_desc %( Deprecated: Starts a Real Time Messaging session. Use rtm.connect instead. )
18
- g.command 'start' do |c|
19
- c.flag 'batch_presence_aware', desc: 'Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. See batch presence.'
20
- c.flag 'include_locale', desc: 'Set this to true to receive the locale for users and channels. Defaults to false.'
21
- c.flag 'mpim_aware', desc: 'Returns MPIMs to the client in the API response.'
22
- c.flag 'no_latest', desc: 'Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1.'
23
- c.flag 'no_unreads', desc: 'Skip unread counts for each channel (improves performance).'
24
- c.flag 'presence_sub', desc: 'Only deliver presence events when requested by subscription. See presence subscriptions.'
25
- c.flag 'simple_latest', desc: 'Return timestamp only for latest message object of each channel (improves performance).'
26
- c.action do |_global_options, options, _args|
27
- puts JSON.dump($client.rtm_start(options))
28
- end
29
- end
30
15
  end
@@ -6,8 +6,9 @@ command 'views' do |g|
6
6
  g.desc 'Open a view for a user.'
7
7
  g.long_desc %( Open a view for a user. )
8
8
  g.command 'open' do |c|
9
- c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
10
9
  c.flag 'view', desc: 'A view payload. This must be a JSON-encoded string.'
10
+ c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
11
+ c.flag 'interactivity_pointer', desc: 'Exchange an interactivity pointer to post to the user.'
11
12
  c.action do |_global_options, options, _args|
12
13
  puts JSON.dump($client.views_open(options))
13
14
  end
@@ -27,8 +28,9 @@ command 'views' do |g|
27
28
  g.desc 'Push a view onto the stack of a root view.'
28
29
  g.long_desc %( Push a view onto the stack of a root view. )
29
30
  g.command 'push' do |c|
30
- c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
31
31
  c.flag 'view', desc: 'A view payload. This must be a JSON-encoded string.'
32
+ c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
33
+ c.flag 'interactivity_pointer', desc: 'Exchange an interactivity pointer to post to the user.'
32
34
  c.action do |_global_options, options, _args|
33
35
  puts JSON.dump($client.views_push(options))
34
36
  end
data/bin/commands.rb CHANGED
@@ -6,6 +6,7 @@ require 'commands/admin_apps'
6
6
  require 'commands/admin_apps_approved'
7
7
  require 'commands/admin_apps_requests'
8
8
  require 'commands/admin_apps_restricted'
9
+ require 'commands/admin_audit_anomaly_allow'
9
10
  require 'commands/admin_auth_policy'
10
11
  require 'commands/admin_barriers'
11
12
  require 'commands/admin_conversations'
data/bin/slack CHANGED
@@ -40,7 +40,7 @@ pre do |global_options, _command, options, _args|
40
40
  end
41
41
 
42
42
  # remove any nil values from options
43
- options.select! { |_k, v| v }
43
+ options.compact!
44
44
 
45
45
  true
46
46
  end
@@ -12,8 +12,9 @@ module Slack
12
12
  # @option options [Object] :text
13
13
  # Text of the message to send. See below for an explanation of formatting.
14
14
  def message(options = {})
15
- throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
16
- throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
15
+ raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
16
+ raise ArgumentError, 'Required arguments :text missing' if options[:text].nil?
17
+
17
18
  send_json({ type: 'message', id: next_id }.merge(options))
18
19
  end
19
20
  end
@@ -1,4 +1,8 @@
1
1
  # <%= desc %>
2
2
  # @see https://api.slack.com/events/<%= name %>
3
3
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/<%= name %>.json
4
- # on :<%= name %> do |data|
4
+ <% if hook %>
5
+ <%= hook %>
6
+ <% else %>
7
+ # on :<%= name %> do |data|
8
+ <% end %>
@@ -10,7 +10,8 @@ module Slack
10
10
  # Channel to send message to. Can be a public channel, private group or IM channel.
11
11
  # Can be an encoded ID, or a name.
12
12
  def typing(options = {})
13
- throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
13
+ raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
14
+
14
15
  send_json({ type: 'typing', id: next_id }.merge(options))
15
16
  end
16
17
  end
@@ -11,15 +11,9 @@ module Slack
11
11
  include Api::Message
12
12
  include Api::Typing
13
13
 
14
- @events = {}
15
-
16
- class << self
17
- attr_accessor :events
18
- end
19
-
20
14
  attr_accessor :web_client, :store, :url, *Config::ATTRIBUTES
21
15
 
22
- protected :store_class, :store_class=
16
+ protected :store_class, :store_class=, :store_options, :store_options=
23
17
 
24
18
  def initialize(options = {})
25
19
  @callbacks = Hash.new { |h, k| h[k] = [] }
@@ -31,7 +25,7 @@ module Slack
31
25
  @web_client = Slack::Web::Client.new(token: token, logger: logger)
32
26
  end
33
27
 
34
- %i[users self channels team teams groups ims bots].each do |store_method|
28
+ [:self, :team, *Stores::Base::CACHES].each do |store_method|
35
29
  define_method store_method do
36
30
  store&.send(store_method)
37
31
  end
@@ -162,10 +156,10 @@ module Slack
162
156
  def restart_async
163
157
  logger.debug("#{self}##{__method__}")
164
158
  @socket.close
165
- start = web_client.send(rtm_start_method, start_options)
159
+ start = web_client.rtm_connect(start_options)
166
160
  data = Slack::Messages::Message.new(start)
167
161
  @url = data.url
168
- @store = @store_class.new(data) if @store_class
162
+ @store = store_class.new(data, store_options.to_h) if store_class
169
163
  @socket.restart_async(self, @url)
170
164
  end
171
165
 
@@ -173,23 +167,13 @@ module Slack
173
167
  def build_socket
174
168
  raise ClientAlreadyStartedError if started?
175
169
 
176
- start = web_client.send(rtm_start_method, start_options)
170
+ start = web_client.rtm_connect(start_options)
177
171
  data = Slack::Messages::Message.new(start)
178
172
  @url = data.url
179
- @store = @store_class.new(data) if @store_class
173
+ @store = store_class.new(data, store_options.to_h) if store_class
180
174
  @socket = socket_class.new(@url, socket_options)
181
175
  end
182
176
 
183
- def rtm_start_method
184
- if start_method
185
- start_method
186
- elsif @store_class && @store_class <= Slack::RealTime::Stores::Store
187
- :rtm_start
188
- else
189
- :rtm_connect
190
- end
191
- end
192
-
193
177
  def socket_options
194
178
  socket_options = {}
195
179
  socket_options[:ping] = websocket_ping if websocket_ping
@@ -249,11 +233,9 @@ module Slack
249
233
  end
250
234
 
251
235
  def run_handlers(type, data)
252
- return unless store.class.events
253
-
254
236
  handlers = store.class.events[type.to_s]
255
- handlers&.each do |handler|
256
- store.instance_exec(data, &handler)
237
+ handlers.each do |handler|
238
+ store.instance_exec(data, self, &handler)
257
239
  end
258
240
  rescue StandardError => e
259
241
  logger.error("#{self}##{__method__}") { e }
@@ -11,9 +11,9 @@ module Slack
11
11
  websocket_ping
12
12
  websocket_proxy
13
13
  concurrency
14
- start_method
15
14
  start_options
16
15
  store_class
16
+ store_options
17
17
  logger
18
18
  ].freeze
19
19
 
@@ -25,9 +25,9 @@ module Slack
25
25
  self.websocket_proxy = nil
26
26
  self.token = nil
27
27
  self.concurrency = method(:detect_concurrency)
28
- self.start_method = nil
29
28
  self.start_options = { request: { timeout: 180 } }
30
- self.store_class = Slack::RealTime::Store
29
+ self.store_class = Slack::RealTime::Stores::Starter
30
+ self.store_options = {}
31
31
  self.logger = nil
32
32
  end
33
33
 
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Slack
3
4
  module RealTime
4
5
  module Models
5
6
  class Channel < Base
7
+ def is_public? # rubocop:disable Naming/PredicateName
8
+ !is_private?
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -2,7 +2,7 @@
2
2
  module Slack
3
3
  module RealTime
4
4
  module Models
5
- class Group < Base
5
+ class Mpim < Base
6
6
  end
7
7
  end
8
8
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'models/base'
3
4
  require_relative 'models/user'
4
5
  require_relative 'models/bot'
5
6
  require_relative 'models/channel'
6
- require_relative 'models/group'
7
7
  require_relative 'models/team'
8
8
  require_relative 'models/im'
9
+ require_relative 'models/mpim'
@@ -1,14 +1,36 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Slack
3
4
  module RealTime
4
5
  module Stores
5
6
  # Doesn't store anything.
6
7
  class Base
8
+ CACHES = %i[
9
+ teams
10
+ users
11
+ bots
12
+ public_channels
13
+ private_channels
14
+ ims
15
+ mpims
16
+ ].freeze
17
+
18
+ @events = Hash.new { |h, k| h[k] = [] }
19
+
7
20
  class << self
8
- attr_accessor :events
21
+ attr_reader :events
22
+
23
+ def inherited(subclass)
24
+ super
25
+ subclass.instance_variable_set :@events, events.dup
26
+ end
27
+
28
+ def on(event, &handler)
29
+ events[event.to_s] << handler
30
+ end
9
31
  end
10
32
 
11
- attr_accessor :users, :bots, :channels, :groups, :teams, :ims
33
+ attr_accessor(*CACHES)
12
34
 
13
35
  def self
14
36
  nil
@@ -18,13 +40,7 @@ module Slack
18
40
  nil
19
41
  end
20
42
 
21
- def initialize(_attrs); end
22
-
23
- def self.on(event, &block)
24
- self.events ||= {}
25
- self.events[event.to_s] ||= []
26
- self.events[event.to_s] << block
27
- end
43
+ def initialize(_attrs, _options = {}); end
28
44
  end
29
45
  end
30
46
  end