slack-ruby-client 0.12.0 → 0.14.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +21 -9
  4. data/.rubocop_todo.yml +64 -56
  5. data/.travis.yml +5 -3
  6. data/CHANGELOG.md +90 -32
  7. data/Dangerfile +2 -0
  8. data/Gemfile +10 -4
  9. data/LICENSE.md +1 -1
  10. data/README.md +176 -32
  11. data/Rakefile +2 -1
  12. data/UPGRADING.md +27 -1
  13. data/bin/commands.rb +21 -0
  14. data/bin/commands/admin_apps.rb +27 -0
  15. data/bin/commands/admin_apps_approved.rb +17 -0
  16. data/bin/commands/admin_apps_requests.rb +16 -0
  17. data/bin/commands/admin_apps_restricted.rb +17 -0
  18. data/bin/commands/admin_conversations.rb +17 -0
  19. data/bin/commands/admin_emoji.rb +54 -0
  20. data/bin/commands/admin_inviteRequests.rb +36 -0
  21. data/bin/commands/admin_inviteRequests_approved.rb +16 -0
  22. data/bin/commands/admin_inviteRequests_denied.rb +16 -0
  23. data/bin/commands/admin_teams.rb +27 -0
  24. data/bin/commands/admin_teams_admins.rb +16 -0
  25. data/bin/commands/admin_teams_owners.rb +16 -0
  26. data/bin/commands/admin_teams_settings.rb +64 -0
  27. data/bin/commands/admin_users.rb +97 -0
  28. data/bin/commands/admin_users_session.rb +16 -0
  29. data/bin/commands/api.rb +1 -0
  30. data/bin/commands/apps.rb +15 -0
  31. data/bin/commands/apps_permissions.rb +1 -0
  32. data/bin/commands/apps_permissions_resources.rb +1 -0
  33. data/bin/commands/apps_permissions_scopes.rb +1 -0
  34. data/bin/commands/apps_permissions_users.rb +1 -0
  35. data/bin/commands/auth.rb +1 -0
  36. data/bin/commands/bots.rb +1 -0
  37. data/bin/commands/channels.rb +3 -1
  38. data/bin/commands/chat.rb +48 -9
  39. data/bin/commands/chat_scheduledMessages.rb +18 -0
  40. data/bin/commands/conversations.rb +4 -2
  41. data/bin/commands/dialog.rb +1 -0
  42. data/bin/commands/dnd.rb +4 -3
  43. data/bin/commands/emoji.rb +1 -0
  44. data/bin/commands/files.rb +4 -14
  45. data/bin/commands/files_comments.rb +1 -21
  46. data/bin/commands/files_remote.rb +78 -0
  47. data/bin/commands/groups.rb +2 -1
  48. data/bin/commands/im.rb +2 -1
  49. data/bin/commands/migration.rb +1 -0
  50. data/bin/commands/mpim.rb +2 -1
  51. data/bin/commands/oauth.rb +2 -1
  52. data/bin/commands/oauth_v2.rb +17 -0
  53. data/bin/commands/pins.rb +1 -2
  54. data/bin/commands/reactions.rb +2 -3
  55. data/bin/commands/reminders.rb +1 -0
  56. data/bin/commands/rtm.rb +1 -0
  57. data/bin/commands/search.rb +2 -1
  58. data/bin/commands/stars.rb +1 -0
  59. data/bin/commands/team.rb +2 -0
  60. data/bin/commands/team_profile.rb +1 -0
  61. data/bin/commands/usergroups.rb +2 -1
  62. data/bin/commands/usergroups_users.rb +1 -0
  63. data/bin/commands/users.rb +2 -2
  64. data/bin/commands/users_admin.rb +1 -0
  65. data/bin/commands/users_prefs.rb +1 -0
  66. data/bin/commands/users_profile.rb +1 -0
  67. data/bin/commands/views.rb +48 -0
  68. data/bin/slack +2 -3
  69. data/examples/hi_real_time/Gemfile +1 -0
  70. data/examples/hi_real_time/hi.rb +7 -3
  71. data/examples/hi_real_time_and_web/Gemfile +1 -0
  72. data/examples/hi_real_time_and_web/hi.rb +7 -3
  73. data/examples/hi_real_time_async_async/Gemfile +7 -0
  74. data/examples/hi_real_time_async_async/Procfile +2 -0
  75. data/examples/hi_real_time_async_async/hi.rb +41 -0
  76. data/examples/hi_real_time_async_celluloid/Gemfile +1 -0
  77. data/examples/hi_real_time_async_celluloid/hi.rb +7 -3
  78. data/examples/hi_real_time_async_eventmachine/Gemfile +1 -0
  79. data/examples/hi_real_time_async_eventmachine/hi.rb +7 -3
  80. data/examples/hi_web/Gemfile +1 -0
  81. data/examples/hi_web/hi.rb +1 -0
  82. data/examples/new_ticket/Gemfile +1 -0
  83. data/examples/new_ticket/new_ticket.rb +1 -0
  84. data/lib/slack-ruby-client.rb +8 -2
  85. data/lib/slack.rb +1 -0
  86. data/lib/slack/config.rb +1 -0
  87. data/lib/slack/events/config.rb +32 -0
  88. data/lib/slack/events/request.rb +66 -0
  89. data/lib/slack/logger.rb +6 -5
  90. data/lib/slack/messages/formatting.rb +1 -0
  91. data/lib/slack/messages/message.rb +1 -0
  92. data/lib/slack/real_time/api/message.rb +3 -1
  93. data/lib/slack/real_time/api/message_id.rb +1 -0
  94. data/lib/slack/real_time/api/ping.rb +5 -2
  95. data/lib/slack/real_time/api/typing.rb +3 -1
  96. data/lib/slack/real_time/client.rb +97 -28
  97. data/lib/slack/real_time/concurrency.rb +2 -0
  98. data/lib/slack/real_time/concurrency/async.rb +142 -0
  99. data/lib/slack/real_time/concurrency/celluloid.rb +33 -9
  100. data/lib/slack/real_time/concurrency/eventmachine.rb +32 -7
  101. data/lib/slack/real_time/config.rb +7 -2
  102. data/lib/slack/real_time/models.rb +1 -0
  103. data/lib/slack/real_time/models/base.rb +1 -0
  104. data/lib/slack/real_time/models/bot.rb +1 -0
  105. data/lib/slack/real_time/models/channel.rb +1 -0
  106. data/lib/slack/real_time/models/group.rb +1 -0
  107. data/lib/slack/real_time/models/im.rb +1 -0
  108. data/lib/slack/real_time/models/team.rb +1 -0
  109. data/lib/slack/real_time/models/user.rb +1 -0
  110. data/lib/slack/real_time/socket.rb +42 -13
  111. data/lib/slack/real_time/stores.rb +1 -0
  112. data/lib/slack/real_time/stores/base.rb +1 -0
  113. data/lib/slack/real_time/stores/starter.rb +11 -0
  114. data/lib/slack/real_time/stores/store.rb +28 -25
  115. data/lib/slack/version.rb +2 -1
  116. data/lib/slack/web/api/endpoints.rb +41 -0
  117. data/lib/slack/web/api/endpoints/admin_apps.rb +42 -0
  118. data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
  119. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +33 -0
  120. data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
  121. data/lib/slack/web/api/endpoints/admin_conversations.rb +30 -0
  122. data/lib/slack/web/api/endpoints/admin_emoji.rb +88 -0
  123. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +61 -0
  124. data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +33 -0
  125. data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +33 -0
  126. data/lib/slack/web/api/endpoints/admin_teams.rb +50 -0
  127. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +34 -0
  128. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +34 -0
  129. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +99 -0
  130. data/lib/slack/web/api/endpoints/admin_users.rb +163 -0
  131. data/lib/slack/web/api/endpoints/admin_users_session.rb +28 -0
  132. data/lib/slack/web/api/endpoints/api.rb +1 -0
  133. data/lib/slack/web/api/endpoints/apps.rb +27 -0
  134. data/lib/slack/web/api/endpoints/apps_permissions.rb +1 -0
  135. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +1 -0
  136. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +1 -0
  137. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +1 -0
  138. data/lib/slack/web/api/endpoints/auth.rb +1 -0
  139. data/lib/slack/web/api/endpoints/bots.rb +1 -0
  140. data/lib/slack/web/api/endpoints/channels.rb +3 -0
  141. data/lib/slack/web/api/endpoints/chat.rb +99 -12
  142. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +38 -0
  143. data/lib/slack/web/api/endpoints/conversations.rb +4 -1
  144. data/lib/slack/web/api/endpoints/dialog.rb +1 -0
  145. data/lib/slack/web/api/endpoints/dnd.rb +3 -1
  146. data/lib/slack/web/api/endpoints/emoji.rb +1 -0
  147. data/lib/slack/web/api/endpoints/files.rb +4 -13
  148. data/lib/slack/web/api/endpoints/files_comments.rb +1 -33
  149. data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
  150. data/lib/slack/web/api/endpoints/groups.rb +1 -0
  151. data/lib/slack/web/api/endpoints/im.rb +1 -0
  152. data/lib/slack/web/api/endpoints/migration.rb +1 -0
  153. data/lib/slack/web/api/endpoints/mpim.rb +1 -0
  154. data/lib/slack/web/api/endpoints/oauth.rb +2 -1
  155. data/lib/slack/web/api/endpoints/oauth_v2.rb +30 -0
  156. data/lib/slack/web/api/endpoints/pins.rb +2 -4
  157. data/lib/slack/web/api/endpoints/reactions.rb +5 -6
  158. data/lib/slack/web/api/endpoints/reminders.rb +1 -0
  159. data/lib/slack/web/api/endpoints/rtm.rb +1 -0
  160. data/lib/slack/web/api/endpoints/search.rb +1 -0
  161. data/lib/slack/web/api/endpoints/stars.rb +1 -0
  162. data/lib/slack/web/api/endpoints/team.rb +3 -0
  163. data/lib/slack/web/api/endpoints/team_profile.rb +1 -0
  164. data/lib/slack/web/api/endpoints/usergroups.rb +1 -0
  165. data/lib/slack/web/api/endpoints/usergroups_users.rb +1 -0
  166. data/lib/slack/web/api/endpoints/users.rb +1 -2
  167. data/lib/slack/web/api/endpoints/users_admin.rb +1 -0
  168. data/lib/slack/web/api/endpoints/users_prefs.rb +1 -0
  169. data/lib/slack/web/api/endpoints/users_profile.rb +1 -0
  170. data/lib/slack/web/api/endpoints/views.rb +97 -0
  171. data/lib/slack/web/api/error.rb +1 -0
  172. data/lib/slack/web/api/errors.rb +566 -0
  173. data/lib/slack/web/api/errors/slack_error.rb +14 -1
  174. data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -0
  175. data/lib/slack/web/api/mixins.rb +1 -0
  176. data/lib/slack/web/api/mixins/channels.id.rb +1 -0
  177. data/lib/slack/web/api/mixins/groups.id.rb +1 -0
  178. data/lib/slack/web/api/mixins/ids.id.rb +4 -1
  179. data/lib/slack/web/api/mixins/users.id.rb +1 -0
  180. data/lib/slack/web/api/mixins/users.search.rb +1 -0
  181. data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +5 -3
  182. data/lib/slack/web/api/patches/chat.6.block-kit-support.patch +69 -0
  183. data/lib/slack/web/api/patches/views.1.view-json.patch +40 -0
  184. data/lib/slack/web/api/patches/views.1.views-published.patch +16 -0
  185. data/lib/slack/web/api/templates/command.erb +1 -0
  186. data/lib/slack/web/api/templates/commands.erb +1 -0
  187. data/lib/slack/web/api/templates/endpoints.erb +1 -0
  188. data/lib/slack/web/api/templates/errors.erb +20 -0
  189. data/lib/slack/web/api/templates/method.erb +1 -0
  190. data/lib/slack/web/api/templates/method_spec.erb +1 -0
  191. data/lib/slack/web/client.rb +2 -1
  192. data/lib/slack/web/config.rb +1 -0
  193. data/lib/slack/web/faraday/connection.rb +1 -0
  194. data/lib/slack/web/faraday/request.rb +1 -0
  195. data/lib/slack/web/faraday/response/raise_error.rb +10 -6
  196. data/lib/slack/web/pagination/cursor.rb +4 -0
  197. data/lib/slack_ruby_client.rb +1 -0
  198. data/lib/tasks/git.rake +1 -0
  199. data/lib/tasks/real_time.rake +15 -5
  200. data/lib/tasks/update.rake +1 -0
  201. data/lib/tasks/web.rake +28 -7
  202. data/screenshots/create-app.png +0 -0
  203. data/slack-ruby-client.gemspec +6 -2
  204. data/spec/fixtures/slack/web/views_open_error.yml +76 -0
  205. data/spec/integration/integration_spec.rb +116 -48
  206. data/spec/slack/config_spec.rb +2 -0
  207. data/spec/slack/events/config_spec.rb +33 -0
  208. data/spec/slack/events/request_spec.rb +179 -0
  209. data/spec/slack/messages/formatting_spec.rb +25 -13
  210. data/spec/slack/real_time/api/message_spec.rb +6 -1
  211. data/spec/slack/real_time/api/ping_spec.rb +2 -0
  212. data/spec/slack/real_time/api/typing_spec.rb +5 -1
  213. data/spec/slack/real_time/client_spec.rb +212 -31
  214. data/spec/slack/real_time/concurrency/celluloid_spec.rb +15 -5
  215. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +11 -1
  216. data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +2 -0
  217. data/spec/slack/real_time/event_handlers/bot_spec.rb +2 -1
  218. data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -6
  219. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +2 -1
  220. data/spec/slack/real_time/event_handlers/group_spec.rb +5 -4
  221. data/spec/slack/real_time/event_handlers/im_spec.rb +4 -3
  222. data/spec/slack/real_time/event_handlers/team_spec.rb +3 -1
  223. data/spec/slack/real_time/event_handlers/user_spec.rb +1 -0
  224. data/spec/slack/real_time/rtm_connect_spec.rb +1 -0
  225. data/spec/slack/real_time/rtm_start_spec.rb +1 -0
  226. data/spec/slack/real_time/store_spec.rb +2 -1
  227. data/spec/slack/slack_spec.rb +37 -5
  228. data/spec/slack/version_spec.rb +2 -1
  229. data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +8 -0
  230. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
  231. data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
  232. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +8 -0
  233. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +13 -0
  234. data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +37 -0
  235. data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +8 -0
  236. data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +8 -0
  237. data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +18 -0
  238. data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +13 -0
  239. data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +13 -0
  240. data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +53 -0
  241. data/spec/slack/web/api/endpoints/admin_teams_spec.rb +16 -0
  242. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +13 -0
  243. data/spec/slack/web/api/endpoints/admin_users_spec.rb +75 -0
  244. data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
  245. data/spec/slack/web/api/endpoints/apps_permissions_resources_spec.rb +1 -0
  246. data/spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb +1 -0
  247. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +3 -2
  248. data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +4 -3
  249. data/spec/slack/web/api/endpoints/apps_spec.rb +16 -0
  250. data/spec/slack/web/api/endpoints/bots_spec.rb +1 -0
  251. data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +8 -0
  252. data/spec/slack/web/api/endpoints/conversations_spec.rb +2 -1
  253. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +5 -1
  254. data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +2 -0
  255. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +112 -36
  256. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +12 -4
  257. data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +2 -0
  258. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +6 -1
  259. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +95 -0
  260. data/spec/slack/web/api/endpoints/dnd_spec.rb +6 -0
  261. data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
  262. data/spec/slack/web/api/endpoints/files_comments_spec.rb +1 -19
  263. data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
  264. data/spec/slack/web/api/endpoints/files_spec.rb +1 -0
  265. data/spec/slack/web/api/endpoints/im_spec.rb +1 -0
  266. data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
  267. data/spec/slack/web/api/endpoints/mpim_spec.rb +1 -0
  268. data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -0
  269. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +13 -0
  270. data/spec/slack/web/api/endpoints/pins_spec.rb +5 -1
  271. data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
  272. data/spec/slack/web/api/endpoints/reminders_spec.rb +1 -0
  273. data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
  274. data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
  275. data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
  276. data/spec/slack/web/api/endpoints/team_profile_spec.rb +1 -0
  277. data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
  278. data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
  279. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +1 -0
  280. data/spec/slack/web/api/endpoints/users_admin_spec.rb +1 -0
  281. data/spec/slack/web/api/endpoints/users_prefs_spec.rb +1 -0
  282. data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
  283. data/spec/slack/web/api/endpoints/views_spec.rb +29 -0
  284. data/spec/slack/web/api/error_spec.rb +4 -2
  285. data/spec/slack/web/api/errors/service_unavailable_spec.rb +6 -3
  286. data/spec/slack/web/api/errors/slack_error_spec.rb +26 -2
  287. data/spec/slack/web/api/mixins/channels_spec.rb +17 -7
  288. data/spec/slack/web/api/mixins/groups_spec.rb +17 -7
  289. data/spec/slack/web/api/mixins/users_spec.rb +17 -8
  290. data/spec/slack/web/api/pagination/cursor_spec.rb +40 -10
  291. data/spec/slack/web/client_spec.rb +45 -18
  292. data/spec/slack/web/faraday/response/raise_error_spec.rb +41 -7
  293. data/spec/spec_helper.rb +8 -1
  294. data/spec/support/queue_with_timeout.rb +5 -4
  295. data/spec/support/real_time/concurrency/mock.rb +1 -0
  296. data/spec/support/real_time/connected_client.rb +9 -3
  297. data/spec/support/real_time/event.rb +1 -0
  298. data/spec/support/token.rb +1 -0
  299. data/spec/support/vcr.rb +1 -0
  300. metadata +149 -9
  301. data/screenshots/register-bot.png +0 -0
