slack-ruby-client 0.13.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (402) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/integration_test.yml +26 -0
  4. data/.github/workflows/lint.yml +14 -0
  5. data/.github/workflows/pr_lint.yml +21 -0
  6. data/.github/workflows/test.yml +36 -0
  7. data/.gitignore +5 -3
  8. data/.rubocop.yml +34 -5
  9. data/.rubocop_todo.yml +180 -46
  10. data/.ruby-version +1 -0
  11. data/CHANGELOG.md +119 -2
  12. data/CONTRIBUTING.md +23 -11
  13. data/Dangerfile +2 -0
  14. data/Gemfile +22 -5
  15. data/Gemfile.danger +6 -0
  16. data/LICENSE.md +1 -1
  17. data/README.md +236 -101
  18. data/RELEASING.md +2 -2
  19. data/Rakefile +2 -1
  20. data/UPGRADING.md +100 -2
  21. data/bin/commands/admin_analytics.rb +16 -0
  22. data/bin/commands/admin_apps.rb +51 -0
  23. data/bin/commands/admin_apps_approved.rb +17 -0
  24. data/bin/commands/admin_apps_requests.rb +28 -0
  25. data/bin/commands/admin_apps_restricted.rb +17 -0
  26. data/bin/commands/admin_audit_anomaly_allow.rb +23 -0
  27. data/bin/commands/admin_auth_policy.rb +39 -0
  28. data/bin/commands/admin_barriers.rb +47 -0
  29. data/bin/commands/admin_conversations.rb +171 -0
  30. data/bin/commands/admin_conversations_ekm.rb +17 -0
  31. data/bin/commands/admin_conversations_restrictAccess.rb +37 -0
  32. data/bin/commands/admin_emoji.rb +54 -0
  33. data/bin/commands/admin_inviteRequests.rb +36 -0
  34. data/bin/commands/admin_inviteRequests_approved.rb +16 -0
  35. data/bin/commands/admin_inviteRequests_denied.rb +16 -0
  36. data/bin/commands/admin_teams.rb +27 -0
  37. data/bin/commands/admin_teams_admins.rb +16 -0
  38. data/bin/commands/admin_teams_owners.rb +16 -0
  39. data/bin/commands/admin_teams_settings.rb +64 -0
  40. data/bin/commands/admin_usergroups.rb +48 -0
  41. data/bin/commands/admin_users.rb +98 -0
  42. data/bin/commands/admin_users_session.rb +78 -0
  43. data/bin/commands/admin_users_unsupportedVersions.rb +15 -0
  44. data/bin/commands/api.rb +1 -1
  45. data/bin/commands/apps.rb +15 -0
  46. data/bin/commands/apps_connections.rb +13 -0
  47. data/bin/commands/apps_event_authorizations.rb +16 -0
  48. data/bin/commands/apps_manifest.rb +52 -0
  49. data/bin/commands/auth.rb +1 -0
  50. data/bin/commands/auth_teams.rb +16 -0
  51. data/bin/commands/bookmarks.rb +53 -0
  52. data/bin/commands/bots.rb +2 -0
  53. data/bin/commands/calls.rb +52 -0
  54. data/bin/commands/calls_participants.rb +25 -0
  55. data/bin/commands/chat.rb +61 -14
  56. data/bin/commands/chat_scheduledMessages.rb +19 -0
  57. data/bin/commands/conversations.rb +82 -10
  58. data/bin/commands/dialog.rb +1 -0
  59. data/bin/commands/dnd.rb +6 -3
  60. data/bin/commands/emoji.rb +1 -0
  61. data/bin/commands/files.rb +34 -18
  62. data/bin/commands/files_comments.rb +1 -21
  63. data/bin/commands/files_remote.rb +78 -0
  64. data/bin/commands/migration.rb +2 -0
  65. data/bin/commands/oauth.rb +2 -14
  66. data/bin/commands/oauth_v2.rb +29 -0
  67. data/bin/commands/openid_connect.rb +27 -0
  68. data/bin/commands/pins.rb +3 -6
  69. data/bin/commands/reactions.rb +3 -3
  70. data/bin/commands/reminders.rb +7 -0
  71. data/bin/commands/rtm.rb +1 -15
  72. data/bin/commands/search.rb +6 -1
  73. data/bin/commands/stars.rb +8 -6
  74. data/bin/commands/team.rb +6 -0
  75. data/bin/commands/team_billing.rb +13 -0
  76. data/bin/commands/team_preferences.rb +13 -0
  77. data/bin/commands/team_profile.rb +1 -0
  78. data/bin/commands/tooling_tokens.rb +14 -0
  79. data/bin/commands/usergroups.rb +7 -1
  80. data/bin/commands/usergroups_users.rb +3 -0
  81. data/bin/commands/users.rb +6 -4
  82. data/bin/commands/users_admin.rb +1 -0
  83. data/bin/commands/users_prefs.rb +1 -0
  84. data/bin/commands/users_profile.rb +6 -5
  85. data/bin/commands/views.rb +50 -0
  86. data/bin/commands/workflows.rb +38 -0
  87. data/bin/commands.rb +41 -8
  88. data/bin/slack +3 -4
  89. data/examples/hi_real_time_and_web/Gemfile +1 -0
  90. data/examples/hi_real_time_and_web/hi.rb +7 -3
  91. data/examples/hi_real_time_async_async/Gemfile +1 -0
  92. data/examples/hi_real_time_async_async/hi.rb +6 -2
  93. data/examples/hi_web/Gemfile +1 -0
  94. data/examples/hi_web/hi.rb +1 -0
  95. data/examples/new_ticket/Gemfile +1 -0
  96. data/examples/new_ticket/new_ticket.rb +1 -0
  97. data/lib/slack/config.rb +2 -2
  98. data/lib/slack/events/config.rb +32 -0
  99. data/lib/slack/events/request.rb +72 -0
  100. data/lib/slack/logger.rb +6 -5
  101. data/lib/slack/messages/formatting.rb +1 -0
  102. data/lib/slack/messages/message.rb +1 -4
  103. data/lib/slack/real_time/api/message.rb +6 -3
  104. data/lib/slack/real_time/api/message_id.rb +1 -0
  105. data/lib/slack/real_time/api/ping.rb +5 -2
  106. data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
  107. data/lib/slack/real_time/api/typing.rb +5 -2
  108. data/lib/slack/real_time/client.rb +105 -54
  109. data/lib/slack/real_time/concurrency/async.rb +77 -6
  110. data/lib/slack/real_time/concurrency.rb +1 -2
  111. data/lib/slack/real_time/config.rb +9 -13
  112. data/lib/slack/real_time/models/base.rb +1 -4
  113. data/lib/slack/real_time/models/bot.rb +1 -0
  114. data/lib/slack/real_time/models/channel.rb +5 -0
  115. data/lib/slack/real_time/models/im.rb +1 -0
  116. data/lib/slack/real_time/models/{group.rb → mpim.rb} +2 -1
  117. data/lib/slack/real_time/models/team.rb +1 -0
  118. data/lib/slack/real_time/models/user.rb +1 -0
  119. data/lib/slack/real_time/models.rb +3 -1
  120. data/lib/slack/real_time/socket.rb +45 -17
  121. data/lib/slack/real_time/stores/base.rb +28 -14
  122. data/lib/slack/real_time/stores/starter.rb +325 -297
  123. data/lib/slack/real_time/stores/store.rb +271 -196
  124. data/lib/slack/real_time/stores.rb +2 -7
  125. data/lib/slack/version.rb +2 -1
  126. data/lib/slack/web/api/endpoints/admin_analytics.rb +28 -0
  127. data/lib/slack/web/api/endpoints/admin_apps.rb +78 -0
  128. data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
  129. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +51 -0
  130. data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
  131. data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
  132. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
  133. data/lib/slack/web/api/endpoints/admin_barriers.rb +82 -0
  134. data/lib/slack/web/api/endpoints/admin_conversations.rb +264 -0
  135. data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +35 -0
  136. data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +61 -0
  137. data/lib/slack/web/api/endpoints/admin_emoji.rb +88 -0
  138. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +61 -0
  139. data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +33 -0
  140. data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +33 -0
  141. data/lib/slack/web/api/endpoints/admin_teams.rb +50 -0
  142. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +34 -0
  143. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +34 -0
  144. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +99 -0
  145. data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
  146. data/lib/slack/web/api/endpoints/admin_users.rb +163 -0
  147. data/lib/slack/web/api/endpoints/admin_users_session.rb +122 -0
  148. data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
  149. data/lib/slack/web/api/endpoints/api.rb +2 -3
  150. data/lib/slack/web/api/endpoints/apps.rb +27 -0
  151. data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
  152. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
  153. data/lib/slack/web/api/endpoints/apps_manifest.rb +77 -0
  154. data/lib/slack/web/api/endpoints/auth.rb +2 -1
  155. data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
  156. data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
  157. data/lib/slack/web/api/endpoints/bots.rb +4 -1
  158. data/lib/slack/web/api/endpoints/calls.rb +83 -0
  159. data/lib/slack/web/api/endpoints/calls_participants.rb +42 -0
  160. data/lib/slack/web/api/endpoints/chat.rb +168 -65
  161. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +40 -0
  162. data/lib/slack/web/api/endpoints/conversations.rb +182 -67
  163. data/lib/slack/web/api/endpoints/dialog.rb +5 -4
  164. data/lib/slack/web/api/endpoints/dnd.rb +9 -4
  165. data/lib/slack/web/api/endpoints/emoji.rb +1 -0
  166. data/lib/slack/web/api/endpoints/files.rb +69 -37
  167. data/lib/slack/web/api/endpoints/files_comments.rb +4 -36
  168. data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
  169. data/lib/slack/web/api/endpoints/migration.rb +6 -3
  170. data/lib/slack/web/api/endpoints/oauth.rb +7 -31
  171. data/lib/slack/web/api/endpoints/oauth_v2.rb +48 -0
  172. data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
  173. data/lib/slack/web/api/endpoints/pins.rb +11 -18
  174. data/lib/slack/web/api/endpoints/reactions.rb +22 -21
  175. data/lib/slack/web/api/endpoints/reminders.rb +23 -10
  176. data/lib/slack/web/api/endpoints/rtm.rb +3 -25
  177. data/lib/slack/web/api/endpoints/search.rb +31 -16
  178. data/lib/slack/web/api/endpoints/stars.rb +14 -11
  179. data/lib/slack/web/api/endpoints/team.rb +15 -4
  180. data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
  181. data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
  182. data/lib/slack/web/api/endpoints/team_profile.rb +2 -1
  183. data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
  184. data/lib/slack/web/api/endpoints/usergroups.rb +31 -20
  185. data/lib/slack/web/api/endpoints/usergroups_users.rb +13 -8
  186. data/lib/slack/web/api/endpoints/users.rb +24 -23
  187. data/lib/slack/web/api/endpoints/users_admin.rb +3 -2
  188. data/lib/slack/web/api/endpoints/users_prefs.rb +1 -0
  189. data/lib/slack/web/api/endpoints/users_profile.rb +8 -7
  190. data/lib/slack/web/api/endpoints/views.rb +102 -0
  191. data/lib/slack/web/api/endpoints/workflows.rb +61 -0
  192. data/lib/slack/web/api/endpoints.rb +82 -18
  193. data/lib/slack/web/api/error.rb +1 -0
  194. data/lib/slack/web/api/errors/server_error.rb +37 -0
  195. data/lib/slack/web/api/errors/slack_error.rb +14 -1
  196. data/lib/slack/web/api/errors/too_many_requests_error.rb +2 -4
  197. data/lib/slack/web/api/errors.rb +1116 -0
  198. data/lib/slack/web/api/mixins/{channels.id.rb → conversations.id.rb} +5 -6
  199. data/lib/slack/web/api/mixins/ids.id.rb +3 -2
  200. data/lib/slack/web/api/mixins/users.id.rb +3 -4
  201. data/lib/slack/web/api/mixins/users.search.rb +3 -1
  202. data/lib/slack/web/api/mixins.rb +2 -2
  203. data/lib/slack/web/api/patches/chat.attachments-blocks.patch +69 -0
  204. data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
  205. data/lib/slack/web/api/patches/views.view-json.patch +55 -0
  206. data/lib/slack/web/api/templates/command.erb +1 -0
  207. data/lib/slack/web/api/templates/commands.erb +1 -0
  208. data/lib/slack/web/api/templates/endpoints.erb +2 -2
  209. data/lib/slack/web/api/templates/errors.erb +20 -0
  210. data/lib/slack/web/api/templates/method.erb +6 -2
  211. data/lib/slack/web/api/templates/method_spec.erb +2 -1
  212. data/lib/slack/web/client.rb +2 -1
  213. data/lib/slack/web/config.rb +5 -2
  214. data/lib/slack/web/faraday/connection.rb +24 -20
  215. data/lib/slack/web/faraday/request.rb +5 -1
  216. data/lib/slack/web/faraday/response/raise_error.rb +14 -7
  217. data/lib/slack/web/faraday/response/wrap_error.rb +24 -0
  218. data/lib/slack/web/pagination/cursor.rb +7 -7
  219. data/lib/slack-ruby-client.rb +12 -5
  220. data/lib/slack.rb +1 -0
  221. data/lib/slack_ruby_client.rb +1 -0
  222. data/lib/tasks/git.rake +1 -0
  223. data/lib/tasks/real_time.rake +51 -21
  224. data/lib/tasks/update.rake +1 -0
  225. data/lib/tasks/web.rake +48 -12
  226. data/screenshots/create-app.png +0 -0
  227. data/slack-ruby-client.gemspec +7 -12
  228. data/spec/fixtures/slack/web/429_error.yml +50 -54
  229. data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
  230. data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
  231. data/spec/fixtures/slack/web/conversations_info.yml +167 -0
  232. data/spec/fixtures/slack/web/conversations_setTopic.yml +84 -0
  233. data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +172 -0
  234. data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +253 -0
  235. data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
  236. data/spec/fixtures/slack/web/rtm_connect.yml +347 -26
  237. data/spec/fixtures/slack/web/users_info.yml +153 -69
  238. data/spec/fixtures/slack/web/users_list.yml +102 -41
  239. data/spec/fixtures/slack/web/views_open_error.yml +83 -0
  240. data/spec/integration/integration_spec.rb +115 -47
  241. data/spec/slack/config_spec.rb +2 -0
  242. data/spec/slack/events/config_spec.rb +35 -0
  243. data/spec/slack/events/request_spec.rb +188 -0
  244. data/spec/slack/messages/formatting_spec.rb +35 -13
  245. data/spec/slack/real_time/api/message_spec.rb +7 -2
  246. data/spec/slack/real_time/api/ping_spec.rb +3 -1
  247. data/spec/slack/real_time/api/typing_spec.rb +6 -2
  248. data/spec/slack/real_time/client_spec.rb +300 -142
  249. data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +2 -0
  250. data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
  251. data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
  252. data/spec/slack/real_time/event_handlers/bot_spec.rb +20 -17
  253. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +3 -2
  254. data/spec/slack/real_time/event_handlers/im_spec.rb +31 -27
  255. data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +36 -27
  256. data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +31 -24
  257. data/spec/slack/real_time/event_handlers/team_spec.rb +8 -7
  258. data/spec/slack/real_time/event_handlers/user_spec.rb +7 -5
  259. data/spec/slack/real_time/rtm_connect_spec.rb +2 -1
  260. data/spec/slack/real_time/stores/store_spec.rb +50 -0
  261. data/spec/slack/slack_spec.rb +41 -6
  262. data/spec/slack/version_spec.rb +2 -1
  263. data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +13 -0
  264. data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +8 -0
  265. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +13 -0
  266. data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
  267. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +18 -0
  268. data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
  269. data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -0
  270. data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +38 -0
  271. data/spec/slack/web/api/endpoints/admin_conversations_ekm_spec.rb +8 -0
  272. data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
  273. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +98 -0
  274. data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +37 -0
  275. data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +8 -0
  276. data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +8 -0
  277. data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +18 -0
  278. data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +13 -0
  279. data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +13 -0
  280. data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +53 -0
  281. data/spec/slack/web/api/endpoints/admin_teams_spec.rb +16 -0
  282. data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
  283. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +41 -0
  284. data/spec/slack/web/api/endpoints/admin_users_spec.rb +67 -0
  285. data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
  286. data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
  287. data/spec/slack/web/api/endpoints/apps_connections_spec.rb +8 -0
  288. data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +13 -0
  289. data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +36 -0
  290. data/spec/slack/web/api/endpoints/apps_spec.rb +16 -0
  291. data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → auth_teams_spec.rb} +2 -1
  292. data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
  293. data/spec/slack/web/api/endpoints/bots_spec.rb +1 -0
  294. data/spec/slack/web/api/endpoints/calls_participants_spec.rb +24 -0
  295. data/spec/slack/web/api/endpoints/calls_spec.rb +31 -0
  296. data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +8 -0
  297. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +9 -7
  298. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +144 -40
  299. data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
  300. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +18 -6
  301. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +8 -3
  302. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +112 -0
  303. data/spec/slack/web/api/endpoints/dnd_spec.rb +4 -3
  304. data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
  305. data/spec/slack/web/api/endpoints/files_comments_spec.rb +3 -21
  306. data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
  307. data/spec/slack/web/api/endpoints/files_spec.rb +18 -4
  308. data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
  309. data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -22
  310. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +16 -0
  311. data/spec/slack/web/api/endpoints/openid_connect_spec.rb +8 -0
  312. data/spec/slack/web/api/endpoints/pins_spec.rb +1 -0
  313. data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
  314. data/spec/slack/web/api/endpoints/reminders_spec.rb +3 -2
  315. data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
  316. data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
  317. data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
  318. data/spec/slack/web/api/endpoints/{apps_permissions_scopes_spec.rb → team_billing_spec.rb} +2 -1
  319. data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -0
  320. data/spec/slack/web/api/endpoints/team_profile_spec.rb +1 -0
  321. data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
  322. data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
  323. data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
  324. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +3 -2
  325. data/spec/slack/web/api/endpoints/users_admin_spec.rb +1 -0
  326. data/spec/slack/web/api/endpoints/users_prefs_spec.rb +1 -0
  327. data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
  328. data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
  329. data/spec/slack/web/api/error_spec.rb +7 -7
  330. data/spec/slack/web/api/errors/slack_error_spec.rb +26 -7
  331. data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
  332. data/spec/slack/web/api/mixins/conversations_spec.rb +45 -0
  333. data/spec/slack/web/api/mixins/users_spec.rb +19 -8
  334. data/spec/slack/web/api/pagination/cursor_spec.rb +47 -15
  335. data/spec/slack/web/client_spec.rb +199 -22
  336. data/spec/slack/web/faraday/request_spec.rb +80 -0
  337. data/spec/slack/web/faraday/response/raise_error_spec.rb +48 -12
  338. data/spec/spec_helper.rb +9 -2
  339. data/spec/support/queue_with_timeout.rb +5 -4
  340. data/spec/support/real_time/concurrency/mock.rb +1 -0
  341. data/spec/support/real_time/connected_client.rb +6 -6
  342. data/spec/support/real_time/event.rb +1 -0
  343. data/spec/support/real_time/loaded_client.rb +120 -0
  344. data/spec/support/token.rb +1 -0
  345. data/spec/support/vcr.rb +37 -1
  346. metadata +174 -262
  347. data/.travis.yml +0 -32
  348. data/bin/commands/apps_permissions.rb +0 -22
  349. data/bin/commands/apps_permissions_resources.rb +0 -14
  350. data/bin/commands/apps_permissions_scopes.rb +0 -12
  351. data/bin/commands/apps_permissions_users.rb +0 -25
  352. data/bin/commands/channels.rb +0 -175
  353. data/bin/commands/groups.rb +0 -174
  354. data/bin/commands/im.rb +0 -67
  355. data/bin/commands/mpim.rb +0 -65
  356. data/examples/hi_real_time/Gemfile +0 -5
  357. data/examples/hi_real_time/hi.gif +0 -0
  358. data/examples/hi_real_time/hi.rb +0 -37
  359. data/examples/hi_real_time_async_celluloid/Gemfile +0 -6
  360. data/examples/hi_real_time_async_celluloid/Procfile +0 -2
  361. data/examples/hi_real_time_async_celluloid/hi.rb +0 -35
  362. data/examples/hi_real_time_async_eventmachine/Gemfile +0 -6
  363. data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
  364. data/examples/hi_real_time_async_eventmachine/hi.rb +0 -35
  365. data/lib/slack/real_time/concurrency/celluloid.rb +0 -118
  366. data/lib/slack/real_time/concurrency/eventmachine.rb +0 -66
  367. data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -35
  368. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -30
  369. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -20
  370. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -49
  371. data/lib/slack/web/api/endpoints/channels.rb +0 -266
  372. data/lib/slack/web/api/endpoints/groups.rb +0 -265
  373. data/lib/slack/web/api/endpoints/im.rb +0 -113
  374. data/lib/slack/web/api/endpoints/mpim.rb +0 -108
  375. data/lib/slack/web/api/endpoints/presence.rb +0 -23
  376. data/lib/slack/web/api/mixins/channels.id.json +0 -20
  377. data/lib/slack/web/api/mixins/groups.id.json +0 -20
  378. data/lib/slack/web/api/mixins/groups.id.rb +0 -26
  379. data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +0 -13
  380. data/lib/slack/web/api/patches/chat.2.attachments-json.patch +0 -17
  381. data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +0 -21
  382. data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +0 -17
  383. data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +0 -13
  384. data/screenshots/register-bot.png +0 -0
  385. data/spec/fixtures/slack/web/503_error.yml +0 -14
  386. data/spec/fixtures/slack/web/channels_info.yml +0 -46
  387. data/spec/fixtures/slack/web/groups_info.yml +0 -43
  388. data/spec/fixtures/slack/web/rtm_start.yml +0 -104
  389. data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -106
  390. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -47
  391. data/spec/slack/real_time/rtm_start_spec.rb +0 -13
  392. data/spec/slack/real_time/store_spec.rb +0 -11
  393. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -15
  394. data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -18
  395. data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -100
  396. data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -11
  397. data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -11
  398. data/spec/slack/web/api/endpoints/im_spec.rb +0 -38
  399. data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -38
  400. data/spec/slack/web/api/errors/service_unavailable_spec.rb +0 -14
  401. data/spec/slack/web/api/mixins/channels_spec.rb +0 -33
  402. data/spec/slack/web/api/mixins/groups_spec.rb +0 -33
