slack-ruby-client 0.13.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/integration_test.yml +26 -0
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/pr_lint.yml +21 -0
- data/.github/workflows/test.yml +36 -0
- data/.gitignore +5 -3
- data/.rubocop.yml +34 -5
- data/.rubocop_todo.yml +180 -46
- data/.ruby-version +1 -0
- data/CHANGELOG.md +119 -2
- data/CONTRIBUTING.md +23 -11
- data/Dangerfile +2 -0
- data/Gemfile +22 -5
- data/Gemfile.danger +6 -0
- data/LICENSE.md +1 -1
- data/README.md +236 -101
- data/RELEASING.md +2 -2
- data/Rakefile +2 -1
- data/UPGRADING.md +100 -2
- data/bin/commands/admin_analytics.rb +16 -0
- data/bin/commands/admin_apps.rb +51 -0
- data/bin/commands/admin_apps_approved.rb +17 -0
- data/bin/commands/admin_apps_requests.rb +28 -0
- data/bin/commands/admin_apps_restricted.rb +17 -0
- data/bin/commands/admin_audit_anomaly_allow.rb +23 -0
- data/bin/commands/admin_auth_policy.rb +39 -0
- data/bin/commands/admin_barriers.rb +47 -0
- data/bin/commands/admin_conversations.rb +171 -0
- data/bin/commands/admin_conversations_ekm.rb +17 -0
- data/bin/commands/admin_conversations_restrictAccess.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 +98 -0
- data/bin/commands/admin_users_session.rb +78 -0
- data/bin/commands/admin_users_unsupportedVersions.rb +15 -0
- data/bin/commands/api.rb +1 -1
- 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_manifest.rb +52 -0
- data/bin/commands/auth.rb +1 -0
- data/bin/commands/auth_teams.rb +16 -0
- data/bin/commands/bookmarks.rb +53 -0
- data/bin/commands/bots.rb +2 -0
- data/bin/commands/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/chat.rb +61 -14
- data/bin/commands/chat_scheduledMessages.rb +19 -0
- data/bin/commands/conversations.rb +82 -10
- data/bin/commands/dialog.rb +1 -0
- data/bin/commands/dnd.rb +6 -3
- data/bin/commands/emoji.rb +1 -0
- data/bin/commands/files.rb +34 -18
- data/bin/commands/files_comments.rb +1 -21
- data/bin/commands/files_remote.rb +78 -0
- data/bin/commands/migration.rb +2 -0
- data/bin/commands/oauth.rb +2 -14
- data/bin/commands/oauth_v2.rb +29 -0
- data/bin/commands/openid_connect.rb +27 -0
- data/bin/commands/pins.rb +3 -6
- data/bin/commands/reactions.rb +3 -3
- data/bin/commands/reminders.rb +7 -0
- data/bin/commands/rtm.rb +1 -15
- data/bin/commands/search.rb +6 -1
- data/bin/commands/stars.rb +8 -6
- data/bin/commands/team.rb +6 -0
- data/bin/commands/team_billing.rb +13 -0
- data/bin/commands/team_preferences.rb +13 -0
- data/bin/commands/team_profile.rb +1 -0
- data/bin/commands/tooling_tokens.rb +14 -0
- data/bin/commands/usergroups.rb +7 -1
- data/bin/commands/usergroups_users.rb +3 -0
- data/bin/commands/users.rb +6 -4
- data/bin/commands/users_admin.rb +1 -0
- data/bin/commands/users_prefs.rb +1 -0
- data/bin/commands/users_profile.rb +6 -5
- data/bin/commands/views.rb +50 -0
- data/bin/commands/workflows.rb +38 -0
- data/bin/commands.rb +41 -8
- data/bin/slack +3 -4
- data/examples/hi_real_time_and_web/Gemfile +1 -0
- data/examples/hi_real_time_and_web/hi.rb +7 -3
- data/examples/hi_real_time_async_async/Gemfile +1 -0
- data/examples/hi_real_time_async_async/hi.rb +6 -2
- data/examples/hi_web/Gemfile +1 -0
- data/examples/hi_web/hi.rb +1 -0
- data/examples/new_ticket/Gemfile +1 -0
- data/examples/new_ticket/new_ticket.rb +1 -0
- data/lib/slack/config.rb +2 -2
- data/lib/slack/events/config.rb +32 -0
- data/lib/slack/events/request.rb +72 -0
- data/lib/slack/logger.rb +6 -5
- data/lib/slack/messages/formatting.rb +1 -0
- data/lib/slack/messages/message.rb +1 -4
- data/lib/slack/real_time/api/message.rb +6 -3
- 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 +5 -1
- data/lib/slack/real_time/api/typing.rb +5 -2
- data/lib/slack/real_time/client.rb +105 -54
- data/lib/slack/real_time/concurrency/async.rb +77 -6
- data/lib/slack/real_time/concurrency.rb +1 -2
- data/lib/slack/real_time/config.rb +9 -13
- data/lib/slack/real_time/models/base.rb +1 -4
- data/lib/slack/real_time/models/bot.rb +1 -0
- data/lib/slack/real_time/models/channel.rb +5 -0
- data/lib/slack/real_time/models/im.rb +1 -0
- data/lib/slack/real_time/models/{group.rb → mpim.rb} +2 -1
- 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/models.rb +3 -1
- data/lib/slack/real_time/socket.rb +45 -17
- data/lib/slack/real_time/stores/base.rb +28 -14
- data/lib/slack/real_time/stores/starter.rb +325 -297
- data/lib/slack/real_time/stores/store.rb +271 -196
- data/lib/slack/real_time/stores.rb +2 -7
- data/lib/slack/version.rb +2 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +28 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +78 -0
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +51 -0
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
- data/lib/slack/web/api/endpoints/admin_barriers.rb +82 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +264 -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_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 +163 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +122 -0
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/api.rb +2 -3
- 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_manifest.rb +77 -0
- data/lib/slack/web/api/endpoints/auth.rb +2 -1
- data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
- data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
- data/lib/slack/web/api/endpoints/bots.rb +4 -1
- 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/chat.rb +168 -65
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +40 -0
- data/lib/slack/web/api/endpoints/conversations.rb +182 -67
- data/lib/slack/web/api/endpoints/dialog.rb +5 -4
- data/lib/slack/web/api/endpoints/dnd.rb +9 -4
- data/lib/slack/web/api/endpoints/emoji.rb +1 -0
- data/lib/slack/web/api/endpoints/files.rb +69 -37
- data/lib/slack/web/api/endpoints/files_comments.rb +4 -36
- data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
- data/lib/slack/web/api/endpoints/migration.rb +6 -3
- data/lib/slack/web/api/endpoints/oauth.rb +7 -31
- data/lib/slack/web/api/endpoints/oauth_v2.rb +48 -0
- data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
- data/lib/slack/web/api/endpoints/pins.rb +11 -18
- data/lib/slack/web/api/endpoints/reactions.rb +22 -21
- data/lib/slack/web/api/endpoints/reminders.rb +23 -10
- data/lib/slack/web/api/endpoints/rtm.rb +3 -25
- data/lib/slack/web/api/endpoints/search.rb +31 -16
- data/lib/slack/web/api/endpoints/stars.rb +14 -11
- data/lib/slack/web/api/endpoints/team.rb +15 -4
- data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
- data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
- data/lib/slack/web/api/endpoints/team_profile.rb +2 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
- data/lib/slack/web/api/endpoints/usergroups.rb +31 -20
- data/lib/slack/web/api/endpoints/usergroups_users.rb +13 -8
- data/lib/slack/web/api/endpoints/users.rb +24 -23
- data/lib/slack/web/api/endpoints/users_admin.rb +3 -2
- data/lib/slack/web/api/endpoints/users_prefs.rb +1 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +8 -7
- data/lib/slack/web/api/endpoints/views.rb +102 -0
- data/lib/slack/web/api/endpoints/workflows.rb +61 -0
- data/lib/slack/web/api/endpoints.rb +82 -18
- data/lib/slack/web/api/error.rb +1 -0
- data/lib/slack/web/api/errors/server_error.rb +37 -0
- data/lib/slack/web/api/errors/slack_error.rb +14 -1
- data/lib/slack/web/api/errors/too_many_requests_error.rb +2 -4
- data/lib/slack/web/api/errors.rb +1116 -0
- data/lib/slack/web/api/mixins/{channels.id.rb → conversations.id.rb} +5 -6
- data/lib/slack/web/api/mixins/ids.id.rb +3 -2
- data/lib/slack/web/api/mixins/users.id.rb +3 -4
- data/lib/slack/web/api/mixins/users.search.rb +3 -1
- data/lib/slack/web/api/mixins.rb +2 -2
- data/lib/slack/web/api/patches/chat.attachments-blocks.patch +69 -0
- data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
- data/lib/slack/web/api/patches/views.view-json.patch +55 -0
- data/lib/slack/web/api/templates/command.erb +1 -0
- data/lib/slack/web/api/templates/commands.erb +1 -0
- data/lib/slack/web/api/templates/endpoints.erb +2 -2
- data/lib/slack/web/api/templates/errors.erb +20 -0
- data/lib/slack/web/api/templates/method.erb +6 -2
- data/lib/slack/web/api/templates/method_spec.erb +2 -1
- data/lib/slack/web/client.rb +2 -1
- data/lib/slack/web/config.rb +5 -2
- data/lib/slack/web/faraday/connection.rb +24 -20
- data/lib/slack/web/faraday/request.rb +5 -1
- data/lib/slack/web/faraday/response/raise_error.rb +14 -7
- data/lib/slack/web/faraday/response/wrap_error.rb +24 -0
- data/lib/slack/web/pagination/cursor.rb +7 -7
- data/lib/slack-ruby-client.rb +12 -5
- data/lib/slack.rb +1 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/lib/tasks/git.rake +1 -0
- data/lib/tasks/real_time.rake +51 -21
- data/lib/tasks/update.rake +1 -0
- data/lib/tasks/web.rake +48 -12
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-client.gemspec +7 -12
- data/spec/fixtures/slack/web/429_error.yml +50 -54
- data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
- data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
- data/spec/fixtures/slack/web/conversations_info.yml +167 -0
- data/spec/fixtures/slack/web/conversations_setTopic.yml +84 -0
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +172 -0
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +253 -0
- data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
- data/spec/fixtures/slack/web/rtm_connect.yml +347 -26
- data/spec/fixtures/slack/web/users_info.yml +153 -69
- data/spec/fixtures/slack/web/users_list.yml +102 -41
- data/spec/fixtures/slack/web/views_open_error.yml +83 -0
- data/spec/integration/integration_spec.rb +115 -47
- data/spec/slack/config_spec.rb +2 -0
- data/spec/slack/events/config_spec.rb +35 -0
- data/spec/slack/events/request_spec.rb +188 -0
- data/spec/slack/messages/formatting_spec.rb +35 -13
- data/spec/slack/real_time/api/message_spec.rb +7 -2
- data/spec/slack/real_time/api/ping_spec.rb +3 -1
- data/spec/slack/real_time/api/typing_spec.rb +6 -2
- data/spec/slack/real_time/client_spec.rb +300 -142
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +2 -0
- data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/event_handlers/bot_spec.rb +20 -17
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +3 -2
- data/spec/slack/real_time/event_handlers/im_spec.rb +31 -27
- data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +36 -27
- data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +31 -24
- data/spec/slack/real_time/event_handlers/team_spec.rb +8 -7
- data/spec/slack/real_time/event_handlers/user_spec.rb +7 -5
- data/spec/slack/real_time/rtm_connect_spec.rb +2 -1
- data/spec/slack/real_time/stores/store_spec.rb +50 -0
- data/spec/slack/slack_spec.rb +41 -6
- 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 +13 -0
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -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_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 +41 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +67 -0
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -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_manifest_spec.rb +36 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → auth_teams_spec.rb} +2 -1
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -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/custom_specs/auth_spec.rb +9 -7
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +144 -40
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +18 -6
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +8 -3
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +112 -0
- data/spec/slack/web/api/endpoints/dnd_spec.rb +4 -3
- 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 +18 -4
- data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -22
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/openid_connect_spec.rb +8 -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/{apps_permissions_scopes_spec.rb → team_billing_spec.rb} +2 -1
- data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -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/tooling_tokens_spec.rb +13 -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 +1 -0
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
- data/spec/slack/web/api/error_spec.rb +7 -7
- data/spec/slack/web/api/errors/slack_error_spec.rb +26 -7
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +45 -0
- data/spec/slack/web/api/mixins/users_spec.rb +19 -8
- data/spec/slack/web/api/pagination/cursor_spec.rb +47 -15
- data/spec/slack/web/client_spec.rb +199 -22
- data/spec/slack/web/faraday/request_spec.rb +80 -0
- data/spec/slack/web/faraday/response/raise_error_spec.rb +48 -12
- data/spec/spec_helper.rb +9 -2
- data/spec/support/queue_with_timeout.rb +5 -4
- data/spec/support/real_time/concurrency/mock.rb +1 -0
- data/spec/support/real_time/connected_client.rb +6 -6
- data/spec/support/real_time/event.rb +1 -0
- data/spec/support/real_time/loaded_client.rb +120 -0
- data/spec/support/token.rb +1 -0
- data/spec/support/vcr.rb +37 -1
- metadata +174 -262
- data/.travis.yml +0 -32
- data/bin/commands/apps_permissions.rb +0 -22
- data/bin/commands/apps_permissions_resources.rb +0 -14
- data/bin/commands/apps_permissions_scopes.rb +0 -12
- data/bin/commands/apps_permissions_users.rb +0 -25
- data/bin/commands/channels.rb +0 -175
- data/bin/commands/groups.rb +0 -174
- data/bin/commands/im.rb +0 -67
- data/bin/commands/mpim.rb +0 -65
- 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_celluloid/Procfile +0 -2
- data/examples/hi_real_time_async_celluloid/hi.rb +0 -35
- data/examples/hi_real_time_async_eventmachine/Gemfile +0 -6
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/examples/hi_real_time_async_eventmachine/hi.rb +0 -35
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -118
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -66
- data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -35
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -30
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -20
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -49
- data/lib/slack/web/api/endpoints/channels.rb +0 -266
- data/lib/slack/web/api/endpoints/groups.rb +0 -265
- data/lib/slack/web/api/endpoints/im.rb +0 -113
- data/lib/slack/web/api/endpoints/mpim.rb +0 -108
- data/lib/slack/web/api/endpoints/presence.rb +0 -23
- data/lib/slack/web/api/mixins/channels.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.rb +0 -26
- 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 -21
- data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +0 -17
- data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +0 -13
- data/screenshots/register-bot.png +0 -0
- data/spec/fixtures/slack/web/503_error.yml +0 -14
- data/spec/fixtures/slack/web/channels_info.yml +0 -46
- data/spec/fixtures/slack/web/groups_info.yml +0 -43
- data/spec/fixtures/slack/web/rtm_start.yml +0 -104
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -106
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -47
- data/spec/slack/real_time/rtm_start_spec.rb +0 -13
- data/spec/slack/real_time/store_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -15
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -100
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/im_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -38
- data/spec/slack/web/api/errors/service_unavailable_spec.rb +0 -14
- data/spec/slack/web/api/mixins/channels_spec.rb +0 -33
- data/spec/slack/web/api/mixins/groups_spec.rb +0 -33
data/README.md
CHANGED
|
@@ -2,23 +2,75 @@ Slack Ruby Client
|
|
|
2
2
|
=================
|
|
3
3
|
|
|
4
4
|
[](http://badge.fury.io/rb/slack-ruby-client)
|
|
5
|
-
[](https://github.com/slack-ruby/slack-ruby-client/actions/workflows/integtest.yml)
|
|
6
|
+
[](https://github.com/slack-ruby/slack-ruby-client/actions/workflows/test.yml)
|
|
6
7
|
[](https://codeclimate.com/github/slack-ruby/slack-ruby-client)
|
|
7
8
|
|
|
8
|
-
A Ruby client for the Slack [Web](https://api.slack.com/web)
|
|
9
|
+
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
10
|
|
|
10
11
|

|
|
11
12
|
|
|
13
|
+
# Table of Contents
|
|
14
|
+
|
|
15
|
+
- [Useful to Me?](#useful-to-me)
|
|
16
|
+
- [Stable Release](#stable-release)
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [Usage](#usage)
|
|
19
|
+
- [Create a New Bot Integration](#create-a-new-bot-integration)
|
|
20
|
+
- [OAuth Code Grant](#oauth-code-grant)
|
|
21
|
+
- [Using the Legacy API Token](#using-the-legacy-api-token)
|
|
22
|
+
- [Global Settings](#global-settings)
|
|
23
|
+
- [Web Client](#web-client)
|
|
24
|
+
- [Web Client Examples](#web-client-examples)
|
|
25
|
+
- [Test Auth](#test-auth)
|
|
26
|
+
- [Send Messages](#send-messages)
|
|
27
|
+
- [List Channels](#list-channels)
|
|
28
|
+
- [Upload a File](#upload-a-file)
|
|
29
|
+
- [Get Channel Info](#get-channel-info)
|
|
30
|
+
- [Get User Info](#get-user-info)
|
|
31
|
+
- [Search for a User](#search-for-a-user)
|
|
32
|
+
- [Other](#other)
|
|
33
|
+
- [Web Client Options](#web-client-options)
|
|
34
|
+
- [Pagination Support](#pagination-support)
|
|
35
|
+
- [Character Encoding](#character-encoding)
|
|
36
|
+
- [Error Handling](#error-handling)
|
|
37
|
+
- [Slack Errors](#slack-errors)
|
|
38
|
+
- [Rate Limiting](#rate-limiting)
|
|
39
|
+
- [Other Errors](#other-errors)
|
|
40
|
+
- [RealTime Client](#realtime-client)
|
|
41
|
+
- [Configuring Slack::RealTime::Client](#configuring-slackrealtimeclient)
|
|
42
|
+
- [Caveats](#caveats)
|
|
43
|
+
- [websocket_ping](#websocket_ping)
|
|
44
|
+
- [RealTime Store](#realtime-store)
|
|
45
|
+
- [Slack::RealTime::Stores::Starter](#slackrealtimestoresstarter)
|
|
46
|
+
- [Slack::RealTime::Stores::Store](#slackrealtimestoresstore)
|
|
47
|
+
- [Combining RealTime and Web Clients](#combining-realtime-and-web-clients)
|
|
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, 2.0.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
|
22
74
|
|
|
23
75
|
## Installation
|
|
24
76
|
|
|
@@ -28,10 +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 'async-websocket'
|
|
86
|
+
gem 'async-websocket', '~> 0.8.0'
|
|
35
87
|
```
|
|
36
88
|
|
|
37
89
|
Run `bundle install`.
|
|
@@ -40,11 +92,17 @@ Run `bundle install`.
|
|
|
40
92
|
|
|
41
93
|
### Create a New Bot Integration
|
|
42
94
|
|
|
43
|
-
|
|
95
|
+
To integrate your bot with Slack, you must first create a new [Slack App](https://api.slack.com/apps).
|
|
96
|
+
|
|
97
|
+

|
|
98
|
+
|
|
99
|
+
### OAuth Code Grant
|
|
100
|
+
|
|
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).
|
|
44
102
|
|
|
45
|
-
|
|
103
|
+
### Using the Legacy API Token
|
|
46
104
|
|
|
47
|
-
|
|
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.
|
|
48
106
|
|
|
49
107
|
```ruby
|
|
50
108
|
Slack.configure do |config|
|
|
@@ -67,14 +125,18 @@ logger | An optional logger, defaults to `::Logger.new(STDOUT)` at `Logger
|
|
|
67
125
|
|
|
68
126
|
The Slack Web API allows you to build applications that interact with Slack.
|
|
69
127
|
|
|
70
|
-
####
|
|
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
|
|
71
133
|
|
|
72
134
|
```ruby
|
|
73
135
|
client = Slack::Web::Client.new
|
|
74
136
|
client.auth_test
|
|
75
137
|
```
|
|
76
138
|
|
|
77
|
-
|
|
139
|
+
##### Send Messages
|
|
78
140
|
|
|
79
141
|
Send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
|
|
80
142
|
|
|
@@ -86,17 +148,17 @@ See a fully working example in [examples/hi_web](examples/hi_web/hi.rb).
|
|
|
86
148
|
|
|
87
149
|

|
|
88
150
|
|
|
89
|
-
|
|
151
|
+
##### List Channels
|
|
90
152
|
|
|
91
|
-
List channels with [
|
|
153
|
+
List channels with [conversations_list](https://api.slack.com/methods/conversations.list).
|
|
92
154
|
|
|
93
155
|
```ruby
|
|
94
|
-
channels = client.
|
|
156
|
+
channels = client.conversations_list.channels
|
|
95
157
|
|
|
96
158
|
general_channel = channels.detect { |c| c.name == 'general' }
|
|
97
159
|
```
|
|
98
160
|
|
|
99
|
-
|
|
161
|
+
##### Upload a File
|
|
100
162
|
|
|
101
163
|
Upload a file with [files_upload](https://api.slack.com/methods/files.upload).
|
|
102
164
|
|
|
@@ -111,19 +173,19 @@ client.files_upload(
|
|
|
111
173
|
)
|
|
112
174
|
```
|
|
113
175
|
|
|
114
|
-
|
|
176
|
+
##### Get Channel Info
|
|
115
177
|
|
|
116
|
-
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 `
|
|
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 `conversations_list` in order to locate the channel ID. This invocation can have a cost if you have many Slack channels. In this scenario, we encourage you to use channel id.
|
|
117
179
|
|
|
118
180
|
```ruby
|
|
119
|
-
client.
|
|
181
|
+
client.conversations_info(channel: 'C04KB5X4D') # calls conversations_info
|
|
120
182
|
```
|
|
121
183
|
|
|
122
184
|
```ruby
|
|
123
|
-
client.
|
|
185
|
+
client.conversations_info(channel: '#general') # calls conversations_list followed by conversations_info
|
|
124
186
|
```
|
|
125
187
|
|
|
126
|
-
|
|
188
|
+
##### Get User Info
|
|
127
189
|
|
|
128
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.
|
|
129
191
|
|
|
@@ -135,7 +197,7 @@ client.users_info(user: 'U092BDCLV') # calls users_info
|
|
|
135
197
|
client.users_info(user: '@dblock') # calls users_list followed by users_info
|
|
136
198
|
```
|
|
137
199
|
|
|
138
|
-
|
|
200
|
+
##### Search for a User
|
|
139
201
|
|
|
140
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.
|
|
141
203
|
|
|
@@ -143,7 +205,7 @@ Constructs an in-memory index of users and searches it. If you want to use this
|
|
|
143
205
|
client.users_search(user: 'dblock')
|
|
144
206
|
```
|
|
145
207
|
|
|
146
|
-
|
|
208
|
+
##### Other
|
|
147
209
|
|
|
148
210
|
Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.
|
|
149
211
|
|
|
@@ -176,11 +238,12 @@ timeout | Optional open/read timeout in seconds.
|
|
|
176
238
|
open_timeout | Optional connection open timeout in seconds.
|
|
177
239
|
default_page_size | Optional page size for paginated requests, default is _100_.
|
|
178
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`.
|
|
179
242
|
|
|
180
243
|
You can also pass request options, including `timeout` and `open_timeout` into individual calls.
|
|
181
244
|
|
|
182
245
|
```ruby
|
|
183
|
-
client.
|
|
246
|
+
client.conversations_list(request: { timeout: 180 })
|
|
184
247
|
```
|
|
185
248
|
|
|
186
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).
|
|
@@ -213,13 +276,59 @@ end
|
|
|
213
276
|
all_members # many thousands of team members retrieved 10 at a time
|
|
214
277
|
```
|
|
215
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
|
+
|
|
216
297
|
#### Error Handling
|
|
217
298
|
|
|
218
|
-
|
|
299
|
+
##### Slack Errors
|
|
219
300
|
|
|
220
|
-
If
|
|
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
|
+
```
|
|
221
308
|
|
|
222
|
-
|
|
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
|
+
When Slack is temporarily unavailable a subclass of `Slack::Web::Api::Errors::ServerError` will be raised and the original `Faraday::Error` will be accesible via `exception.cause`. (Starting with 0.18.0 this is no longer a subclass of `Slack::Web::Api::Errors::SlackError`.)
|
|
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.
|
|
223
332
|
|
|
224
333
|
### RealTime Client
|
|
225
334
|
|
|
@@ -235,9 +344,9 @@ end
|
|
|
235
344
|
client.on :message do |data|
|
|
236
345
|
case data.text
|
|
237
346
|
when 'bot hi' then
|
|
238
|
-
client.message
|
|
347
|
+
client.message(channel: data.channel, text: "Hi <@#{data.user}>!")
|
|
239
348
|
when /^bot/ then
|
|
240
|
-
client.message
|
|
349
|
+
client.message(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
|
|
241
350
|
end
|
|
242
351
|
end
|
|
243
352
|
|
|
@@ -264,32 +373,7 @@ You can send a ping with `ping`.
|
|
|
264
373
|
client.ping
|
|
265
374
|
```
|
|
266
375
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
property | description
|
|
270
|
-
---------|-------------------------------------------------------------------------------------------------
|
|
271
|
-
url | A WebSocket Message Server URL.
|
|
272
|
-
self | The authenticated bot user.
|
|
273
|
-
team | Details on the authenticated user's team.
|
|
274
|
-
users | A hash of user objects by user ID.
|
|
275
|
-
channels | A hash of channel objects, one for every channel visible to the authenticated user.
|
|
276
|
-
groups | A hash of group objects, one for every group the authenticated user is in.
|
|
277
|
-
ims | A hash of IM objects, one for every direct message channel visible to the authenticated user.
|
|
278
|
-
bots | Details of the integrations set up on this team.
|
|
279
|
-
|
|
280
|
-
It also tracks changes, such as users being renamed, added or deleted, therefore `client.users` is always up-to-date.
|
|
281
|
-
|
|
282
|
-
Tracking with a local store can be disabled with `Slack::RealTime::Client.new(store_class: nil)`. Other stores are also available.
|
|
283
|
-
|
|
284
|
-
#### Slack::RealTime::Stores::Store
|
|
285
|
-
|
|
286
|
-
The default store that tracks all changes. By default the client will be connected using `rtm_start`.
|
|
287
|
-
|
|
288
|
-
#### Slack::RealTime::Stores::Starter
|
|
289
|
-
|
|
290
|
-
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`.
|
|
291
|
-
|
|
292
|
-
### Configuring Slack::RealTime::Client
|
|
376
|
+
#### Configuring Slack::RealTime::Client
|
|
293
377
|
|
|
294
378
|
You can configure the RealTime client either globally or via the initializer.
|
|
295
379
|
|
|
@@ -308,28 +392,79 @@ The following settings are supported.
|
|
|
308
392
|
setting | description
|
|
309
393
|
----------------|-----------------------------------------------------------------------------------------------------
|
|
310
394
|
token | Slack API token.
|
|
311
|
-
websocket_ping |
|
|
395
|
+
websocket_ping | How long the socket can be idle before sending a ping message to confirm it's still connected, default is 30.
|
|
312
396
|
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
397
|
+
start_options | Options to pass to `rtm.connect`, default is `{ request: { timeout: 180 } }`.
|
|
398
|
+
store_class | Local store class, default is an in-memory `Slack::RealTime::Stores::Starter`.
|
|
399
|
+
store_options | Options to initialize the store, default is `{}`.
|
|
316
400
|
logger | Optional `Logger` instance that logs RealTime requests and socket data.
|
|
317
401
|
|
|
318
|
-
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.
|
|
402
|
+
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [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.
|
|
319
403
|
|
|
320
|
-
See a fully working example in [examples/
|
|
404
|
+
See a fully working example in [examples/hi_real_time_and_web](examples/hi_real_time_and_web/hi.rb).
|
|
321
405
|
|
|
322
|
-

|
|
323
407
|
|
|
324
|
-
|
|
408
|
+
##### Caveats
|
|
325
409
|
|
|
326
|
-
|
|
410
|
+
###### `websocket_ping`
|
|
327
411
|
|
|
412
|
+
This setting determines how long the socket can be idle before sending a ping message to confirm it's still connected.
|
|
413
|
+
|
|
414
|
+
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.
|
|
415
|
+
|
|
416
|
+
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.
|
|
417
|
+
|
|
418
|
+
To disable this feature set `websocket_ping` to 0.
|
|
419
|
+
|
|
420
|
+
#### RealTime Store
|
|
421
|
+
|
|
422
|
+
The RealTime client exposes and maintains a local store upon successful connection.
|
|
423
|
+
Event hooks keep the store's cached data up-to-date.
|
|
424
|
+
|
|
425
|
+
Tracking with a local store can be disabled with `Slack::RealTime::Client.new(store_class: nil)`.
|
|
426
|
+
|
|
427
|
+
##### `Slack::RealTime::Stores::Starter`
|
|
428
|
+
|
|
429
|
+
A small store that only caches and tracks data returned in the [rtm.connect](https://api.slack.com/methods/rtm.connect#examples) response.
|
|
430
|
+
This store provides `self` and `team` for accessing the limited data about the authenticated user and its workspace, but does not cache other users or bots, channels, or direct messages.
|
|
431
|
+
|
|
432
|
+
##### `Slack::RealTime::Stores::Store`
|
|
433
|
+
|
|
434
|
+
A more complete store that tracks most changes visible to the authenticated user.
|
|
435
|
+
|
|
436
|
+
You can see all of the cache types in the table below (each is a hash indexed by its objects' `id`).
|
|
437
|
+
|
|
438
|
+
Cache | Description
|
|
439
|
+
-------------------|-------------------------------------------------------------------------------------------------
|
|
440
|
+
`teams` | Workspaces (teams). Will likely contain only one `team`.
|
|
441
|
+
`users` | All [user](https://api.slack.com/types/user) objects, including `self`.
|
|
442
|
+
`bots` | All [bot users](https://api.slack.com/bot-users) (from Slack Apps and legacy custom integrations).
|
|
443
|
+
`public_channels` | Public [conversation](https://api.slack.com/types/conversation) objects.
|
|
444
|
+
`private_channels` | Private [conversation](https://api.slack.com/types/conversation) and [group](https://api.slack.com/types/group) objects with the authenticated user as a member.
|
|
445
|
+
`ims` | Visible [im](https://api.slack.com/types/im) objects, direct message channels with the authenticated user.
|
|
446
|
+
`mpims` | Visible [mpim](https://api.slack.com/types/mpim) objects, multiparty direct message channels that include the authenticated user.
|
|
447
|
+
|
|
448
|
+
By default, none of these caches are initialized with data beyond what is returned from [rtm.connect](https://api.slack.com/methods/rtm.connect#examples), same as [Slack::RealTime::Stores::Starter](#slackrealtimestoresstarter).
|
|
449
|
+
When configured, this store initializes its caches by making additional calls to Web API methods upon successful connection to the RTM API (i.e. "hello" message).
|
|
450
|
+
|
|
451
|
+
Configure by specifying which caches to fetch:
|
|
328
452
|
```ruby
|
|
329
453
|
Slack::RealTime::Client.configure do |config|
|
|
330
|
-
config.
|
|
454
|
+
config.store_class = Slack::RealTime::Stores::Store
|
|
455
|
+
config.store_options = { caches: %i[teams users public_channels private_channels ims] }
|
|
331
456
|
end
|
|
332
457
|
```
|
|
458
|
+
or with the `:all` option:
|
|
459
|
+
```ruby
|
|
460
|
+
Slack::RealTime::Client.configure do |config|
|
|
461
|
+
config.store_class = Slack::RealTime::Stores::Store
|
|
462
|
+
config.store_options = { caches: :all }
|
|
463
|
+
end
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Note: For `teams`, this makes a single call to `team.info`, while for `users` and all conversation-like types, this makes paginated calls to `users.list` and `conversations.list` respectively.
|
|
467
|
+
Only `bots` requires a separate call for every bot user, so may be slow if your workplace has a lot of bot users.
|
|
333
468
|
|
|
334
469
|
### Combining RealTime and Web Clients
|
|
335
470
|
|
|
@@ -341,9 +476,9 @@ client = Slack::RealTime::Client.new
|
|
|
341
476
|
client.on :message do |data|
|
|
342
477
|
case data.text
|
|
343
478
|
when 'bot hi' then
|
|
344
|
-
client.web_client.chat_postMessage
|
|
479
|
+
client.web_client.chat_postMessage(channel: data.channel, text: "Hi <@#{data.user}>!")
|
|
345
480
|
when /^bot/ then
|
|
346
|
-
client.web_client.chat_postMessage
|
|
481
|
+
client.web_client.chat_postMessage(channel: data.channel, text: "Sorry <@#{data.user}>, what?")
|
|
347
482
|
end
|
|
348
483
|
end
|
|
349
484
|
|
|
@@ -354,26 +489,9 @@ See a fully working example in [examples/hi_real_time_and_web](examples/hi_real_
|
|
|
354
489
|
|
|
355
490
|

|
|
356
491
|
|
|
357
|
-
### Large Team Considerations
|
|
358
|
-
|
|
359
|
-
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.
|
|
360
|
-
|
|
361
|
-
```ruby
|
|
362
|
-
Slack::RealTime::Client.configure do |config|
|
|
363
|
-
# Return timestamp only for latest message object of each channel.
|
|
364
|
-
config.start_options[:simple_latest] = true
|
|
365
|
-
# Skip unread counts for each channel.
|
|
366
|
-
config.start_options[:no_unreads] = true
|
|
367
|
-
# Increase request timeout to 6 minutes.
|
|
368
|
-
config.start_options[:request][:timeout] = 360
|
|
369
|
-
end
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a discussion on this topic.
|
|
373
|
-
|
|
374
492
|
#### Concurrency
|
|
375
493
|
|
|
376
|
-
`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async)
|
|
494
|
+
`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async).
|
|
377
495
|
|
|
378
496
|
```ruby
|
|
379
497
|
Slack::RealTime.configure do |config|
|
|
@@ -381,7 +499,7 @@ Slack::RealTime.configure do |config|
|
|
|
381
499
|
end
|
|
382
500
|
```
|
|
383
501
|
|
|
384
|
-
Use `client.start_async` instead of `client.start!`. A good example of such application is [slack-bot-server](https://github.com/
|
|
502
|
+
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).
|
|
385
503
|
|
|
386
504
|
```ruby
|
|
387
505
|
client = Slack::RealTime::Client.new
|
|
@@ -391,7 +509,7 @@ client.start_async
|
|
|
391
509
|
|
|
392
510
|
##### Async
|
|
393
511
|
|
|
394
|
-
|
|
512
|
+
Add `async-websocket` to your Gemfile.
|
|
395
513
|
|
|
396
514
|
```
|
|
397
515
|
gem 'async-websocket'
|
|
@@ -399,27 +517,44 @@ gem 'async-websocket'
|
|
|
399
517
|
|
|
400
518
|
See a fully working example in [examples/hi_real_time_async_async](examples/hi_real_time_async_async/hi.rb).
|
|
401
519
|
|
|
402
|
-
|
|
520
|
+
### Events API
|
|
403
521
|
|
|
404
|
-
|
|
522
|
+
This library provides limited support for the [Slack Events API](https://api.slack.com/events-api).
|
|
405
523
|
|
|
406
|
-
|
|
407
|
-
|
|
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
|
|
408
532
|
```
|
|
409
533
|
|
|
410
|
-
|
|
534
|
+
The following settings are supported.
|
|
411
535
|
|
|
412
|
-
|
|
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`.
|
|
413
540
|
|
|
414
|
-
|
|
541
|
+
#### Verifying the Request Signature
|
|
415
542
|
|
|
416
|
-
|
|
417
|
-
|
|
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!
|
|
418
548
|
```
|
|
419
549
|
|
|
420
|
-
|
|
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
|
+
```
|
|
421
556
|
|
|
422
|
-
|
|
557
|
+
The `verify!` call may raise `Slack::Events::Request::MissingSigningSecret`, `Slack::Events::Request::InvalidSignature` or `Slack::Events::Request::TimestampExpired` errors.
|
|
423
558
|
|
|
424
559
|
### Message Parsing
|
|
425
560
|
|
|
@@ -509,6 +644,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
|
|
|
509
644
|
|
|
510
645
|
## Copyright and License
|
|
511
646
|
|
|
512
|
-
Copyright (c) 2015-
|
|
647
|
+
Copyright (c) 2015-2021, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
|
|
513
648
|
|
|
514
649
|
This project is licensed under the [MIT License](LICENSE.md).
|
data/RELEASING.md
CHANGED
|
@@ -11,7 +11,7 @@ bundle install
|
|
|
11
11
|
rake
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Check that the last build succeeded in [
|
|
14
|
+
Check that the last build succeeded in [GitHub Actions](https://github.com/slack-ruby/slack-ruby-client/actions) for all supported platforms.
|
|
15
15
|
|
|
16
16
|
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
|
|
21
21
|
|
|
22
22
|
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
|
23
23
|
|
|
24
|
-
In the "Stable Release" section of the README, change `**next**` to `**stable**` so users know that they are reading the documentation for a released version.
|
|
24
|
+
In the "Stable Release" section of the README, change `**next**` to `**stable**` and add the version number so users know that they are reading the documentation for a released version.
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
## Stable Release
|
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
|
|
18
|
+
task default: %i[spec rubocop]
|
|
18
19
|
|
|
19
20
|
load 'tasks/git.rake'
|
|
20
21
|
load 'tasks/web.rake'
|