data/Dangerfile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  danger.import_dangerfile(gem: 'slack-ruby-danger')
3
+ toc.check
data/Gemfile CHANGED
@@ -1,12 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  source 'http://rubygems.org'
2
3
 
3
4
  gemspec
4
5
 
5
- gem ENV['CONCURRENCY'], require: false if ENV.key?('CONCURRENCY')
6
-
7
- gem 'activesupport', '~> 4.0'
8
- gem 'picky' unless RUBY_PLATFORM == 'java'
6
+ if ENV.key?('CONCURRENCY')
7
+ case ENV['CONCURRENCY']
8
+ when 'async-websocket'
9
+ gem 'async-websocket', '~> 0.8.0', require: false
10
+ else
11
+ gem ENV['CONCURRENCY'], require: false
12
+ end
13
+ end
9
14
 
10
15
  group :test do
16
+ gem 'danger-toc', '~> 0.1.3', require: false
11
17
  gem 'slack-ruby-danger', '~> 0.1.0', require: false
12
18
  end
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2015-2016 Daniel Doubrovkine, Artsy and Contributors
3
+ Copyright (c) 2015-2019 Daniel Doubrovkine, Artsy and Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -5,20 +5,73 @@ Slack Ruby Client
5
5
  [![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-client.svg?branch=master)](https://travis-ci.org/slack-ruby/slack-ruby-client)
6
6
  [![Code Climate](https://codeclimate.com/github/slack-ruby/slack-ruby-client/badges/gpa.svg)](https://codeclimate.com/github/slack-ruby/slack-ruby-client)
7
7
 
8
- A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messaging](https://api.slack.com/rtm) APIs. Comes with a handy command-line client, too. If you are not familiar with these concepts, you might want to watch [this video](http://code.dblock.org/2016/03/11/your-first-slack-bot-service-video.html).
8
+ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messaging](https://api.slack.com/rtm) and [Events](https://api.slack.com/events-api) APIs. Comes with a handy command-line client, too. If you are not familiar with these concepts, you might want to watch [this video](http://code.dblock.org/2016/03/11/your-first-slack-bot-service-video.html).
9
9
 
10
10
  ![](slack.png)
11
11
 
12
+ ## Table of Contents
13
+
14
+ - [Useful to Me?](#useful-to-me)
15
+ - [Stable Release](#stable-release)
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [Create a New Bot Integration](#create-a-new-bot-integration)
19
+ - [OAuth Code Grant](#oauth-code-grant)
20
+ - [Using the Legacy API Token](#using-the-legacy-api-token)
21
+ - [Global Settings](#global-settings)
22
+ - [Web Client](#web-client)
23
+ - [Web Client Examples](#web-client-examples)
24
+ - [Test Auth](#test-auth)
25
+ - [Send Messages](#send-messages)
26
+ - [List Channels](#list-channels)
27
+ - [Upload a File](#upload-a-file)
28
+ - [Get Channel Info](#get-channel-info)
29
+ - [Get User Info](#get-user-info)
30
+ - [Search for a User](#search-for-a-user)
31
+ - [Other](#other)
32
+ - [Web Client Options](#web-client-options)
33
+ - [Pagination Support](#pagination-support)
34
+ - [Error Handling](#error-handling)
35
+ - [Slack Errors](#slack-errors)
36
+ - [Rate Limiting](#rate-limiting)
37
+ - [Other Errors](#other-errors)
38
+ - [RealTime Client](#realtime-client)
39
+ - [Slack::RealTime::Stores::Store](#slackrealtimestoresstore)
40
+ - [Slack::RealTime::Stores::Starter](#slackrealtimestoresstarter)
41
+ - [Configuring Slack::RealTime::Client](#configuring-slackrealtimeclient)
42
+ - [Caveats](#caveats)
43
+ - [websocket_ping](#websocket_ping)
44
+ - [Connection Methods](#connection-methods)
45
+ - [Combining RealTime and Web Clients](#combining-realtime-and-web-clients)
46
+ - [Large Team Considerations](#large-team-considerations)
47
+ - [Concurrency](#concurrency)
48
+ - [Async](#async)
49
+ - [Faye::Websocket with Eventmachine](#fayewebsocket-with-eventmachine)
50
+ - [Celluloid](#celluloid)
51
+ - [Events API](#events-api)
52
+ - [Configuring Slack::Events](#configuring-slackevents)
53
+ - [Verifying the Request Signature](#verifying-the-request-signature)
54
+ - [Message Parsing](#message-parsing)
55
+ - [Command-Line Client](#command-line-client)
56
+ - [Authenticate with Slack](#authenticate-with-slack)
57
+ - [Send a Message](#send-a-message)
58
+ - [Get Channel Id](#get-channel-id)
59
+ - [Get Channel Info](#get-channel-info-1)
60
+ - [List Users](#list-users)
61
+ - [History](#history)
62
+ - [Contributing](#contributing)
63
+ - [Copyright and License](#copyright-and-license)
64
+
12
65
  ## Useful to Me?
13
66
 
14
- * This piece of the puzzle will help you send messages to Slack via the Web API and send and receive messages via the Real Time API.
15
- * If you're trying to respond to slash commands, just write a basic web application and use this library to call the Slack Web API.
16
- * If you're trying to build a Real Time bot, use [slack-ruby-bot](https://github.com/dblock/slack-ruby-bot), which uses this library.
17
- * If you're trying to roll out a full service with Slack button integration to multiple teams, check out [slack-ruby-bot-server](https://github.com/dblock/slack-ruby-bot-server), which is built on top of slack-ruby-bot, which uses this library.
67
+ * This library will let you send messages to Slack via the Web API, send and receive messages via the Real Time Messaging API and facilitate integration with the Events API.
68
+ * To respond to slash commands, interactive components or events, implement a web application using your favorite web framework and use this library to call the Slack Web API and to verify that events are coming from Slack.
69
+ * To build a bot using the Real Time Messaging API, use [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot), which uses this library.
70
+ * To roll out a complete service using the Real Time Messaging API with Slack button integration to multiple teams, check out [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server), which is built on top of slack-ruby-bot, which uses this library.
18
71
 
19
72
  ## Stable Release
20
73
 
21
- You're reading the documentation for the **stable** release of slack-ruby-client, 0.12.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
74
+ You're reading the documentation for the **stable** release of slack-ruby-client, 0.14.6. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
75
 
23
76
  ## Installation
24
77
 
@@ -28,11 +81,10 @@ Add to Gemfile.
28
81
  gem 'slack-ruby-client'
29
82
  ```
30
83
 
31
- If you're going to be using the RealTime client, add either `eventmachine` and `faye-websocket` or `celluloid-io`. See below for more information about concurrency.
84
+ If you're going to be using the RealTime client, add either `async-websocket`, `eventmachine` and `faye-websocket` or `celluloid-io`. See below for more information about concurrency. We recommend you use `async-websocket`.
32
85
 
33
86
  ```
34
- gem 'eventmachine'
35
- gem 'faye-websocket'
87
+ gem 'async-websocket', '~> 0.8.0'
36
88
  ```
37
89
 
38
90
  Run `bundle install`.
@@ -41,11 +93,17 @@ Run `bundle install`.
41
93
 
42
94
  ### Create a New Bot Integration
43
95
 
44
- This is something done in Slack, under [integrations](https://my.slack.com/services). Create a [new bot](https://my.slack.com/services/new/bot), and note its API token.
96
+ To integrate your bot with Slack, you must first create a new [Slack App](https://api.slack.com/apps).
97
+
98
+ ![](screenshots/create-app.png)
99
+
100
+ ### OAuth Code Grant
45
101
 
46
- ![](screenshots/register-bot.png)
102
+ Once created, go to the app's Basic Info tab and grab the Client ID and Client Secret. You'll need these in order complete an [OAuth code grant flow](https://api.slack.com/docs/oauth#flow) as described at [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server).
47
103
 
48
- ### Use the API Token
104
+ ### Using the Legacy API Token
105
+
106
+ Although OAuth is recommended, you can still [generate a legacy API token](https://api.slack.com/custom-integrations/legacy-tokens) for your app and use it for some interactions.
49
107
 
50
108
  ```ruby
51
109
  Slack.configure do |config|
@@ -68,14 +126,18 @@ logger | An optional logger, defaults to `::Logger.new(STDOUT)` at `Logger
68
126
 
69
127
  The Slack Web API allows you to build applications that interact with Slack.
70
128
 
71
- #### Test Auth
129
+ #### Web Client Examples
130
+
131
+ Here are some examples of how to use the web client with the Web API.
132
+
133
+ ##### Test Auth
72
134
 
73
135
  ```ruby
74
136
  client = Slack::Web::Client.new
75
137
  client.auth_test
76
138
  ```
77
139
 
78
- #### Send Messages
140
+ ##### Send Messages
79
141
 
80
142
  Send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
81
143
 
@@ -87,7 +149,7 @@ See a fully working example in [examples/hi_web](examples/hi_web/hi.rb).
87
149
 
88
150
  ![](examples/hi_web/hi.gif)
89
151
 
90
- #### List Channels
152
+ ##### List Channels
91
153
 
92
154
  List channels with [channels_list](https://api.slack.com/methods/channels.list).
93
155
 
@@ -97,7 +159,7 @@ channels = client.channels_list.channels
97
159
  general_channel = channels.detect { |c| c.name == 'general' }
98
160
  ```
99
161
 
100
- #### Upload a File
162
+ ##### Upload a File
101
163
 
102
164
  Upload a file with [files_upload](https://api.slack.com/methods/files.upload).
103
165
 
@@ -112,7 +174,7 @@ client.files_upload(
112
174
  )
113
175
  ```
114
176
 
115
- ### Get Channel Info
177
+ ##### Get Channel Info
116
178
 
117
179
  You can use a channel ID or name (prefixed with `#`) in all functions that take a `:channel` argument. Lookup by name is not supported by the Slack API and the `channels_id` method called invokes `channels_list` in order to locate the channel ID.
118
180
 
@@ -124,7 +186,7 @@ client.channels_info(channel: 'C04KB5X4D') # calls channels_info
124
186
  client.channels_info(channel: '#general') # calls channels_list followed by channels_info
125
187
  ```
126
188
 
127
- ### Get User Info
189
+ ##### Get User Info
128
190
 
129
191
  You can use a user ID or name (prefixed with `@`) in all functions that take a `:user` argument. Lookup by name is not supported by the Slack API and the `users_id` method called invokes `users_list` in order to locate the user ID.
130
192
 
@@ -136,7 +198,7 @@ client.users_info(user: 'U092BDCLV') # calls users_info
136
198
  client.users_info(user: '@dblock') # calls users_list followed by users_info
137
199
  ```
138
200
 
139
- ### Search for a User
201
+ ##### Search for a User
140
202
 
141
203
  Constructs an in-memory index of users and searches it. If you want to use this functionality, add the [picky](https://github.com/floere/picky) gem to your project's Gemfile.
142
204
 
@@ -144,7 +206,7 @@ Constructs an in-memory index of users and searches it. If you want to use this
144
206
  client.users_search(user: 'dblock')
145
207
  ```
146
208
 
147
- #### Other
209
+ ##### Other
148
210
 
149
211
  Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.
150
212
 
@@ -216,9 +278,33 @@ all_members # many thousands of team members retrieved 10 at a time
216
278
 
217
279
  #### Error Handling
218
280
 
219
- If a request fails, a `Slack::Web::Api::Errors::SlackError` will be raised. The error message contains the error code. In case of multiple errors, the error codes are separated by commas. The original response is also accessible using the `response` attribute.
281
+ ##### Slack Errors
282
+
283
+ If Slack returns an error for the request, then an error will be raised. The error class is specific to the type of error that Slack returns. For instance if Slack returns `account_inactive` then the error will be `Slack::Web::Api::Errors::AccountInactive`. This allows you to handle certain types of errors as needed:
284
+
285
+ ```ruby
286
+ rescue Slack::Web::Api::Errors::AccountInactive => e
287
+ # deal with inactive account
288
+ end
289
+ ```
290
+
291
+ All of these errors inherit from `Slack::Web::Api::Errors::SlackError`, so you can handle or silence all errors if necessary:
220
292
 
221
- If you exceed [Slack’s rate limits](https://api.slack.com/docs/rate-limits), a `Slack::Web::Api::Errors::TooManyRequestsError` will be raised instead.
293
+ ```ruby
294
+ rescue Slack::Web::Api::Errors::SlackError => e
295
+ # capture all Slack errors
296
+ end
297
+ ```
298
+
299
+ If there's a new error type that is not yet known by this library, then it will raise `Slack::Web::Api::Errors::SlackError`. (Update the Web API if you find that errors are missing — see [CONTRIBUTING](CONTRIBUTING.md).)
300
+
301
+ In all of these cases the error message contains the error code, which is also accessible with `slack_error.error`. In case of multiple errors, the error message contains the error codes separated by commas, or they are accessible as an array with `slack_error.errors`. The original response is also accessible using the `response` attribute. The `response_metadata` is accessible with `slack_error.response_metadata`.
302
+
303
+ ##### Rate Limiting
304
+
305
+ If you exceed [Slack’s rate limits](https://api.slack.com/docs/rate-limits), a `Slack::Web::Api::Errors::TooManyRequestsError` will be raised instead. (This does not inherit from `Slack::Web::Api::Errors::SlackError`.)
306
+
307
+ ##### Other Errors
222
308
 
223
309
  In any other case, a `Faraday::ClientError` will be raised. This may be the case if Slack is temporarily unavailable, for example.
224
310
 
@@ -236,9 +322,9 @@ end
236
322
  client.on :message do |data|
237
323
  case data.text
238
324
  when 'bot hi' then
239
- client.message channel: data.channel, text: "Hi <@#{data.user}>!"
325
+ client.message(channel: data.channel, text: "Hi <@#{data.user}>!")
240
326
  when /^bot/ then
241
- client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?"
327
+ client.message(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
242
328
  end
243
329
  end
244
330
 
@@ -309,7 +395,7 @@ The following settings are supported.
309
395
  setting | description
310
396
  ----------------|-----------------------------------------------------------------------------------------------------
311
397
  token | Slack API token.
312
- websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
398
+ websocket_ping | How long the socket can be idle before sending a ping message to confirm it's still connected, default is 30.
313
399
  websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
314
400
  store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
315
401
  start_method | Optional start method, either `:rtm_start` or `:rtm_connect`.
@@ -322,6 +408,17 @@ See a fully working example in [examples/hi_real_time](examples/hi_real_time/hi.
322
408
 
323
409
  ![](examples/hi_real_time/hi.gif)
324
410
 
411
+ #### Caveats
412
+
413
+ ##### `websocket_ping`
414
+ This setting determines how long the socket can be idle before sending a ping message to confirm it's still connected.
415
+
416
+ It's important to note that if a ping message was sent and no response was received within the amount of time specified in `websocket_ping` the client will attempt to reestablish it's connection to the message server.
417
+
418
+ Note that the ping may take between `websocket_ping` and `websocket_ping * 3/2` seconds to actually trigger when there is no activity on the socket. This is because the timer that checks whether to ping is triggered at every `websocket_ping / 2` interval.
419
+
420
+ To disable this feature set `websocket_ping` to 0.
421
+
325
422
  ### Connection Methods
326
423
 
327
424
  The RealTime client uses either [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect) to open a connection. The former retrieves a lot of team information while the latter only serves connection purposes and is preferred. You should let the library choose the right method for you based on the `store_class` used and override this behavior with `start_method` when necessary.
@@ -342,9 +439,9 @@ client = Slack::RealTime::Client.new
342
439
  client.on :message do |data|
343
440
  case data.text
344
441
  when 'bot hi' then
345
- client.web_client.chat_postMessage channel: data.channel, text: "Hi <@#{data.user}>!"
442
+ client.web_client.chat_postMessage(channel: data.channel, text: "Hi <@#{data.user}>!")
346
443
  when /^bot/ then
347
- client.web_client.chat_postMessage channel: data.channel, text: "Sorry <@#{data.user}>, what?"
444
+ client.web_client.chat_postMessage(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
348
445
  end
349
446
  end
350
447
 
@@ -374,15 +471,15 @@ See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a dis
374
471
 
375
472
  #### Concurrency
376
473
 
377
- `Slack::RealTime::Client` needs help from a concurrency library and supports [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine) and [Celluloid](https://github.com/celluloid/celluloid). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly.
474
+ `Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async), [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine) and [Celluloid](https://github.com/celluloid/celluloid). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly.
378
475
 
379
476
  ```ruby
380
477
  Slack::RealTime.configure do |config|
381
- config.concurrency = Slack::RealTime::Concurrency::Eventmachine
478
+ config.concurrency = Slack::RealTime::Concurrency::Async
382
479
  end
383
480
  ```
384
481
 
385
- Use `client.start_async` instead of `client.start!`. A good example of such application is [slack-bot-server](https://github.com/dblock/slack-bot-server).
482
+ Use `client.start_async` instead of `client.start!`. A good example of such application is [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server).
386
483
 
387
484
  ```ruby
388
485
  client = Slack::RealTime::Client.new
@@ -390,6 +487,16 @@ client = Slack::RealTime::Client.new
390
487
  client.start_async
391
488
  ```
392
489
 
490
+ ##### Async
491
+
492
+ This is the recommended library. Add `async-websocket` to your Gemfile.
493
+
494
+ ```
495
+ gem 'async-websocket'
496
+ ```
497
+
498
+ See a fully working example in [examples/hi_real_time_async_async](examples/hi_real_time_async_async/hi.rb).
499
+
393
500
  ##### Faye::Websocket with Eventmachine
394
501
 
395
502
  Add the following to your Gemfile.
@@ -410,7 +517,44 @@ gem 'celluloid-io', require: ['celluloid/current', 'celluloid/io']
410
517
 
411
518
  See a fully working example in [examples/hi_real_time_async_celluloid](examples/hi_real_time_async_celluloid/hi.rb).
412
519
 
413
- Require
520
+ ### Events API
521
+
522
+ This library provides limited support for the [Slack Events API](https://api.slack.com/events-api).
523
+
524
+ #### Configuring Slack::Events
525
+
526
+ You can configure Events support globally.
527
+
528
+ ```ruby
529
+ Slack::Events.configure do |config|
530
+ config.signing_secret = 'secret'
531
+ end
532
+ ```
533
+
534
+ The following settings are supported.
535
+
536
+ setting | description
537
+ ----------------------|---------------------------------------------------------------------------------------------------
538
+ signing_secret | Slack signing secret, defaults is `ENV['SLACK_SIGNING_SECRET']`.
539
+ signature_expires_in | Signature expiration window in seconds, default is `300`.
540
+
541
+ #### Verifying the Request Signature
542
+
543
+ Slack signs its requests using a secret that's unique to your app. Verify incoming HTTP requests as follows.
544
+
545
+ ```ruby
546
+ slack_request = Slack::Events::Request.new(http_request)
547
+ slack_request.verify!
548
+ ```
549
+
550
+ To specify secrets on a per-request basis:
551
+ ```ruby
552
+ Slack::Events::Request.new(http_request,
553
+ signing_secret: signing_secret,
554
+ signature_expires_in: signature_expires_in)
555
+ ```
556
+
557
+ The `verify!` call may raise `Slack::Events::Request::MissingSigningSecret`, `Slack::Events::Request::InvalidSignature` or `Slack::Events::Request::TimestampExpired` errors.
414
558
 
415
559
  ### Message Parsing
416
560
 
@@ -500,6 +644,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
500
644
 
501
645
  ## Copyright and License
502
646
 
503
- Copyright (c) 2015-2016, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
647
+ Copyright (c) 2015-2019, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
504
648
 
505
649
  This project is licensed under the [MIT License](LICENSE.md).
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rubygems'
2
3
  require 'bundler'
3
4
  require 'bundler/gem_tasks'
@@ -14,7 +15,7 @@ end
14
15
  require 'rubocop/rake_task'
15
16
  RuboCop::RakeTask.new
16
17
 
17
- task default: %i[rubocop spec]
18
+ task default: %i[spec rubocop]
18
19
 
19
20
  load 'tasks/git.rake'
20
21
  load 'tasks/web.rake'
@@ -1,6 +1,32 @@
1
1
  Upgrading Slack-Ruby-Client
2
2
  ===========================
3
3
 
4
+ ### Upgrading to >= 0.14.0
5
+
6
+ If you are using async-websocket, lock down its version to 0.8.0 as newer versions are currently incompatible.
7
+
8
+ ```
9
+ gem 'async-websocket', '~> 0.8.0'
10
+ ```
11
+
12
+ See [#282](https://github.com/slack-ruby/slack-ruby-client/issues/282) for more information.
13
+
14
+ ### Upgrading to >= 0.13.0
15
+
16
+ #### Recommended Async Library
17
+
18
+ The RealTime client now supports [async-websocket](https://github.com/socketry/async-websocket), which is actively maintained and is now the recommended library.
19
+
20
+ See [#219](https://github.com/slack-ruby/slack-ruby-client/pull/219) for implementation details.
21
+
22
+ #### Async Library Threading and Reactor Changes
23
+
24
+ The RealTime celluloid-io implementation now uses a `Thread` per client. Previous versions used an `Actor`.
25
+
26
+ The faye-websocket implementation with EventMachine will attempt to shutdown EventMachine via `EventMachine.stop` upon shutdown if a reactor wasn't already running.
27
+
28
+ See [#224](https://github.com/slack-ruby/slack-ruby-client/pull/224) for more information.
29
+
4
30
  ### Upgrading to >= 0.9.0
5
31
 
6
32
  #### Changes in How the RTM Client Connects
@@ -37,7 +63,7 @@ Slack::RealTime::Client.config do |config|
37
63
  end
38
64
  ```
39
65
 
40
- See [#136](https://github.com/slack-ruby/slack-ruby-client/pull/136) for more details.
66
+ See [#136](https://github.com/slack-ruby/slack-ruby-client/pull/136) for more information.
41
67
 
42
68
  ### Upgrading to >= 0.6.0
43
69