@@ -1,180 +1,104 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Slack
2
4
  module RealTime
3
5
  module Stores
4
- # Stores everything.
6
+ # Full store with initialization logic
5
7
  class Store < Base
6
- def self
7
- users[@self_id]
8
- end
9
-
10
- def team
11
- teams[@team_id]
12
- end
8
+ CONVERSATION_TYPES = {
9
+ public_channels: 'public_channel',
10
+ private_channels: 'private_channel',
11
+ ims: 'im',
12
+ mpims: 'mpim'
13
+ }.freeze
14
+
15
+ attr_reader :caches
16
+
17
+ def initialize(attrs, options = {})
18
+ @teams = {}
19
+ @users = {}
20
+ @bots = {}
21
+ @public_channels = {}
22
+ @private_channels = {}
23
+ @ims = {}
24
+ @mpims = {}
13
25
 
14
- def initialize(attrs)
15
26
  if attrs.team
16
27
  @team_id = attrs.team.id
17
- @teams = { @team_id => Slack::RealTime::Models::Team.new(attrs.team) }
18
- else
19
- @teams = {}
28
+ @teams[@team_id] = Models::Team.new(attrs.team)
20
29
  end
21
30
 
22
31
  if attrs.self
23
32
  @self_id = attrs.self.id
24
- @users = { @self_id => Slack::RealTime::Models::User.new(attrs.self) }
25
- else
26
- @users = {}
33
+ @users[@self_id] = Models::User.new(attrs.self)
27
34
  end
