slack-ruby-client 0.7.9 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +32 -1
- data/.rubocop_todo.yml +98 -49
- data/.travis.yml +10 -14
- data/CHANGELOG.md +172 -24
- data/CONTRIBUTING.md +17 -6
- data/Dangerfile +2 -0
- data/Gemfile +10 -4
- data/LICENSE.md +1 -1
- data/README.md +276 -54
- data/RELEASING.md +19 -11
- data/Rakefile +2 -1
- data/UPGRADING.md +84 -2
- data/bin/commands.rb +43 -1
- data/bin/commands/admin_analytics.rb +15 -0
- data/bin/commands/admin_apps.rb +40 -0
- data/bin/commands/admin_apps_approved.rb +17 -0
- data/bin/commands/admin_apps_requests.rb +16 -0
- data/bin/commands/admin_apps_restricted.rb +17 -0
- data/bin/commands/admin_barriers.rb +47 -0
- data/bin/commands/admin_conversations.rb +169 -0
- data/bin/commands/admin_conversations_ekm.rb +17 -0
- data/bin/commands/admin_conversations_restrictAccess.rb +37 -0
- data/bin/commands/admin_conversations_whitelist.rb +37 -0
- data/bin/commands/admin_emoji.rb +54 -0
- data/bin/commands/admin_inviteRequests.rb +36 -0
- data/bin/commands/admin_inviteRequests_approved.rb +16 -0
- data/bin/commands/admin_inviteRequests_denied.rb +16 -0
- data/bin/commands/admin_teams.rb +27 -0
- data/bin/commands/admin_teams_admins.rb +16 -0
- data/bin/commands/admin_teams_owners.rb +16 -0
- data/bin/commands/admin_teams_settings.rb +64 -0
- data/bin/commands/admin_usergroups.rb +48 -0
- data/bin/commands/admin_users.rb +97 -0
- data/bin/commands/admin_users_session.rb +38 -0
- data/bin/commands/api.rb +3 -3
- data/bin/commands/apps.rb +15 -0
- data/bin/commands/apps_connections.rb +13 -0
- data/bin/commands/apps_event_authorizations.rb +16 -0
- data/bin/commands/apps_permissions.rb +23 -0
- data/bin/commands/apps_permissions_resources.rb +15 -0
- data/bin/commands/apps_permissions_scopes.rb +13 -0
- data/bin/commands/apps_permissions_users.rb +26 -0
- data/bin/commands/auth.rb +5 -4
- data/bin/commands/auth_teams.rb +16 -0
- data/bin/commands/bots.rb +4 -2
- data/bin/commands/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/channels.rb +64 -43
- data/bin/commands/chat.rb +114 -24
- data/bin/commands/chat_scheduledMessages.rb +19 -0
- data/bin/commands/conversations.rb +196 -0
- data/bin/commands/dialog.rb +15 -0
- data/bin/commands/dnd.rb +9 -8
- data/bin/commands/emoji.rb +3 -2
- data/bin/commands/files.rb +45 -30
- data/bin/commands/files_comments.rb +3 -24
- data/bin/commands/files_remote.rb +78 -0
- data/bin/commands/groups.rb +53 -53
- data/bin/commands/im.rb +17 -13
- data/bin/commands/migration.rb +16 -0
- data/bin/commands/mpim.rb +16 -13
- data/bin/commands/oauth.rb +17 -2
- data/bin/commands/oauth_v2.rb +17 -0
- data/bin/commands/pins.rb +7 -10
- data/bin/commands/reactions.rb +17 -15
- data/bin/commands/reminders.rb +11 -10
- data/bin/commands/rtm.rb +19 -4
- data/bin/commands/search.rb +15 -11
- data/bin/commands/stars.rb +11 -8
- data/bin/commands/team.rb +15 -10
- data/bin/commands/team_profile.rb +3 -2
- data/bin/commands/usergroups.rb +22 -16
- data/bin/commands/usergroups_users.rb +7 -4
- data/bin/commands/users.rb +65 -37
- data/bin/commands/users_admin.rb +29 -0
- data/bin/commands/users_prefs.rb +13 -0
- data/bin/commands/users_profile.rb +8 -7
- data/bin/commands/views.rb +48 -0
- data/bin/commands/workflows.rb +38 -0
- data/bin/slack +3 -4
- data/examples/hi_real_time_and_web/Gemfile +1 -0
- data/examples/hi_real_time_and_web/hi.rb +8 -4
- data/examples/{hi_real_time_async_eventmachine → hi_real_time_async_async}/Gemfile +2 -1
- data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/Procfile +0 -0
- data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/hi.rb +13 -8
- data/examples/hi_web/Gemfile +1 -0
- data/examples/hi_web/hi.rb +2 -1
- data/examples/new_ticket/Gemfile +1 -0
- data/examples/new_ticket/new_ticket.rb +2 -1
- data/lib/slack-ruby-client.rb +40 -26
- data/lib/slack.rb +1 -0
- data/lib/slack/config.rb +1 -0
- data/lib/slack/events/config.rb +32 -0
- data/lib/slack/events/request.rb +70 -0
- data/lib/slack/logger.rb +6 -5
- data/lib/slack/messages/formatting.rb +4 -4
- data/lib/slack/messages/message.rb +2 -6
- data/lib/slack/real_time/api/message.rb +3 -1
- data/lib/slack/real_time/api/message_id.rb +1 -0
- data/lib/slack/real_time/api/ping.rb +5 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +1 -1
- data/lib/slack/real_time/api/typing.rb +3 -1
- data/lib/slack/real_time/client.rb +113 -32
- data/lib/slack/real_time/concurrency.rb +2 -2
- data/lib/slack/real_time/concurrency/async.rb +140 -0
- data/lib/slack/real_time/config.rb +20 -12
- data/lib/slack/real_time/models.rb +8 -7
- data/lib/slack/real_time/models/base.rb +2 -6
- data/lib/slack/real_time/models/bot.rb +1 -0
- data/lib/slack/real_time/models/channel.rb +1 -0
- data/lib/slack/real_time/models/group.rb +1 -0
- data/lib/slack/real_time/models/im.rb +1 -0
- data/lib/slack/real_time/models/team.rb +1 -0
- data/lib/slack/real_time/models/user.rb +1 -0
- data/lib/slack/real_time/socket.rb +46 -17
- data/lib/slack/real_time/stores.rb +4 -3
- data/lib/slack/real_time/stores/base.rb +5 -3
- data/lib/slack/real_time/stores/starter.rb +113 -72
- data/lib/slack/real_time/stores/store.rb +131 -88
- data/lib/slack/version.rb +2 -1
- data/lib/slack/web/api/endpoints.rb +110 -26
- data/lib/slack/web/api/endpoints/admin_analytics.rb +26 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +62 -0
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_barriers.rb +82 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +260 -0
- data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +64 -0
- data/lib/slack/web/api/endpoints/admin_emoji.rb +88 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_teams.rb +50 -0
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +99 -0
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
- data/lib/slack/web/api/endpoints/admin_users.rb +161 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +66 -0
- data/lib/slack/web/api/endpoints/api.rb +3 -4
- data/lib/slack/web/api/endpoints/apps.rb +27 -0
- data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
- data/lib/slack/web/api/endpoints/apps_permissions.rb +36 -0
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +31 -0
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +50 -0
- data/lib/slack/web/api/endpoints/auth.rb +5 -4
- data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
- data/lib/slack/web/api/endpoints/bots.rb +5 -2
- data/lib/slack/web/api/endpoints/calls.rb +83 -0
- data/lib/slack/web/api/endpoints/calls_participants.rb +42 -0
- data/lib/slack/web/api/endpoints/channels.rb +105 -49
- data/lib/slack/web/api/endpoints/chat.rb +221 -40
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +40 -0
- data/lib/slack/web/api/endpoints/conversations.rb +332 -0
- data/lib/slack/web/api/endpoints/dialog.rb +33 -0
- data/lib/slack/web/api/endpoints/dnd.rb +11 -9
- data/lib/slack/web/api/endpoints/emoji.rb +3 -2
- data/lib/slack/web/api/endpoints/files.rb +75 -38
- data/lib/slack/web/api/endpoints/files_comments.rb +3 -38
- data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
- data/lib/slack/web/api/endpoints/groups.rb +76 -53
- data/lib/slack/web/api/endpoints/im.rb +38 -21
- data/lib/slack/web/api/endpoints/migration.rb +28 -0
- data/lib/slack/web/api/endpoints/mpim.rb +37 -22
- data/lib/slack/web/api/endpoints/oauth.rb +25 -4
- data/lib/slack/web/api/endpoints/oauth_v2.rb +30 -0
- data/lib/slack/web/api/endpoints/pins.rb +10 -19
- data/lib/slack/web/api/endpoints/presence.rb +1 -1
- data/lib/slack/web/api/endpoints/reactions.rb +37 -28
- data/lib/slack/web/api/endpoints/reminders.rb +11 -10
- data/lib/slack/web/api/endpoints/rtm.rb +28 -7
- data/lib/slack/web/api/endpoints/search.rb +21 -14
- data/lib/slack/web/api/endpoints/stars.rb +24 -15
- data/lib/slack/web/api/endpoints/team.rb +21 -13
- data/lib/slack/web/api/endpoints/team_profile.rb +3 -2
- data/lib/slack/web/api/endpoints/usergroups.rb +33 -22
- data/lib/slack/web/api/endpoints/usergroups_users.rb +9 -4
- data/lib/slack/web/api/endpoints/users.rb +78 -29
- data/lib/slack/web/api/endpoints/users_admin.rb +49 -0
- data/lib/slack/web/api/endpoints/users_prefs.rb +21 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +11 -10
- data/lib/slack/web/api/endpoints/views.rb +97 -0
- data/lib/slack/web/api/endpoints/workflows.rb +61 -0
- data/lib/slack/web/api/error.rb +2 -8
- data/lib/slack/web/api/errors.rb +850 -0
- data/lib/slack/web/api/errors/internal_error.rb +14 -0
- data/lib/slack/web/api/errors/slack_error.rb +29 -0
- data/lib/slack/web/api/errors/too_many_requests_error.rb +24 -0
- data/lib/slack/web/api/mixins.rb +6 -4
- data/lib/slack/web/api/mixins/channels.id.rb +6 -7
- data/lib/slack/web/api/mixins/conversations.id.rb +25 -0
- data/lib/slack/web/api/mixins/groups.id.rb +6 -7
- data/lib/slack/web/api/mixins/ids.id.rb +24 -0
- data/lib/slack/web/api/mixins/users.id.rb +6 -7
- data/lib/slack/web/api/mixins/users.search.rb +39 -36
- data/lib/slack/web/api/patches/chat.1.patch +72 -0
- data/lib/slack/web/api/patches/dialog.1.open-json-support.patch +17 -0
- data/lib/slack/web/api/patches/views.1.view-json.patch +40 -0
- data/lib/slack/web/api/patches/views.1.views-published.patch +16 -0
- data/lib/slack/web/api/templates/command.erb +5 -3
- data/lib/slack/web/api/templates/commands.erb +2 -1
- data/lib/slack/web/api/templates/endpoints.erb +5 -3
- data/lib/slack/web/api/templates/errors.erb +20 -0
- data/lib/slack/web/api/templates/method.erb +26 -4
- data/lib/slack/web/api/templates/method_spec.erb +3 -2
- data/lib/slack/web/client.rb +2 -1
- data/lib/slack/web/config.rb +21 -10
- data/lib/slack/web/faraday/connection.rb +25 -16
- data/lib/slack/web/faraday/request.rb +2 -0
- data/lib/slack/web/faraday/response/raise_error.rb +23 -1
- data/lib/slack/web/faraday/response/wrap_error.rb +18 -0
- data/lib/slack/web/pagination/cursor.rb +52 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/lib/tasks/git.rake +2 -1
- data/lib/tasks/real_time.rake +16 -6
- data/lib/tasks/update.rake +1 -0
- data/lib/tasks/web.rake +38 -10
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-client.gemspec +9 -6
- data/spec/fixtures/slack/web/429_error.yml +2 -0
- data/spec/fixtures/slack/web/503_error.yml +14 -0
- data/spec/fixtures/slack/web/channels_info.yml +108 -15
- data/spec/fixtures/slack/web/conversations_setTopic.yml +69 -0
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +142 -0
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +208 -0
- data/spec/fixtures/slack/web/paginated_users_list.yml +181 -0
- data/spec/fixtures/slack/web/rtm_connect.yml +70 -0
- data/spec/fixtures/slack/web/rtm_start.yml +1 -1
- data/spec/fixtures/slack/web/views_open_error.yml +76 -0
- data/spec/integration/integration_spec.rb +116 -48
- data/spec/slack/config_spec.rb +2 -0
- data/spec/slack/events/config_spec.rb +33 -0
- data/spec/slack/events/request_spec.rb +183 -0
- data/spec/slack/messages/formatting_spec.rb +25 -14
- data/spec/slack/real_time/api/message_spec.rb +6 -1
- data/spec/slack/real_time/api/ping_spec.rb +2 -0
- data/spec/slack/real_time/api/typing_spec.rb +5 -1
- data/spec/slack/real_time/client_spec.rb +462 -134
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +3 -1
- data/spec/slack/real_time/event_handlers/bot_spec.rb +6 -3
- data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -6
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +3 -2
- data/spec/slack/real_time/event_handlers/group_spec.rb +5 -4
- data/spec/slack/real_time/event_handlers/im_spec.rb +4 -3
- data/spec/slack/real_time/event_handlers/team_spec.rb +8 -4
- data/spec/slack/real_time/event_handlers/user_spec.rb +5 -2
- data/spec/slack/real_time/rtm_connect_spec.rb +14 -0
- data/spec/slack/real_time/rtm_start_spec.rb +1 -0
- data/spec/slack/real_time/store_spec.rb +2 -1
- data/spec/slack/slack_spec.rb +39 -7
- data/spec/slack/version_spec.rb +2 -1
- data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +38 -0
- data/spec/slack/web/api/endpoints/admin_conversations_ekm_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +98 -0
- data/spec/slack/web/api/endpoints/admin_conversations_whitelist_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +53 -0
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +21 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +67 -0
- data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_connections_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/apps_permissions_resources_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +19 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/bots_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/calls_participants_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/calls_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/conversations_spec.rb +109 -0
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +13 -4
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +5 -3
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +140 -24
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +36 -0
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +2 -0
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +21 -6
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +95 -0
- data/spec/slack/web/api/endpoints/dnd_spec.rb +6 -0
- data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +3 -21
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/files_spec.rb +17 -5
- data/spec/slack/web/api/endpoints/im_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/migration_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/mpim_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/oauth_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/pins_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
- data/spec/slack/web/api/endpoints/reminders_spec.rb +3 -2
- data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/team_profile_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +3 -2
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/views_spec.rb +29 -0
- data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
- data/spec/slack/web/api/error_spec.rb +5 -3
- data/spec/slack/web/api/errors/slack_error_spec.rb +38 -0
- data/spec/slack/web/api/mixins/channels_spec.rb +24 -12
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +43 -0
- data/spec/slack/web/api/mixins/groups_spec.rb +24 -12
- data/spec/slack/web/api/mixins/users_spec.rb +30 -17
- data/spec/slack/web/api/pagination/cursor_spec.rb +100 -0
- data/spec/slack/web/client_spec.rb +215 -14
- data/spec/slack/web/faraday/response/raise_error_spec.rb +85 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/support/queue_with_timeout.rb +6 -5
- data/spec/support/real_time/concurrency/mock.rb +2 -2
- data/spec/support/real_time/connected_client.rb +13 -2
- data/spec/support/real_time/event.rb +1 -0
- data/spec/support/token.rb +1 -0
- data/spec/support/vcr.rb +6 -1
- metadata +280 -55
- data/examples/hi_real_time/Gemfile +0 -5
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +0 -37
- data/examples/hi_real_time_async_celluloid/Gemfile +0 -6
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/examples/hi_real_time_async_eventmachine/hi.rb +0 -36
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -113
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -60
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +0 -13
- data/lib/slack/web/api/patches/chat.2.attachments-json.patch +0 -17
- data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +0 -20
- data/screenshots/register-bot.png +0 -0
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -31
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -47
data/CONTRIBUTING.md
CHANGED
@@ -65,7 +65,7 @@ Make sure that `bundle exec rake` completes without errors.
|
|
65
65
|
|
66
66
|
### Update Slack Web API
|
67
67
|
|
68
|
-
Slack Web API is updated from https://github.com/
|
68
|
+
Slack Web API is updated from https://github.com/slack-ruby/slack-api-ref, a maintained, machine-readable version of Slack API Docs, generated by scraping [api.slack.com](https://api.slack.com). To update the Web API from the latest definition run the following Rake task.
|
69
69
|
|
70
70
|
```
|
71
71
|
rake slack:api:update
|
@@ -75,13 +75,24 @@ rake slack:api:update
|
|
75
75
|
|
76
76
|
Sometimes it's necessary to patch auto-generated Slack Web API methods. For example, we want to help clients with calling `to_json` on the `attachments` parameter sent to `chat_postMessage`. See [#20](https://github.com/slack-ruby/slack-ruby-client/issues/20).
|
77
77
|
|
78
|
-
|
78
|
+
The broad steps are:
|
79
|
+
1. Run `rake slack:api:update` to check that existing patches are still valid.
|
80
|
+
- If you run into a `failed to apply patch` error, the auto-generated methods likely drifted from the last patch. Follow the steps [below](#resolving-patch-errors).
|
81
|
+
- This may add new methods if the API has updated, please split them up into multiple PRs if so.
|
82
|
+
2. Make a change to a generated file, for example `lib/slack/web/api/endpoints/chat.rb`.
|
83
|
+
3. Generate a patch:
|
84
|
+
```
|
85
|
+
git diff --no-color HEAD lib/slack/web/api/endpoints/chat.rb > lib/slack/web/api/patches/chat.1.patch
|
86
|
+
```
|
87
|
+
4. Run `rake slack:api:update` to ensure that the patch is cleanly applied. Implement a test for the added or modified functionality and commit the patch file.
|
79
88
|
|
80
|
-
|
81
|
-
|
82
|
-
|
89
|
+
##### Resolving Patch Errors
|
90
|
+
|
91
|
+
The auto-generated method files may drift overtime e.g. new arguments may be added or descriptions changed. Since previous patches were based on the older auto-generated files, git may be unable to apply them to the new files. Resolving them requires some good ol' splicing:
|
92
|
+
1. Run `rake slack:api:update SKIP_PATCH=true` to create the raw auto-generated files. Commit the files that you are updating, so we can run `git diff` later.
|
93
|
+
2. Go through the old patches for the files (e.g. in `lib/slack/web/api/patches/chat.1.patch`), copying code into the new files.
|
94
|
+
3. Continue with Step 2 [above](#patching-slack-web-api).
|
83
95
|
|
84
|
-
Run `rake slack:api:update` to ensure that the patch is cleanly applied. Implement a test for the added or modified functionality and commit the patch file.
|
85
96
|
|
86
97
|
### Write Documentation
|
87
98
|
|
data/Dangerfile
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
source 'http://rubygems.org'
|
2
3
|
|
3
4
|
gemspec
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
14
|
|
9
15
|
group :test do
|
10
|
-
gem 'slack-ruby-danger', '~> 0.
|
16
|
+
gem 'slack-ruby-danger', '~> 0.2.0', require: false
|
11
17
|
end
|
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2015-
|
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,72 @@ 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)
|
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
|
+
- [Character Encoding](#character-encoding)
|
35
|
+
- [Error Handling](#error-handling)
|
36
|
+
- [Slack Errors](#slack-errors)
|
37
|
+
- [Rate Limiting](#rate-limiting)
|
38
|
+
- [Other Errors](#other-errors)
|
39
|
+
- [RealTime Client](#realtime-client)
|
40
|
+
- [Slack::RealTime::Stores::Store](#slackrealtimestoresstore)
|
41
|
+
- [Slack::RealTime::Stores::Starter](#slackrealtimestoresstarter)
|
42
|
+
- [Configuring Slack::RealTime::Client](#configuring-slackrealtimeclient)
|
43
|
+
- [Caveats](#caveats)
|
44
|
+
- [websocket_ping](#websocket_ping)
|
45
|
+
- [Connection Methods](#connection-methods)
|
46
|
+
- [Combining RealTime and Web Clients](#combining-realtime-and-web-clients)
|
47
|
+
- [Large Team Considerations](#large-team-considerations)
|
48
|
+
- [Concurrency](#concurrency)
|
49
|
+
- [Async](#async)
|
50
|
+
- [Events API](#events-api)
|
51
|
+
- [Configuring Slack::Events](#configuring-slackevents)
|
52
|
+
- [Verifying the Request Signature](#verifying-the-request-signature)
|
53
|
+
- [Message Parsing](#message-parsing)
|
54
|
+
- [Command-Line Client](#command-line-client)
|
55
|
+
- [Authenticate with Slack](#authenticate-with-slack)
|
56
|
+
- [Send a Message](#send-a-message)
|
57
|
+
- [Get Channel Id](#get-channel-id)
|
58
|
+
- [Get Channel Info](#get-channel-info-1)
|
59
|
+
- [List Users](#list-users)
|
60
|
+
- [History](#history)
|
61
|
+
- [Contributing](#contributing)
|
62
|
+
- [Copyright and License](#copyright-and-license)
|
63
|
+
|
12
64
|
## Useful to Me?
|
13
65
|
|
14
|
-
* This
|
15
|
-
*
|
16
|
-
*
|
17
|
-
*
|
66
|
+
* 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.
|
67
|
+
* 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.
|
68
|
+
* 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.
|
69
|
+
* 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
70
|
|
19
71
|
## Stable Release
|
20
72
|
|
21
|
-
You're reading the documentation for the **stable** release of slack-ruby-client, 0.
|
73
|
+
You're reading the documentation for the **stable** release of slack-ruby-client, 0.16.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
22
74
|
|
23
75
|
## Installation
|
24
76
|
|
@@ -28,11 +80,10 @@ Add to Gemfile.
|
|
28
80
|
gem 'slack-ruby-client'
|
29
81
|
```
|
30
82
|
|
31
|
-
If you're going to be using the RealTime client, add
|
83
|
+
If you're going to be using the RealTime client, add `async-websocket`. See below for more information about concurrency.
|
32
84
|
|
33
85
|
```
|
34
|
-
gem '
|
35
|
-
gem 'faye-websocket'
|
86
|
+
gem 'async-websocket', '~> 0.8.0'
|
36
87
|
```
|
37
88
|
|
38
89
|
Run `bundle install`.
|
@@ -41,11 +92,17 @@ Run `bundle install`.
|
|
41
92
|
|
42
93
|
### Create a New Bot Integration
|
43
94
|
|
44
|
-
|
95
|
+
To integrate your bot with Slack, you must first create a new [Slack App](https://api.slack.com/apps).
|
96
|
+
|
97
|
+
![](screenshots/create-app.png)
|
98
|
+
|
99
|
+
### OAuth Code Grant
|
45
100
|
|
46
|
-
|
101
|
+
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
102
|
|
48
|
-
###
|
103
|
+
### Using the Legacy API Token
|
104
|
+
|
105
|
+
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
106
|
|
50
107
|
```ruby
|
51
108
|
Slack.configure do |config|
|
@@ -68,14 +125,18 @@ logger | An optional logger, defaults to `::Logger.new(STDOUT)` at `Logger
|
|
68
125
|
|
69
126
|
The Slack Web API allows you to build applications that interact with Slack.
|
70
127
|
|
71
|
-
####
|
128
|
+
#### Web Client Examples
|
129
|
+
|
130
|
+
Here are some examples of how to use the web client with the Web API.
|
131
|
+
|
132
|
+
##### Test Auth
|
72
133
|
|
73
134
|
```ruby
|
74
135
|
client = Slack::Web::Client.new
|
75
136
|
client.auth_test
|
76
137
|
```
|
77
138
|
|
78
|
-
|
139
|
+
##### Send Messages
|
79
140
|
|
80
141
|
Send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
|
81
142
|
|
@@ -87,7 +148,7 @@ See a fully working example in [examples/hi_web](examples/hi_web/hi.rb).
|
|
87
148
|
|
88
149
|
![](examples/hi_web/hi.gif)
|
89
150
|
|
90
|
-
|
151
|
+
##### List Channels
|
91
152
|
|
92
153
|
List channels with [channels_list](https://api.slack.com/methods/channels.list).
|
93
154
|
|
@@ -97,7 +158,7 @@ channels = client.channels_list.channels
|
|
97
158
|
general_channel = channels.detect { |c| c.name == 'general' }
|
98
159
|
```
|
99
160
|
|
100
|
-
|
161
|
+
##### Upload a File
|
101
162
|
|
102
163
|
Upload a file with [files_upload](https://api.slack.com/methods/files.upload).
|
103
164
|
|
@@ -112,7 +173,7 @@ client.files_upload(
|
|
112
173
|
)
|
113
174
|
```
|
114
175
|
|
115
|
-
|
176
|
+
##### Get Channel Info
|
116
177
|
|
117
178
|
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
179
|
|
@@ -124,7 +185,7 @@ client.channels_info(channel: 'C04KB5X4D') # calls channels_info
|
|
124
185
|
client.channels_info(channel: '#general') # calls channels_list followed by channels_info
|
125
186
|
```
|
126
187
|
|
127
|
-
|
188
|
+
##### Get User Info
|
128
189
|
|
129
190
|
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
191
|
|
@@ -136,7 +197,7 @@ client.users_info(user: 'U092BDCLV') # calls users_info
|
|
136
197
|
client.users_info(user: '@dblock') # calls users_list followed by users_info
|
137
198
|
```
|
138
199
|
|
139
|
-
|
200
|
+
##### Search for a User
|
140
201
|
|
141
202
|
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
203
|
|
@@ -144,7 +205,7 @@ Constructs an in-memory index of users and searches it. If you want to use this
|
|
144
205
|
client.users_search(user: 'dblock')
|
145
206
|
```
|
146
207
|
|
147
|
-
|
208
|
+
##### Other
|
148
209
|
|
149
210
|
Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.
|
150
211
|
|
@@ -153,7 +214,7 @@ Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for
|
|
153
214
|
You can configure the Web client either globally or via the initializer.
|
154
215
|
|
155
216
|
```ruby
|
156
|
-
Slack::Web::Client.
|
217
|
+
Slack::Web::Client.configure do |config|
|
157
218
|
config.user_agent = 'Slack Ruby Client/1.0'
|
158
219
|
end
|
159
220
|
```
|
@@ -164,15 +225,110 @@ client = Slack::Web::Client.new(user_agent: 'Slack Ruby Client/1.0')
|
|
164
225
|
|
165
226
|
The following settings are supported.
|
166
227
|
|
167
|
-
setting
|
168
|
-
|
169
|
-
token
|
170
|
-
user_agent
|
171
|
-
proxy
|
172
|
-
ca_path
|
173
|
-
ca_file
|
174
|
-
endpoint
|
175
|
-
logger
|
228
|
+
setting | description
|
229
|
+
--------------------|-------------------------------------------------------------------------------------------------
|
230
|
+
token | Slack API token.
|
231
|
+
user_agent | User-agent, defaults to _Slack Ruby Client/version_.
|
232
|
+
proxy | Optional HTTP proxy.
|
233
|
+
ca_path | Optional SSL certificates path.
|
234
|
+
ca_file | Optional SSL certificates file.
|
235
|
+
endpoint | Slack endpoint, default is _https://slack.com/api_.
|
236
|
+
logger | Optional `Logger` instance that logs HTTP requests.
|
237
|
+
timeout | Optional open/read timeout in seconds.
|
238
|
+
open_timeout | Optional connection open timeout in seconds.
|
239
|
+
default_page_size | Optional page size for paginated requests, default is _100_.
|
240
|
+
default_max_retries | Optional number of retries for paginated requests, default is _100_.
|
241
|
+
adapter | Optional HTTP adapter to use, defaults to `Faraday.default_adapter`.
|
242
|
+
|
243
|
+
You can also pass request options, including `timeout` and `open_timeout` into individual calls.
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
client.channels_list(request: { timeout: 180 })
|
247
|
+
```
|
248
|
+
|
249
|
+
You can also control what proxy options are used by modifying the `http_proxy` environment variable per [Net::HTTP's documentation](https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#class-Net::HTTP-label-Proxies).
|
250
|
+
|
251
|
+
Note that Docker on OSX seems to incorrectly set the proxy, causing `Faraday::ConnectionFailed, ERROR -- : Failed to open TCP connection to : (getaddrinfo: Name or service not known)`. You might need to manually unset `http_proxy` in that case, eg. `http_proxy="" bundle exec ruby ./my_bot.rb`.
|
252
|
+
|
253
|
+
#### Pagination Support
|
254
|
+
|
255
|
+
The Web client natively supports [cursor pagination](https://api.slack.com/docs/pagination#cursors) for methods that allow it, such as `users_list`. Supply a block and the client will make repeated requests adjusting the value of `cursor` with every response. The default limit is set to 100 and can be adjusted via `Slack::Web::Client.config.default_page_size` or by passing it directly into the API call.
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
all_members = []
|
259
|
+
client.users_list(presence: true, limit: 10) do |response|
|
260
|
+
all_members.concat(response.members)
|
261
|
+
end
|
262
|
+
all_members # many thousands of team members retrieved 10 at a time
|
263
|
+
```
|
264
|
+
|
265
|
+
When using cursor pagination the client will automatically pause and then retry the request if it runs into Slack rate limiting. (It will pause according to the `Retry-After` header in the 429 response before retrying the request.) If it receives too many rate-limited responses in a row it will give up and raise an error. The default number of retries is 100 and can be adjusted via `Slack::Web::Client.config.default_max_retries` or by passing it directly into the method as `max_retries`.
|
266
|
+
|
267
|
+
You can also proactively avoid rate limiting by adding a pause between every paginated request with the `sleep_interval` parameter, which is given in seconds.
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
all_members = []
|
271
|
+
client.users_list(presence: true, limit: 10, sleep_interval: 5, max_retries: 20) do |response|
|
272
|
+
# pauses for 5 seconds between each request
|
273
|
+
# gives up after 20 consecutive rate-limited responses
|
274
|
+
all_members.concat(response.members)
|
275
|
+
end
|
276
|
+
all_members # many thousands of team members retrieved 10 at a time
|
277
|
+
```
|
278
|
+
|
279
|
+
#### Character Encoding
|
280
|
+
|
281
|
+
Note that Slack expects `text` to be UTF-8 encoded. If your messages appear with text such as `BAD+11` in Slack, check `text.encoding` and `.encode(Encoding::UTF_8)` your messages before sending them to Slack.
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
text = 'characters such as "Ñ", "Á", "É"'
|
285
|
+
text.encoding
|
286
|
+
=> #<Encoding:UTF-8>
|
287
|
+
client.chat_postMessage(channel: '#general', text: text, as_user: true)
|
288
|
+
# renders 'characters such as "Ñ", "Á", "É"' in Slack
|
289
|
+
|
290
|
+
text = text.encode(Encoding::ISO_8859_1)
|
291
|
+
text.encoding
|
292
|
+
# => #<Encoding:ISO-8859-1>
|
293
|
+
client.chat_postMessage(channel: '#general', text: text, as_user: true)
|
294
|
+
# renders 'characters such as "BAD+11", "", "BAD+9"' in Slack
|
295
|
+
```
|
296
|
+
|
297
|
+
#### Error Handling
|
298
|
+
|
299
|
+
##### Slack Errors
|
300
|
+
|
301
|
+
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:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
rescue Slack::Web::Api::Errors::AccountInactive => e
|
305
|
+
# deal with inactive account
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
All of these errors inherit from `Slack::Web::Api::Errors::SlackError`, so you can handle or silence all errors if necessary:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
313
|
+
# capture all Slack errors
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
317
|
+
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).)
|
318
|
+
|
319
|
+
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`.
|
320
|
+
|
321
|
+
##### Rate Limiting
|
322
|
+
|
323
|
+
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`.)
|
324
|
+
|
325
|
+
##### Other Errors
|
326
|
+
|
327
|
+
In case of Slack temporarily unavailability a `Slack::Web::Api::Errors::ServerError` (`Slack::Web::Api::Errors::SlackError` subclass) subclasses will be raised and original `Faraday::Error` will be accesible via `exception.cause`.
|
328
|
+
|
329
|
+
Specifically `Slack::Web::Api::Errors::ParsingError` will be raised on non-json response (i. e. 200 OK with `Slack unavailable` HTML page) and `Slack::Web::Api::Errors::HttpRequestError` subclasses for connection failures (`Slack::Web::Api::Errors::TimeoutError` for read/open timeouts & `Slack::Web::Api::Errors::UnavailableError` for 5xx HTTP responses).
|
330
|
+
|
331
|
+
In any other case, a `Faraday::ClientError` will be raised.
|
176
332
|
|
177
333
|
### RealTime Client
|
178
334
|
|
@@ -188,9 +344,9 @@ end
|
|
188
344
|
client.on :message do |data|
|
189
345
|
case data.text
|
190
346
|
when 'bot hi' then
|
191
|
-
client.message
|
347
|
+
client.message(channel: data.channel, text: "Hi <@#{data.user}>!")
|
192
348
|
when /^bot/ then
|
193
|
-
client.message
|
349
|
+
client.message(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
|
194
350
|
end
|
195
351
|
end
|
196
352
|
|
@@ -236,18 +392,18 @@ Tracking with a local store can be disabled with `Slack::RealTime::Client.new(st
|
|
236
392
|
|
237
393
|
#### Slack::RealTime::Stores::Store
|
238
394
|
|
239
|
-
The default store that tracks all changes.
|
395
|
+
The default store that tracks all changes. By default the client will be connected using `rtm_start`.
|
240
396
|
|
241
397
|
#### Slack::RealTime::Stores::Starter
|
242
398
|
|
243
|
-
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots.
|
399
|
+
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots. By default the client will be connected using `rtm_connect`.
|
244
400
|
|
245
401
|
### Configuring Slack::RealTime::Client
|
246
402
|
|
247
403
|
You can configure the RealTime client either globally or via the initializer.
|
248
404
|
|
249
405
|
```ruby
|
250
|
-
Slack::RealTime::Client.
|
406
|
+
Slack::RealTime::Client.configure do |config|
|
251
407
|
config.websocket_ping = 42
|
252
408
|
end
|
253
409
|
```
|
@@ -261,18 +417,40 @@ The following settings are supported.
|
|
261
417
|
setting | description
|
262
418
|
----------------|-----------------------------------------------------------------------------------------------------
|
263
419
|
token | Slack API token.
|
264
|
-
websocket_ping |
|
420
|
+
websocket_ping | How long the socket can be idle before sending a ping message to confirm it's still connected, default is 30.
|
265
421
|
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
|
266
422
|
store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
|
267
|
-
|
423
|
+
start_method | Optional start method, either `:rtm_start` or `:rtm_connect`.
|
424
|
+
start_options | Options to pass into `rtm.start` or `rtm.connect`, default is `{ request: { timeout: 180 } }`.
|
268
425
|
logger | Optional `Logger` instance that logs RealTime requests and socket data.
|
269
426
|
|
270
|
-
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
|
427
|
+
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
|
271
428
|
|
272
429
|
See a fully working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).
|
273
430
|
|
274
431
|
![](examples/hi_real_time/hi.gif)
|
275
432
|
|
433
|
+
#### Caveats
|
434
|
+
|
435
|
+
##### `websocket_ping`
|
436
|
+
This setting determines how long the socket can be idle before sending a ping message to confirm it's still connected.
|
437
|
+
|
438
|
+
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.
|
439
|
+
|
440
|
+
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.
|
441
|
+
|
442
|
+
To disable this feature set `websocket_ping` to 0.
|
443
|
+
|
444
|
+
### Connection Methods
|
445
|
+
|
446
|
+
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.
|
447
|
+
|
448
|
+
```ruby
|
449
|
+
Slack::RealTime::Client.configure do |config|
|
450
|
+
config.start_method = :rtm_start
|
451
|
+
end
|
452
|
+
```
|
453
|
+
|
276
454
|
### Combining RealTime and Web Clients
|
277
455
|
|
278
456
|
Since the Web client is used to obtain the RealTime client's WebSocket URL, you can continue using the Web client in combination with the RealTime client.
|
@@ -283,30 +461,47 @@ client = Slack::RealTime::Client.new
|
|
283
461
|
client.on :message do |data|
|
284
462
|
case data.text
|
285
463
|
when 'bot hi' then
|
286
|
-
client.web_client.chat_postMessage
|
464
|
+
client.web_client.chat_postMessage(channel: data.channel, text: "Hi <@#{data.user}>!")
|
287
465
|
when /^bot/ then
|
288
|
-
client.web_client.chat_postMessage
|
466
|
+
client.web_client.chat_postMessage(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
|
289
467
|
end
|
290
468
|
end
|
291
469
|
|
292
470
|
client.start!
|
293
471
|
```
|
294
472
|
|
295
|
-
See a
|
473
|
+
See a fully working example in [examples/hi_real_time_and_web](examples/hi_real_time_and_web/hi.rb).
|
296
474
|
|
297
475
|
![](examples/hi_real_time_and_web/hi.gif)
|
298
476
|
|
477
|
+
### Large Team Considerations
|
478
|
+
|
479
|
+
The `rtm.start` call downloads a large amount of data. For large teams, consider reducing the amount of unnecessary data downloaded with `start_options`. You may also want to increase the default timeout of 180 seconds.
|
480
|
+
|
481
|
+
```ruby
|
482
|
+
Slack::RealTime::Client.configure do |config|
|
483
|
+
# Return timestamp only for latest message object of each channel.
|
484
|
+
config.start_options[:simple_latest] = true
|
485
|
+
# Skip unread counts for each channel.
|
486
|
+
config.start_options[:no_unreads] = true
|
487
|
+
# Increase request timeout to 6 minutes.
|
488
|
+
config.start_options[:request][:timeout] = 360
|
489
|
+
end
|
490
|
+
```
|
491
|
+
|
492
|
+
See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a discussion on this topic.
|
493
|
+
|
299
494
|
#### Concurrency
|
300
495
|
|
301
|
-
`Slack::RealTime::Client` needs help from a concurrency library and supports [
|
496
|
+
`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async).
|
302
497
|
|
303
498
|
```ruby
|
304
499
|
Slack::RealTime.configure do |config|
|
305
|
-
config.concurrency = Slack::RealTime::Concurrency::
|
500
|
+
config.concurrency = Slack::RealTime::Concurrency::Async
|
306
501
|
end
|
307
502
|
```
|
308
503
|
|
309
|
-
Use `client.start_async` instead of `client.start!`. A good example of such application is [slack-bot-server](https://github.com/
|
504
|
+
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).
|
310
505
|
|
311
506
|
```ruby
|
312
507
|
client = Slack::RealTime::Client.new
|
@@ -314,27 +509,54 @@ client = Slack::RealTime::Client.new
|
|
314
509
|
client.start_async
|
315
510
|
```
|
316
511
|
|
317
|
-
#####
|
512
|
+
##### Async
|
318
513
|
|
319
|
-
Add
|
514
|
+
Add `async-websocket` to your Gemfile.
|
320
515
|
|
321
516
|
```
|
322
|
-
gem '
|
517
|
+
gem 'async-websocket'
|
323
518
|
```
|
324
519
|
|
325
|
-
See a fully working example in [examples/
|
520
|
+
See a fully working example in [examples/hi_real_time_async_async](examples/hi_real_time_async_async/hi.rb).
|
521
|
+
|
522
|
+
### Events API
|
326
523
|
|
327
|
-
|
524
|
+
This library provides limited support for the [Slack Events API](https://api.slack.com/events-api).
|
328
525
|
|
329
|
-
|
526
|
+
#### Configuring Slack::Events
|
330
527
|
|
528
|
+
You can configure Events support globally.
|
529
|
+
|
530
|
+
```ruby
|
531
|
+
Slack::Events.configure do |config|
|
532
|
+
config.signing_secret = 'secret'
|
533
|
+
end
|
331
534
|
```
|
332
|
-
|
535
|
+
|
536
|
+
The following settings are supported.
|
537
|
+
|
538
|
+
setting | description
|
539
|
+
----------------------|---------------------------------------------------------------------------------------------------
|
540
|
+
signing_secret | Slack signing secret, defaults is `ENV['SLACK_SIGNING_SECRET']`.
|
541
|
+
signature_expires_in | Signature expiration window in seconds, default is `300`.
|
542
|
+
|
543
|
+
#### Verifying the Request Signature
|
544
|
+
|
545
|
+
Slack signs its requests using a secret that's unique to your app. Verify incoming HTTP requests as follows.
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
slack_request = Slack::Events::Request.new(http_request)
|
549
|
+
slack_request.verify!
|
333
550
|
```
|
334
551
|
|
335
|
-
|
552
|
+
To specify secrets on a per-request basis:
|
553
|
+
```ruby
|
554
|
+
Slack::Events::Request.new(http_request,
|
555
|
+
signing_secret: signing_secret,
|
556
|
+
signature_expires_in: signature_expires_in)
|
557
|
+
```
|
336
558
|
|
337
|
-
|
559
|
+
The `verify!` call may raise `Slack::Events::Request::MissingSigningSecret`, `Slack::Events::Request::InvalidSignature` or `Slack::Events::Request::TimestampExpired` errors.
|
338
560
|
|
339
561
|
### Message Parsing
|
340
562
|
|
@@ -424,6 +646,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
|
|
424
646
|
|
425
647
|
## Copyright and License
|
426
648
|
|
427
|
-
Copyright (c) 2015-
|
649
|
+
Copyright (c) 2015-2019, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
|
428
650
|
|
429
651
|
This project is licensed under the [MIT License](LICENSE.md).
|