28
35
 
29
- if attrs.users
30
- attrs.users.each do |data|
31
- user = Models::User.new(data)
32
- @users[data.id] = @users.key?(data.id) ? @users[data.id].merge(user) : user
36
+ @caches =
37
+ if options[:caches].is_a?(Array) || options[:caches].nil?
38
+ caches = options[:caches].to_a.map(&:to_sym)
39
+ unknown_caches = caches - CACHES
40
+ raise ArgumentError, "Unknown caches: #{unknown_caches.join(', ')}" unless unknown_caches.empty?
41
+
42
+ Set.new(caches).freeze
43
+ elsif options[:caches] == :all
44
+ Set.new(CACHES).freeze
45
+ else
46
+ raise ArgumentError, 'Unexpected value for option `caches`. Expects :all or an array of caches'
33
47
  end
34
- end
35
-
36
- @channels = {}
37
- if attrs.channels
38
- attrs.channels.each do |data|
39
- @channels[data.id] = Models::Channel.new(data)
40
- end
41
- end
42
-
43
- @bots = {}
44
- if attrs.bots
45
- attrs.bots.each do |data|
46
- @bots[data.id] = Models::Bot.new(data)
47
- end
48
- end
48
+ end
49
49
 
50
- @groups = {}
51
- if attrs.groups
52
- attrs.groups.each do |data|
53
- @groups[data.id] = Models::Group.new(data)
54
- end
55
- end
50
+ def self
51
+ users[@self_id]
52
+ end
56
53
 
57
- @ims = {}
58
- if attrs.ims
59
- attrs.ims.each do |data|
60
- @ims[data.id] = Models::Im.new(data)
61
- end
62
- end
54
+ def team
55
+ teams[@team_id]
63
56
  end
64
57
 
65
58
  ### RealTime Events
66
59
 
67
- # A private channel was deleted.
68
- # @see https://api.slack.com/events/group_deleted
69
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_deleted.json
70
- # on :group_deleted do |data|
71
-
72
- # Determine the current presence status for a list of users.
73
- # @see https://api.slack.com/events/presence_query
74
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/presence_query.json
75
- # on :presence_query do |data|
76
-
77
- # The membership of an existing User Group has changed.
78
- # @see https://api.slack.com/events/subteam_members_changed
79
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_members_changed.json
80
- # on :subteam_members_changed do |data|
81
-
82
- # Subscribe to presence events for the specified users.
83
- # @see https://api.slack.com/events/presence_sub
84
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/presence_sub.json
85
- # on :presence_sub do |data|
86
-
87
- # A user left a public or private channel.
88
- # @see https://api.slack.com/events/member_left_channel
89
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/member_left_channel.json
90
- # on :member_left_channel do |data|
91
-
92
- # A user joined a public or private channel.
93
- # @see https://api.slack.com/events/member_joined_channel
94
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/member_joined_channel.json
95
- # on :member_joined_channel do |data|
96
-
97
- # The server intends to close the connection soon..
98
- # @see https://api.slack.com/events/goodbye
99
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/goodbye.json
100
- # on :goodbye do |data|
101
-
102
- # Verifies ownership of an Events API Request URL.
103
- # @see https://api.slack.com/events/url_verification
104
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/url_verification.json
105
- # on :url_verification do |data|
106
-
107
- # A message was posted in a multiparty direct message channel.
108
- # @see https://api.slack.com/events/message.mpim
109
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/message.mpim.json
110
- # on :message.mpim do |data|
111
-
112
- # A message was posted in a direct message channel.
113
- # @see https://api.slack.com/events/message.im
114
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/message.im.json
115
- # on :message.im do |data|
116
-
117
- # A message was posted to a private channel.
118
- # @see https://api.slack.com/events/message.groups
119
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/message.groups.json
120
- # on :message.groups do |data|
121
-
122
- # A message was posted to a channel.
123
- # @see https://api.slack.com/events/message.channels
124
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/message.channels.json
125
- # on :message.channels do |data|
126
-
127
- # A direct message read marker was updated.
128
- # @see https://api.slack.com/events/im_marked
129
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_marked.json
130
- # on :im_marked do |data|
131
-
132
- # Bulk updates were made to a DM channel's history.
133
- # @see https://api.slack.com/events/im_history_changed
134
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_history_changed.json
135
- # on :im_history_changed do |data|
136
-
137
60
  # The list of accounts a user is signed into has changed.
138
61
  # @see https://api.slack.com/events/accounts_changed
139
62
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/accounts_changed.json
140
63
  # on :accounts_changed do |data|
141
64
 
142
- # An integration bot was added.
65
+ # A bot user was added.
143
66
  # @see https://api.slack.com/events/bot_added
144
67
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/bot_added.json
145
68
  on :bot_added do |data|
146
- bots[data.bot.id] = Models::Bot.new(data.bot)
69
+ bot = Models::Bot.new(data.bot)
70
+ bots[bot.id] = bot
147
71
  end
148
72
 
149
- # An integration bot was changed.
73
+ # A bot user was changed.
150
74
  # @see https://api.slack.com/events/bot_changed
151
75
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/bot_changed.json
152
76
  on :bot_changed do |data|
153
77
  bot = bots[data.bot.id]
154
- bot.merge!(data.bot) if bot
78
+ bot&.merge!(data.bot)
155
79
  end
156
80
 
157
- # A team channel was archived.
81
+ # A channel was archived.
158
82
  # @see https://api.slack.com/events/channel_archive
159
83
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_archive.json
160
84
  on :channel_archive do |data|
161
- channel = channels[data.channel]
85
+ channel = public_channels[data.channel]
162
86
  channel.is_archived = true if channel
163
87
  end
164
88
 
165
- # A team channel was created.
89
+ # A channel was created.
166
90
  # @see https://api.slack.com/events/channel_created
167
91
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_created.json
168
92
  on :channel_created do |data|
169
93
  channel = Models::Channel.new(data.channel)
170
- channels[channel.id] = channel
94
+ public_channels[channel.id] = channel
171
95
  end
172
96
 
173
- # A team channel was deleted.
97
+ # A channel was deleted.
174
98
  # @see https://api.slack.com/events/channel_deleted
175
99
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_deleted.json
176
100
  on :channel_deleted do |data|
177
- channels.delete(data.channel)
101
+ public_channels.delete(data.channel)
178
102
  end
179
103
 
180
104
  # Bulk updates were made to a channel's history.
@@ -187,11 +111,20 @@ module Slack
187
111
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_joined.json
188
112
  on :channel_joined do |data|
189
113
  channel_id = data.channel.id
190
- channel = channels[channel_id]
191
- if channel
192
- channel.merge!(data.channel)
114
+ if data.channel.is_private?
115
+ channel = private_channels[channel_id]
116
+ if channel
117
+ channel.merge!(data.channel)
118
+ else
119
+ private_channels[channel_id] = Models::Channel.new(data.channel)
120
+ end
193
121
  else
194
- channels[channel_id] = Models::Channel.new(data.channel)
122
+ channel = public_channels[channel_id]
123
+ if channel
124
+ channel.merge!(data.channel)
125
+ else
126
+ public_channels[channel_id] = Models::Channel.new(data.channel)
127
+ end
195
128
  end
196
129
  end
197
130
 
@@ -199,8 +132,8 @@ module Slack
199
132
  # @see https://api.slack.com/events/channel_left
200
133
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_left.json
201
134
  on :channel_left do |data|
202
- channel = channels[data.channel]
203
- channel.members.delete(self.self.id) if channel.key? :members
135
+ channel = public_channels[data.channel]
136
+ channel&.members&.delete(self.self.id)
204
137
  end
205
138
 
206
139
  # Your channel read marker was updated.
@@ -208,23 +141,23 @@ module Slack
208
141
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_marked.json
209
142
  # on :channel_marked do |data|
210
143
 
211
- # A team channel was renamed.
144
+ # A channel was renamed.
212
145
  # @see https://api.slack.com/events/channel_rename
213
146
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_rename.json
214
147
  on :channel_rename do |data|
215
- channel = channels[data.channel.id]
216
- channel.name = data.channel.name if channel
148
+ channel = public_channels[data.channel.id]
149
+ channel&.merge!(data.channel)
217
150
  end
218
151
 
219
- # A team channel was unarchived.
152
+ # A channel was unarchived.
220
153
  # @see https://api.slack.com/events/channel_unarchive
221
154
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/channel_unarchive.json
222
155
  on :channel_unarchive do |data|
223
- channel = channels[data.channel]
156
+ channel = public_channels[data.channel]
224
157
  channel.is_archived = false if channel
225
158
  end
226
159
 
227
- # A team slash command has been added or changed.
160
+ # A slash command has been added or changed.
228
161
  # @see https://api.slack.com/events/commands_changed
229
162
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/commands_changed.json
230
163
  # on :commands_changed do |data|
@@ -232,25 +165,40 @@ module Slack
232
165
  # Do not Disturb settings changed for the current user.
233
166
  # @see https://api.slack.com/events/dnd_updated
234
167
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/dnd_updated.json
235
- # on :dnd_updated do |data|
168
+ on :dnd_updated do |data|
169
+ self.dnd_status = data.dnd_status
170
+ end
236
171
 
237
- # Do not Disturb settings changed for a team member.
172
+ # Do not Disturb settings changed for a member.
238
173
  # @see https://api.slack.com/events/dnd_updated_user
239
174
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/dnd_updated_user.json
240
- # on :dnd_updated_user do |data|
175
+ on :dnd_updated_user do |data|
176
+ user = users[data.user]
177
+ user.dnd_status = data.dnd_status if user
178
+ end
241
179
 
242
- # The team email domain has changed.
180
+ # The workspace email domain has changed.
243
181
  # @see https://api.slack.com/events/email_domain_changed
244
182
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/email_domain_changed.json
245
183
  on :email_domain_changed do |data|
246
184
  team.email_domain = data.email_domain
247
185
  end
248
186
 
249
- # A team custom emoji has been added or changed.
187
+ # A custom emoji has been added or changed.
250
188
  # @see https://api.slack.com/events/emoji_changed
251
189
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/emoji_changed.json
252
190
  # on :emoji_changed do |data|
253
191
 
192
+ # An enterprise grid migration has finished on an external workspace..
193
+ # @see https://api.slack.com/events/external_org_migration_finished
194
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/external_org_migration_finished.json
195
+ # on :external_org_migration_finished do |data|
196
+
197
+ # An enterprise grid migration has started on an external workspace..
198
+ # @see https://api.slack.com/events/external_org_migration_started
199
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/external_org_migration_started.json
200
+ # on :external_org_migration_started do |data|
201
+
254
202
  # A file was changed.
255
203
  # @see https://api.slack.com/events/file_change
256
204
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_change.json
@@ -259,7 +207,7 @@ module Slack
259
207
  # A file comment was added.
260
208
  # @see https://api.slack.com/events/file_comment_added
261
209
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_comment_added.json
262
- # on :file_comment_added do |data| do
210
+ # on :file_comment_added do |data|
263
211
 
264
212
  # A file comment was deleted.
265
213
  # @see https://api.slack.com/events/file_comment_deleted
@@ -281,11 +229,6 @@ module Slack
281
229
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_deleted.json
282
230
  # on :file_deleted do |data|
283
231
 
284
- # A file was made private.
285
- # @see https://api.slack.com/events/file_private
286
- # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_private.json
287
- # on :file_private do |data|
288
-
289
232
  # A file was made public.
290
233
  # @see https://api.slack.com/events/file_public
291
234
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_public.json
@@ -301,85 +244,157 @@ module Slack
301
244
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/file_unshared.json
302
245
  # on :file_unshared do |data|
303
246
 
304
- # A private group was archived.
247
+ # The server intends to close the connection soon..
248
+ # @see https://api.slack.com/events/goodbye
249
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/goodbye.json
250
+ # on :goodbye do |data|
251
+
252
+ # A private channel was archived.
305
253
  # @see https://api.slack.com/events/group_archive
306
254
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_archive.json
307
255
  on :group_archive do |data|
308
- channel = groups[data.channel]
256
+ channel = private_channels[data.channel]
309
257
  channel.is_archived = true if channel
310
258
  end
311
259
 
312
- # You closed a group channel.
260
+ # You closed a private channel.
313
261
  # @see https://api.slack.com/events/group_close
314
262
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_close.json
315
263
  on :group_close do |data|
316
- groups[data.channel].is_open = false
264
+ channel = private_channels[data.channel]
265
+ channel.is_open = false if channel
266
+ end
267
+
268
+ # A private channel was deleted.
269
+ # @see https://api.slack.com/events/group_deleted
270
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_deleted.json
271
+ on :group_deleted do |data|
272
+ private_channels.delete(data.channel)
317
273
  end
318
274
 
319
- # Bulk updates were made to a group's history.
275
+ # Bulk updates were made to a private channel's history.
320
276
  # @see https://api.slack.com/events/group_history_changed
321
277
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_history_changed.json
322
278
  # on :group_history_changed do |data|
323
279
 
324
- # You joined a private group.
280
+ # You joined a private channel.
325
281
  # @see https://api.slack.com/events/group_joined
326
282
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_joined.json
327
283
  on :group_joined do |data|
328
- groups[data.channel.id] = Models::Channel.new(data.channel)
284
+ channel = Models::Channel.new(data.channel)
285
+ private_channels[channel.id] = channel
329
286
  end
330
287
 
331
- # You left a private group.
288
+ # You left a private channel.
332
289
  # @see https://api.slack.com/events/group_left
333
290
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_left.json
334
291
  on :group_left do |data|
335
- channel = groups[data.channel]
336
- channel.members.delete(self.self.id) if channel && channel.key?(:members)
292
+ # Deleting because we can't access a private channel when we're not a member
293
+ private_channels.delete(data.channel)
337
294
  end
338
295
 
339
- # A private group read marker was updated.
296
+ # A private channel read marker was updated.
340
297
  # @see https://api.slack.com/events/group_marked
341
298
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_marked.json
342
299
  # on :group_marked do |data|
343
300
 
344
- # You opened a group channel.
301
+ # You created a group DM.
345
302
  # @see https://api.slack.com/events/group_open
346
303
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_open.json
347
304
  on :group_open do |data|
348
- groups[data.channel].is_open = true
305
+ channel = private_channels[data.channel]
306
+ channel.is_open = true if channel
349
307
  end
350
308
 
351
- # A private group was renamed.
309
+ # A private channel was renamed.
352
310
  # @see https://api.slack.com/events/group_rename
353
311
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_rename.json
354
312
  on :group_rename do |data|
355
- channel = groups[data.channel.id]
356
- channel.name = data.channel.name if channel
313
+ channel = private_channels[data.channel.id]
314
+ channel&.merge!(data.channel)
357
315
  end
358
316
 
359
- # A private group was unarchived.
317
+ # A private channel was unarchived.
360
318
  # @see https://api.slack.com/events/group_unarchive
361
319
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/group_unarchive.json
362
320
  on :group_unarchive do |data|
363
- channel = groups[data.channel]
321
+ channel = private_channels[data.channel]
364
322
  channel.is_archived = false if channel
365
323
  end
366
324
 
367
- # You closed a direct message channel.
325
+ # The client has successfully connected to the server.
326
+ # @see https://api.slack.com/events/hello
327
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/hello.json
328
+ on :hello do |_data, client|
329
+ # rubocop:disable Metrics/BlockNesting
330
+ if caches.include?(:teams)
331
+ team_info = client.web_client.team_info
332
+ team = Models::Team.new(team_info.team)
333
+ teams[team.id] = teams.key?(team.id) ? teams[team.id].merge(team) : team
334
+ end
335
+
336
+ if caches.include?(:users) || caches.include?(:bots)
337
+ client.web_client.users_list do |users_list|
338
+ users_list.members.each do |user_data|
339
+ if caches.include?(:users)
340
+ user = Models::User.new(user_data)
341
+ users[user.id] = users.key?(user.id) ? users[user.id].merge(user) : user
342
+ end
343
+
344
+ next unless user_data.is_bot? && caches.include?(:bots)
345
+
346
+ bot_info = client.web_client.bots_info(bot: user_data.profile.bot_id)
347
+ bot = Models::Bot.new(bot_info.bot)
348
+ bots[bot.id] = bots.key?(bot.id) ? bots[bot.id].merge(bot) : bot
349
+ end
350
+ end
351
+ end
352
+
353
+ if caches.include?(:public_channels) || caches.include?(:private_channels) ||
354
+ caches.include?(:ims) || caches.include?(:mpims)
355
+ types = CONVERSATION_TYPES.slice(*caches).values.join(',')
356
+ client.web_client.conversations_list(types: types) do |conversations|
357
+ conversations.channels.each do |channel_data|
358
+ if channel_data.is_mpim?
359
+ mpim = Models::Mpim.new(channel_data)
360
+ mpims[mpim.id] = mpims.key?(mpim.id) ? mpims[mpim.id].merge(mpim) : mpim
361
+ elsif channel_data.is_im?
362
+ im = Models::Im.new(channel_data)
363
+ ims[im.id] = ims.key?(im.id) ? ims[im.id].merge(im) : im
364
+ elsif channel_data.is_channel? || channel_data.is_group?
365
+ channel = Models::Channel.new(channel_data)
366
+ if channel.is_private?
367
+ private_channels[channel.id] =
368
+ private_channels.key?(channel.id) ? private_channels[channel.id].merge(channel) : channel
369
+ else
370
+ public_channels[channel.id] =
371
+ public_channels.key?(channel.id) ? public_channels[channel.id].merge(channel) : channel
372
+ end
373
+ end
374
+ end
375
+ end
376
+ end
377
+ # rubocop:enable Metrics/BlockNesting
378
+ end
379
+
380
+ # You closed a DM.
368
381
  # @see https://api.slack.com/events/im_close
369
382
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_close.json
370
383
  on :im_close do |data|
371
- return unless ims && ims.key?(data.channel)
384
+ return unless ims&.key?(data.channel)
385
+
372
386
  ims[data.channel].is_open = false
373
387
  end
374
388
 
375
- # A direct message channel was created.
389
+ # A DM was created.
376
390
  # @see https://api.slack.com/events/im_created
377
391
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_created.json
378
392
  on :im_created do |data|
379
- ims[data.channel.id] = Models::Im.new(data.channel)
393
+ im = Models::Im.new(data.channel)
394
+ ims[im.id] = im
380
395
  end
381
396
 
382
- # Bulk updates were made to a DM channel's history.
397
+ # Bulk updates were made to a DM's history.
383
398
  # @see https://api.slack.com/events/im_history_changed
384
399
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_history_changed.json
385
400
  # on :im_history_changed do |data|
@@ -389,11 +404,12 @@ module Slack
389
404
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_marked.json
390
405
  # on :im_marked do |data|
391
406
 
392
- # You opened a direct message channel.
407
+ # You opened a DM.
393
408
  # @see https://api.slack.com/events/im_open
394
409
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/im_open.json
395
410
  on :im_open do |data|
396
- return unless ims && ims.key?(data.channel)
411
+ return unless ims&.key?(data.channel)
412
+
397
413
  ims[data.channel].is_open = true
398
414
  end
399
415
 
@@ -404,6 +420,25 @@ module Slack
404
420
  self.self.presence = data.presence
405
421
  end
406
422
 
423
+ # A user joined a public channel, private channel or MPDM..
424
+ # @see https://api.slack.com/events/member_joined_channel
425
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/member_joined_channel.json
426
+ on :member_joined_channel do |data|
427
+ channel = public_channels[data.channel] || private_channels[data.channel]
428
+ if channel
429
+ channel.members ||= Set.new
430
+ channel.members << data.user
431
+ end
432
+ end
433
+
434
+ # A user left a public or private channel.
435
+ # @see https://api.slack.com/events/member_left_channel
436
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/member_left_channel.json
437
+ on :member_left_channel do |data|
438
+ channel = public_channels[data.channel] || private_channels[data.channel]
439
+ channel&.members&.delete(data.user)
440
+ end
441
+
407
442
  # A pin was added to a channel.
408
443
  # @see https://api.slack.com/events/pin_added
409
444
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/pin_added.json
@@ -422,7 +457,7 @@ module Slack
422
457
  self.self.prefs[data.name] = data.value
423
458
  end
424
459
 
425
- # A team member's presence changed.
460
+ # A member's presence changed.
426
461
  # @see https://api.slack.com/events/presence_change
427
462
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/presence_change.json
428
463
  on :presence_change do |data|
@@ -430,12 +465,22 @@ module Slack
430
465
  user.presence = data.presence if user
431
466
  end
432
467
 
433
- # A team member has added an emoji reaction to an item.
468
+ # Determine the current presence status for a list of users.
469
+ # @see https://api.slack.com/events/presence_query
470
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/presence_query.json
471
+ # on :presence_query do |data|
472
+
473
+ # Subscribe to presence events for the specified users.
474
+ # @see https://api.slack.com/events/presence_sub
475
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/presence_sub.json
476
+ # on :presence_sub do |data|
477
+
478
+ # A member has added an emoji reaction to an item.
434
479
  # @see https://api.slack.com/events/reaction_added
435
480
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/reaction_added.json
436
481
  # on :reaction_added do |data|
437
482
 
438
- # A team member removed an emoji reaction.
483
+ # A member removed an emoji reaction.
439
484
  # @see https://api.slack.com/events/reaction_removed
440
485
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/reaction_removed.json
441
486
  # on :reaction_removed do |data|
@@ -445,37 +490,47 @@ module Slack
445
490
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/reconnect_url.json
446
491
  # on :reconnect_url do |data|
447
492
 
448
- # A team member has starred an item.
493
+ # A shared channel invite was sent to a Slack user.
494
+ # @see https://api.slack.com/events/shared_channel_invite_received
495
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/shared_channel_invite_received.json
496
+ # on :shared_channel_invite_received do |data|
497
+
498
+ # A member has starred an item.
449
499
  # @see https://api.slack.com/events/star_added
450
500
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/star_added.json
451
501
  # on :star_added do |data|
452
502
 
453
- # A team member removed a star.
503
+ # A member removed a star.
454
504
  # @see https://api.slack.com/events/star_removed
455
505
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/star_removed.json
456
506
  # on :star_removed do |data|
457
507
 
458
- # A user group has been added to the team.
508
+ # A User Group has been added to the workspace.
459
509
  # @see https://api.slack.com/events/subteam_created
460
510
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_created.json
461
511
  # on :subteam_created do |data|
462
512
 
463
- # You have been added to a user group.
513
+ # The membership of an existing User Group has changed.
514
+ # @see https://api.slack.com/events/subteam_members_changed
515
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_members_changed.json
516
+ # on :subteam_members_changed do |data|
517
+
518
+ # You have been added to a User Group.
464
519
  # @see https://api.slack.com/events/subteam_self_added
465
520
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_self_added.json
466
521
  # on :subteam_self_added do |data|
467
522
 
468
- # You have been removed from a user group.
523
+ # You have been removed from a User Group.
469
524
  # @see https://api.slack.com/events/subteam_self_removed
470
525
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_self_removed.json
471
526
  # on :subteam_self_removed do |data|
472
527
 
473
- # An existing user group has been updated or its members changed.
528
+ # An existing User Group has been updated or its members changed.
474
529
  # @see https://api.slack.com/events/subteam_updated
475
530
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/subteam_updated.json
476
531
  # on :subteam_updated do |data|
477
532
 
478
- # The team domain has changed.
533
+ # The workspace domain has changed.
479
534
  # @see https://api.slack.com/events/team_domain_change
480
535
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_domain_change.json
481
536
  on :team_domain_change do |data|
@@ -483,26 +538,27 @@ module Slack
483
538
  team.domain = data.domain
484
539
  end
485
540
 
486
- # A new team member has joined.
541
+ # A new member has joined.
487
542
  # @see https://api.slack.com/events/team_join
488
543
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_join.json
489
544
  on :team_join do |data|
490
- users[data.user.id] = Models::User.new(data.user)
545
+ user = Models::User.new(data.user)
546
+ users[user.id] = user
491
547
  end
492
548
 
493
- # The team is being migrated between servers.
549
+ # The workspace is being migrated between servers.
494
550
  # @see https://api.slack.com/events/team_migration_started
495
551
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_migration_started.json
496
552
  # on :team_migration_started do |data|
497
553
 
498
- # The team billing plan has changed.
554
+ # The account billing plan has changed.
499
555
  # @see https://api.slack.com/events/team_plan_change
500
556
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_plan_change.json
501
557
  on :team_plan_change do |data|
502
558
  team.plan = data.plan
503
559
  end
504
560
 
505
- # A team preference has been updated.
561
+ # A preference has been updated.
506
562
  # @see https://api.slack.com/events/team_pref_change
507
563
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_pref_change.json
508
564
  on :team_pref_change do |data|
@@ -510,34 +566,53 @@ module Slack
510
566
  team.prefs[data.name] = data.value
511
567
  end
512
568
 
513
- # Team profile fields have been updated.
569
+ # The workspace profile fields have been updated.
514
570
  # @see https://api.slack.com/events/team_profile_change
515
571
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_profile_change.json
516
572
  # on :team_profile_change do |data|
517
573
 
518
- # Team profile fields have been deleted.
574
+ # The workspace profile fields have been deleted.
519
575
  # @see https://api.slack.com/events/team_profile_delete
520
576
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_profile_delete.json
521
577
  # on :team_profile_delete do |data|
522
578
 
523
- # Team profile fields have been reordered.
579
+ # The workspace profile fields have been reordered.
524
580
  # @see https://api.slack.com/events/team_profile_reorder
525
581
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_profile_reorder.json
526
582
  # on :team_profile_reorder do |data|
527
583
 
528
- # The team name has changed.
584
+ # The workspace name has changed.
529
585
  # @see https://api.slack.com/events/team_rename
530
586
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/team_rename.json
531
587
  on :team_rename do |data|
532
588
  team.name = data.name
533
589
  end
534
590
 
535
- # A team member's data has changed.
591
+ # A member's data has changed.
536
592
  # @see https://api.slack.com/events/user_change
537
593
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/user_change.json
538
594
  on :user_change do |data|
539
- users[data.user.id] = Models::User.new(data.user)
540
- end
595
+ user = Models::User.new(data.user)
596
+ users[user.id] = user
597
+ end
598
+
599
+ # A user's huddle status has changed.
600
+ # @see https://api.slack.com/events/user_huddle_changed
601
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/user_huddle_changed.json
602
+ # on :user_huddle_changed do |data|
603
+ # (handled by :user_change)
604
+
605
+ # A user's profile data has changed.
606
+ # @see https://api.slack.com/events/user_profile_changed
607
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/user_profile_changed.json
608
+ # on :user_profile_changed do |data|
609
+ # (handled by :user_change)
610
+
611
+ # A user's status has changed.
612
+ # @see https://api.slack.com/events/user_status_changed
613
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/events/user_status_changed.json
614
+ # on :user_status_changed do |data|
615
+ # (handled by :user_change)
541
616
 
542
617
  # A channel member is typing a message.
543
618
  # @see https://api.slack.com/events/user_typing