slack-ruby-client 0.11.0 → 2.7.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 +5 -5
- data/.coveralls.yml +2 -0
- data/.github/FUNDING.yml +2 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/integration_test.yml +45 -0
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/pr_lint.yml +21 -0
- data/.github/workflows/test.yml +56 -0
- data/.github/workflows/update_api.yml +81 -0
- data/.gitignore +7 -3
- data/.rubocop.yml +40 -2
- data/.rubocop_todo.yml +209 -55
- data/.ruby-version +1 -0
- data/CHANGELOG.md +257 -30
- data/CONTRIBUTING.md +44 -29
- data/Dangerfile +2 -0
- data/Gemfile +28 -6
- data/Gemfile.danger +6 -0
- data/LICENSE.md +1 -1
- data/README.md +473 -134
- data/RELEASING.md +2 -2
- data/Rakefile +2 -1
- data/SECURITY.md +9 -0
- data/UPGRADING.md +117 -3
- data/bin/commands/admin_analytics.rb +22 -0
- data/bin/commands/admin_apps.rb +57 -0
- data/bin/commands/admin_apps_activities.rb +32 -0
- data/bin/commands/admin_apps_approved.rb +24 -0
- data/bin/commands/admin_apps_config.rb +31 -0
- data/bin/commands/admin_apps_requests.rb +35 -0
- data/bin/commands/admin_apps_restricted.rb +24 -0
- data/bin/commands/admin_audit_anomaly_allow.rb +29 -0
- data/bin/commands/admin_auth_policy.rb +45 -0
- data/bin/commands/admin_barriers.rb +53 -0
- data/bin/commands/admin_conversations.rb +260 -0
- data/bin/commands/admin_conversations_ekm.rb +23 -0
- data/bin/commands/admin_conversations_restrictAccess.rb +43 -0
- data/bin/commands/admin_emoji.rb +60 -0
- data/bin/commands/admin_functions.rb +23 -0
- data/bin/commands/admin_functions_permissions.rb +31 -0
- data/bin/commands/admin_inviteRequests.rb +42 -0
- data/bin/commands/admin_inviteRequests_approved.rb +22 -0
- data/bin/commands/admin_inviteRequests_denied.rb +22 -0
- data/bin/commands/admin_roles.rb +46 -0
- data/bin/commands/admin_teams.rb +33 -0
- data/bin/commands/admin_teams_admins.rb +22 -0
- data/bin/commands/admin_teams_owners.rb +22 -0
- data/bin/commands/admin_teams_settings.rb +70 -0
- data/bin/commands/admin_usergroups.rb +54 -0
- data/bin/commands/admin_users.rb +106 -0
- data/bin/commands/admin_users_session.rb +84 -0
- data/bin/commands/admin_users_unsupportedVersions.rb +21 -0
- data/bin/commands/admin_workflows.rb +42 -0
- data/bin/commands/admin_workflows_collaborators.rb +31 -0
- data/bin/commands/admin_workflows_permissions.rb +21 -0
- data/bin/commands/admin_workflows_triggers_types_permissions.rb +31 -0
- data/bin/commands/api.rb +15 -9
- data/bin/commands/apps.rb +21 -0
- data/bin/commands/apps_activities.rb +32 -0
- data/bin/commands/apps_auth_external.rb +32 -0
- data/bin/commands/apps_connections.rb +19 -0
- data/bin/commands/apps_datastore.rb +116 -0
- data/bin/commands/apps_event_authorizations.rb +22 -0
- data/bin/commands/apps_manifest.rb +58 -0
- data/bin/commands/assistant_search.rb +27 -0
- data/bin/commands/assistant_threads.rb +45 -0
- data/bin/commands/auth.rb +22 -15
- data/bin/commands/auth_teams.rb +22 -0
- data/bin/commands/bookmarks.rb +60 -0
- data/bin/commands/bots.rb +16 -8
- data/bin/commands/calls.rb +58 -0
- data/bin/commands/calls_participants.rb +31 -0
- data/bin/commands/canvases.rb +41 -0
- data/bin/commands/canvases_access.rb +34 -0
- data/bin/commands/canvases_sections.rb +21 -0
- data/bin/commands/chat.rb +158 -99
- data/bin/commands/chat_scheduledMessages.rb +25 -0
- data/bin/commands/conversations.rb +241 -157
- data/bin/commands/conversations_canvases.rb +22 -0
- data/bin/commands/conversations_externalInvitePermissions.rb +22 -0
- data/bin/commands/conversations_requestSharedInvite.rb +48 -0
- data/bin/commands/dialog.rb +16 -9
- data/bin/commands/dnd.rb +47 -38
- data/bin/commands/emoji.rb +15 -7
- data/bin/commands/files.rb +113 -87
- data/bin/commands/files_comments.rb +16 -30
- data/bin/commands/files_remote.rb +84 -0
- data/bin/commands/functions.rb +31 -0
- data/bin/commands/functions_distributions_permissions.rb +61 -0
- data/bin/commands/functions_workflows_steps.rb +23 -0
- data/bin/commands/functions_workflows_steps_responses.rb +23 -0
- data/bin/commands/migration.rb +17 -9
- data/bin/commands/oauth.rb +19 -24
- data/bin/commands/oauth_v2.rb +35 -0
- data/bin/commands/openid_connect.rb +33 -0
- data/bin/commands/pins.rb +33 -30
- data/bin/commands/reactions.rb +53 -45
- data/bin/commands/reminders.rb +54 -41
- data/bin/commands/rtm.rb +16 -22
- data/bin/commands/search.rb +44 -33
- data/bin/commands/stars.rb +39 -29
- data/bin/commands/team.rb +50 -34
- data/bin/commands/team_billing.rb +19 -0
- data/bin/commands/team_externalTeams.rb +35 -0
- data/bin/commands/team_preferences.rb +19 -0
- data/bin/commands/team_profile.rb +15 -8
- data/bin/commands/tooling_tokens.rb +20 -0
- data/bin/commands/usergroups.rb +69 -53
- data/bin/commands/usergroups_users.rb +30 -19
- data/bin/commands/users.rb +114 -84
- data/bin/commands/users_admin.rb +29 -22
- data/bin/commands/users_discoverableContacts.rb +20 -0
- data/bin/commands/users_prefs.rb +14 -7
- data/bin/commands/users_profile.rb +27 -20
- data/bin/commands/views.rb +56 -0
- data/bin/commands/workflows.rb +44 -0
- data/bin/commands/workflows_triggers_permissions.rb +60 -0
- data/bin/slack +50 -46
- data/examples/files_upload_v2/.env.example +1 -0
- data/examples/{hi_real_time → files_upload_v2}/Gemfile +2 -2
- data/examples/files_upload_v2/README.md +13 -0
- data/examples/files_upload_v2/files_upload_v2.rb +45 -0
- 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_eventmachine → hi_real_time_async_async}/Gemfile +2 -1
- data/examples/{hi_real_time_async_eventmachine → hi_real_time_async_async}/hi.rb +12 -7
- 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/examples/oauth_v2/.env.example +4 -0
- data/examples/oauth_v2/Gemfile +7 -0
- data/examples/oauth_v2/README.md +33 -0
- data/examples/oauth_v2/oauth_v2.rb +60 -0
- data/lib/slack/config.rb +2 -2
- data/lib/slack/events/config.rb +32 -0
- data/lib/slack/events/request.rb +76 -0
- data/lib/slack/logger.rb +6 -5
- data/lib/slack/messages/formatting.rb +66 -1
- 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 +117 -54
- data/lib/slack/real_time/concurrency/async.rb +142 -0
- data/lib/slack/real_time/concurrency.rb +2 -2
- data/lib/slack/real_time/config.rb +12 -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 +49 -17
- data/lib/slack/real_time/stores/base.rb +28 -14
- data/lib/slack/real_time/stores/starter.rb +325 -287
- data/lib/slack/real_time/stores/store.rb +271 -186
- data/lib/slack/real_time/stores.rb +2 -7
- data/lib/slack/utils/security.rb +44 -0
- 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_activities.rb +53 -0
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +37 -0
- data/lib/slack/web/api/endpoints/admin_apps_config.rb +40 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +53 -0
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +37 -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 +397 -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_functions.rb +36 -0
- data/lib/slack/web/api/endpoints/admin_functions_permissions.rb +41 -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_roles.rb +73 -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 +167 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +121 -0
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/admin_workflows.rb +67 -0
- data/lib/slack/web/api/endpoints/admin_workflows_collaborators.rb +42 -0
- data/lib/slack/web/api/endpoints/admin_workflows_permissions.rb +26 -0
- data/lib/slack/web/api/endpoints/admin_workflows_triggers_types_permissions.rb +41 -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_activities.rb +54 -0
- data/lib/slack/web/api/endpoints/apps_auth_external.rb +41 -0
- data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_datastore.rb +181 -0
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
- data/lib/slack/web/api/endpoints/apps_manifest.rb +79 -0
- data/lib/slack/web/api/endpoints/assistant_search.rb +44 -0
- data/lib/slack/web/api/endpoints/assistant_threads.rb +68 -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 +90 -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/canvases.rb +54 -0
- data/lib/slack/web/api/endpoints/canvases_access.rb +47 -0
- data/lib/slack/web/api/endpoints/canvases_sections.rb +27 -0
- data/lib/slack/web/api/endpoints/chat.rb +172 -87
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +40 -0
- data/lib/slack/web/api/endpoints/conversations.rb +190 -64
- data/lib/slack/web/api/endpoints/conversations_canvases.rb +28 -0
- data/lib/slack/web/api/endpoints/conversations_externalInvitePermissions.rb +31 -0
- data/lib/slack/web/api/endpoints/conversations_requestSharedInvite.rb +73 -0
- data/lib/slack/web/api/endpoints/dialog.rb +6 -10
- data/lib/slack/web/api/endpoints/dnd.rb +11 -5
- data/lib/slack/web/api/endpoints/emoji.rb +3 -0
- data/lib/slack/web/api/endpoints/files.rb +85 -36
- 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/functions.rb +43 -0
- data/lib/slack/web/api/endpoints/functions_distributions_permissions.rb +84 -0
- data/lib/slack/web/api/endpoints/functions_workflows_steps.rb +30 -0
- data/lib/slack/web/api/endpoints/functions_workflows_steps_responses.rb +30 -0
- data/lib/slack/web/api/endpoints/migration.rb +6 -3
- data/lib/slack/web/api/endpoints/oauth.rb +10 -32
- 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 +31 -20
- data/lib/slack/web/api/endpoints/reminders.rb +25 -12
- data/lib/slack/web/api/endpoints/rtm.rb +4 -22
- data/lib/slack/web/api/endpoints/search.rb +33 -18
- data/lib/slack/web/api/endpoints/stars.rb +23 -10
- data/lib/slack/web/api/endpoints/team.rb +38 -7
- data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
- data/lib/slack/web/api/endpoints/team_externalTeams.rb +53 -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 +44 -25
- data/lib/slack/web/api/endpoints/usergroups_users.rb +23 -14
- data/lib/slack/web/api/endpoints/users.rb +57 -18
- data/lib/slack/web/api/endpoints/users_admin.rb +5 -2
- data/lib/slack/web/api/endpoints/users_discoverableContacts.rb +24 -0
- data/lib/slack/web/api/endpoints/users_prefs.rb +2 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +11 -9
- data/lib/slack/web/api/endpoints/views.rb +86 -0
- data/lib/slack/web/api/endpoints/workflows.rb +63 -0
- data/lib/slack/web/api/endpoints/workflows_triggers_permissions.rb +87 -0
- data/lib/slack/web/api/endpoints.rb +136 -12
- 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 +1396 -0
- data/lib/slack/web/api/helpers/files.rb +97 -0
- data/lib/slack/web/api/helpers.rb +13 -0
- data/lib/slack/web/api/mixins/conversations.id.rb +47 -0
- data/lib/slack/web/api/mixins/ids.id.rb +4 -3
- data/lib/slack/web/api/mixins/users.id.rb +18 -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/options.rb +26 -0
- data/lib/slack/web/api/patches/.gitkeep +0 -0
- data/lib/slack/web/api/templates/command.erb +19 -12
- 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 +23 -3
- data/lib/slack/web/api/templates/method_spec.erb +40 -3
- data/lib/slack/web/client.rb +4 -1
- data/lib/slack/web/config.rb +9 -2
- data/lib/slack/web/faraday/connection.rb +11 -20
- data/lib/slack/web/faraday/options.rb +24 -0
- data/lib/slack/web/faraday/request.rb +6 -1
- data/lib/slack/web/faraday/response/raise_error.rb +14 -8
- 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 +18 -6
- 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 +43 -17
- data/slack-ruby-client.gemspec +10 -14
- metadata +191 -307
- data/.travis.yml +0 -30
- data/bin/commands/apps_permissions.rb +0 -22
- data/bin/commands/channels.rb +0 -175
- data/bin/commands/groups.rb +0 -172
- data/bin/commands/im.rb +0 -67
- data/bin/commands/mpim.rb +0 -63
- data/bin/commands.rb +0 -33
- 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/hi.rb +0 -36
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -117
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -60
- data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -35
- data/lib/slack/web/api/endpoints/channels.rb +0 -265
- data/lib/slack/web/api/endpoints/groups.rb +0 -255
- data/lib/slack/web/api/endpoints/im.rb +0 -113
- data/lib/slack/web/api/endpoints/mpim.rb +0 -98
- 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/channels.id.rb +0 -26
- 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/dialog.1.open-json-support.patch +0 -17
- data/lib/slack/web/api/templates/commands.erb +0 -5
- data/screenshots/register-bot.png +0 -0
- data/spec/fixtures/slack/web/429_error.yml +0 -85
- data/spec/fixtures/slack/web/auth_test_error.yml +0 -48
- data/spec/fixtures/slack/web/auth_test_success.yml +0 -57
- 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/paginated_users_list.yml +0 -181
- data/spec/fixtures/slack/web/rtm_connect.yml +0 -70
- data/spec/fixtures/slack/web/rtm_start.yml +0 -104
- data/spec/fixtures/slack/web/users_info.yml +0 -130
- data/spec/fixtures/slack/web/users_list.yml +0 -72
- data/spec/integration/integration_spec.rb +0 -139
- data/spec/slack/config_spec.rb +0 -14
- data/spec/slack/messages/formatting_spec.rb +0 -43
- data/spec/slack/real_time/api/message_spec.rb +0 -15
- data/spec/slack/real_time/api/ping_spec.rb +0 -15
- data/spec/slack/real_time/api/typing_spec.rb +0 -15
- data/spec/slack/real_time/client_spec.rb +0 -425
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -62
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -47
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +0 -19
- data/spec/slack/real_time/event_handlers/bot_spec.rb +0 -44
- data/spec/slack/real_time/event_handlers/channel_spec.rb +0 -116
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +0 -15
- data/spec/slack/real_time/event_handlers/group_spec.rb +0 -90
- data/spec/slack/real_time/event_handlers/im_spec.rb +0 -47
- data/spec/slack/real_time/event_handlers/team_spec.rb +0 -62
- data/spec/slack/real_time/event_handlers/user_spec.rb +0 -63
- data/spec/slack/real_time/rtm_connect_spec.rb +0 -13
- data/spec/slack/real_time/rtm_start_spec.rb +0 -13
- data/spec/slack/real_time/store_spec.rb +0 -11
- data/spec/slack/slack_spec.rb +0 -58
- data/spec/slack/version_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/api_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -15
- data/spec/slack/web/api/endpoints/bots_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -100
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +0 -25
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +0 -105
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +0 -28
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +0 -33
- data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -12
- data/spec/slack/web/api/endpoints/emoji_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +0 -34
- data/spec/slack/web/api/endpoints/files_spec.rb +0 -43
- data/spec/slack/web/api/endpoints/im_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/migration_spec.rb +0 -12
- data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -29
- data/spec/slack/web/api/endpoints/pins_spec.rb +0 -22
- data/spec/slack/web/api/endpoints/reactions_spec.rb +0 -17
- data/spec/slack/web/api/endpoints/reminders_spec.rb +0 -30
- data/spec/slack/web/api/endpoints/rtm_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/search_spec.rb +0 -22
- data/spec/slack/web/api/endpoints/stars_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/team_profile_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/team_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +0 -27
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +0 -20
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +0 -17
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +0 -7
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +0 -7
- data/spec/slack/web/api/error_spec.rb +0 -14
- data/spec/slack/web/api/errors/slack_error_spec.rb +0 -14
- data/spec/slack/web/api/mixins/channels_spec.rb +0 -31
- data/spec/slack/web/api/mixins/groups_spec.rb +0 -31
- data/spec/slack/web/api/mixins/users_spec.rb +0 -39
- data/spec/slack/web/api/pagination/cursor_spec.rb +0 -70
- data/spec/slack/web/client_spec.rb +0 -174
- data/spec/spec_helper.rb +0 -14
- data/spec/support/queue_with_timeout.rb +0 -34
- data/spec/support/real_time/concurrency/mock.rb +0 -30
- data/spec/support/real_time/connected_client.rb +0 -21
- data/spec/support/real_time/event.rb +0 -11
- data/spec/support/token.rb +0 -10
- data/spec/support/vcr.rb +0 -9
- /data/examples/{hi_real_time_async_celluloid → hi_real_time_async_async}/Procfile +0 -0
data/bin/slack
CHANGED
@@ -1,52 +1,56 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require 'gli'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
3
|
+
require 'slack_ruby_client'
|
4
|
+
|
5
|
+
module Slack
|
6
|
+
module Cli
|
7
|
+
class App
|
8
|
+
extend GLI::App
|
9
|
+
|
10
|
+
program_desc 'Slack client.'
|
11
|
+
|
12
|
+
default_command :help
|
13
|
+
|
14
|
+
switch %i[d debug], desc: 'Enable debug-level logging.', default_value: false
|
15
|
+
flag [:t, 'slack-api-token'], desc: 'Slack API token.', default_value: ENV['SLACK_API_TOKEN']
|
16
|
+
flag ['vcr-cassette-name'], desc: 'Offline VCR cassette.'
|
17
|
+
|
18
|
+
commands_from File.expand_path('commands', __dir__)
|
19
|
+
|
20
|
+
pre do |global_options, _command, options, _args|
|
21
|
+
# global Slack configuration
|
22
|
+
Slack.config.token = global_options['slack-api-token']
|
23
|
+
help_now! 'Set Slack API token via --slack-api-token or SLACK_API_TOKEN.' unless Slack.config.token && !Slack.config.token.empty?
|
24
|
+
|
25
|
+
if global_options['debug']
|
26
|
+
require 'logger'
|
27
|
+
logger = Logger.new(STDOUT)
|
28
|
+
logger.level = Logger::DEBUG
|
29
|
+
Slack::Web::Client.config.logger = logger
|
30
|
+
end
|
31
|
+
|
32
|
+
@client = Slack::Web::Client.new
|
33
|
+
|
34
|
+
# Offline VCR cassette
|
35
|
+
if global_options['vcr-cassette-name']
|
36
|
+
require 'webmock'
|
37
|
+
WebMock.enable!
|
38
|
+
require 'vcr'
|
39
|
+
VCR.configure do |config|
|
40
|
+
config.cassette_library_dir = 'spec/fixtures/slack'
|
41
|
+
config.hook_into :webmock
|
42
|
+
config.default_cassette_options = { record: :new_episodes }
|
43
|
+
end
|
44
|
+
VCR.insert_cassette global_options['vcr-cassette-name']
|
45
|
+
end
|
46
|
+
|
47
|
+
# remove any nil values from options
|
48
|
+
options.compact!
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
39
52
|
end
|
40
|
-
VCR.insert_cassette global_options['vcr-cassette-name']
|
41
53
|
end
|
42
|
-
|
43
|
-
# remove any nil values from options
|
44
|
-
options.select! { |_k, v| v }
|
45
|
-
|
46
|
-
true
|
47
54
|
end
|
48
55
|
|
49
|
-
|
50
|
-
require 'commands'
|
51
|
-
|
52
|
-
exit run(ARGV)
|
56
|
+
exit Slack::Cli::App.run(ARGV)
|
@@ -0,0 +1 @@
|
|
1
|
+
SLACK_API_TOKEN=
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Samples for using `files_upload_v2`.
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
Create a Slack app and obtain a User OAuth Token [here](https://api.slack.com/tutorials/tracks/getting-a-token) or use the [oauth_v2](../oauth_v2) example to obtain a User OAuth Token.
|
6
|
+
Make sure to select `files:write` and `files:read` scopes under "User Token Scopes".
|
7
|
+
|
8
|
+
Create `.env` file with `SLACK_API_TOKEN` or set the `SLACK_API_TOKEN` environment variable.
|
9
|
+
|
10
|
+
```
|
11
|
+
bundle install
|
12
|
+
bundle exec dotenv ruby files_upload_v2.rb
|
13
|
+
```
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'slack-ruby-client'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
Slack.configure do |config|
|
6
|
+
config.token = ENV['SLACK_API_TOKEN']
|
7
|
+
raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
|
8
|
+
end
|
9
|
+
|
10
|
+
client = Slack::Web::Client.new
|
11
|
+
|
12
|
+
auth = client.auth_test
|
13
|
+
puts "Connected to team #{auth.team} (#{auth.team_id}) as #{auth.user}."
|
14
|
+
|
15
|
+
puts client.files_upload_v2(
|
16
|
+
filename: 'files_upload_v2.txt',
|
17
|
+
content: SecureRandom.hex
|
18
|
+
).files.first.permalink_public
|
19
|
+
|
20
|
+
puts client.files_upload_v2(
|
21
|
+
filename: 'files_upload_v2_to_general_channel.txt',
|
22
|
+
content: SecureRandom.hex,
|
23
|
+
channel: '#general'
|
24
|
+
).files.first.permalink_public
|
25
|
+
|
26
|
+
puts client.files_upload_v2(
|
27
|
+
filename: 'files_upload_v2_to_general_and_random_channels.txt',
|
28
|
+
content: SecureRandom.hex,
|
29
|
+
channels: ['#general', '#random']
|
30
|
+
).files.first.permalink_public
|
31
|
+
|
32
|
+
channel_id = client.conversations_id(channel: '#general')['channel']['id']
|
33
|
+
puts client.files_upload_v2(
|
34
|
+
filename: 'files_upload_v2_to_general_by_id.txt',
|
35
|
+
content: SecureRandom.hex,
|
36
|
+
channel_id: channel_id
|
37
|
+
).files.first.permalink_public
|
38
|
+
|
39
|
+
client.files_upload_v2(
|
40
|
+
files: [
|
41
|
+
{ filename: 'files_upload_v2_to_general_first_file.txt', content: SecureRandom.hex },
|
42
|
+
{ filename: 'files_upload_v2_to_general_second_file.txt', content: SecureRandom.hex }
|
43
|
+
],
|
44
|
+
channels: ['#general']
|
45
|
+
).files.each { |file| puts file.permalink_public }
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'slack-ruby-client'
|
2
3
|
|
3
4
|
Slack.configure do |config|
|
@@ -8,15 +9,18 @@ end
|
|
8
9
|
client = Slack::RealTime::Client.new
|
9
10
|
|
10
11
|
client.on :hello do
|
11
|
-
puts
|
12
|
+
puts(
|
13
|
+
"Successfully connected, welcome '#{client.self.name}' " \
|
14
|
+
"to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
|
15
|
+
)
|
12
16
|
end
|
13
17
|
|
14
18
|
client.on :message do |data|
|
15
19
|
puts data
|
16
20
|
case data.text
|
17
|
-
when 'bot hi'
|
21
|
+
when 'bot hi'
|
18
22
|
client.web_client.chat_postMessage channel: data.channel, text: "Hi <@#{data.user}>!"
|
19
|
-
when /^bot/
|
23
|
+
when /^bot/
|
20
24
|
client.web_client.chat_postMessage channel: data.channel, text: "Sorry <@#{data.user}>, what?"
|
21
25
|
end
|
22
26
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'slack-ruby-client'
|
3
|
+
require 'async'
|
2
4
|
|
3
5
|
raise 'Missing ENV[SLACK_API_TOKENS]!' unless ENV.key?('SLACK_API_TOKENS')
|
4
6
|
|
@@ -6,13 +8,18 @@ $stdout.sync = true
|
|
6
8
|
logger = Logger.new($stdout)
|
7
9
|
logger.level = Logger::DEBUG
|
8
10
|
|
11
|
+
threads = []
|
12
|
+
|
9
13
|
ENV['SLACK_API_TOKENS'].split.each do |token|
|
10
14
|
logger.info "Starting #{token[0..12]} ..."
|
11
15
|
|
12
16
|
client = Slack::RealTime::Client.new(token: token)
|
13
17
|
|
14
18
|
client.on :hello do
|
15
|
-
logger.info
|
19
|
+
logger.info(
|
20
|
+
"Successfully connected, welcome '#{client.self.name}' to " \
|
21
|
+
"the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
|
22
|
+
)
|
16
23
|
end
|
17
24
|
|
18
25
|
client.on :message do |data|
|
@@ -21,16 +28,14 @@ ENV['SLACK_API_TOKENS'].split.each do |token|
|
|
21
28
|
client.typing channel: data.channel
|
22
29
|
|
23
30
|
case data.text
|
24
|
-
when
|
31
|
+
when /hi/
|
25
32
|
client.message channel: data.channel, text: "Hi <@#{data.user}>!"
|
26
|
-
|
33
|
+
else
|
27
34
|
client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?"
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
|
-
client.start_async
|
38
|
+
threads << client.start_async
|
32
39
|
end
|
33
40
|
|
34
|
-
|
35
|
-
Thread.pass
|
36
|
-
end
|
41
|
+
threads.each(&:join)
|
data/examples/hi_web/Gemfile
CHANGED
data/examples/hi_web/hi.rb
CHANGED
data/examples/new_ticket/Gemfile
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
Obtain a user OAuth token from Slack.
|
2
|
+
|
3
|
+
Create a Slack app [here](https://api.slack.com/tutorials/tracks/getting-a-token).
|
4
|
+
|
5
|
+
The new app has a pre-configured User OAuth Token which you can use for most of the examples.
|
6
|
+
However you may want to obtain a token for a different user, which can be accomplished as follows.
|
7
|
+
|
8
|
+
To test locally use [ngrok](https://ngrok.com/) to expose your local server to the internet.
|
9
|
+
|
10
|
+
```sh
|
11
|
+
ngrok http 4242
|
12
|
+
```
|
13
|
+
|
14
|
+
Add the ngrok URL to the app's "Redirect URLs" under "OAuth & Permissions" in the app's settings.
|
15
|
+
|
16
|
+
Create a `.env` file with the following:
|
17
|
+
|
18
|
+
```
|
19
|
+
SLACK_CLIENT_ID=[App Client ID]
|
20
|
+
SLACK_CLIENT_SECRET=[App Client Secret]
|
21
|
+
REDIRECT_URI=[Your ngrok URL, e.g. https://...ngrok-free.app]
|
22
|
+
SCOPE=[Bot User OAuth Scopes Requested]
|
23
|
+
USER_SCOPE=[User OAuth Token Scopes Requested]
|
24
|
+
```
|
25
|
+
|
26
|
+
Run the example.
|
27
|
+
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
bundle exec dotenv ruby oauth_v2.rb
|
31
|
+
```
|
32
|
+
|
33
|
+
A browser window will open to complete the OAuth flow.
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'dotenv/load'
|
5
|
+
require 'webrick'
|
6
|
+
require 'slack-ruby-client'
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/core_ext/object/to_query'
|
9
|
+
|
10
|
+
server = WEBrick::HTTPServer.new(Port: ENV['PORT'] || 4242)
|
11
|
+
|
12
|
+
trap 'INT' do
|
13
|
+
server.shutdown
|
14
|
+
end
|
15
|
+
|
16
|
+
server.mount_proc '/' do |req, res|
|
17
|
+
client = Slack::Web::Client.new
|
18
|
+
|
19
|
+
response = client.oauth_v2_access(
|
20
|
+
req.query.merge(
|
21
|
+
client_id: ENV['SLACK_CLIENT_ID'],
|
22
|
+
client_secret: ENV['SLACK_CLIENT_SECRET'],
|
23
|
+
grant_type: 'authorization_code'
|
24
|
+
)
|
25
|
+
)
|
26
|
+
|
27
|
+
pp response
|
28
|
+
|
29
|
+
res.body = %(
|
30
|
+
<html>
|
31
|
+
<body>
|
32
|
+
<ul>
|
33
|
+
<li>bot access_token: #{response.access_token}</li>
|
34
|
+
<li>token_type: #{response.token_type}</li>
|
35
|
+
<li>app_id: #{response.app_id}</li>
|
36
|
+
<li>scope: #{response.scope}</li>
|
37
|
+
<li>user: #{response.authed_user.id}</li>
|
38
|
+
<li>user access token: #{response.authed_user.access_token}</li>
|
39
|
+
</ul>
|
40
|
+
<body>
|
41
|
+
</html>
|
42
|
+
)
|
43
|
+
|
44
|
+
pp Slack::Web::Client.new(token: response.authed_user.access_token || response.access_token).auth_test
|
45
|
+
|
46
|
+
server.shutdown
|
47
|
+
end
|
48
|
+
|
49
|
+
query = {
|
50
|
+
client_id: ENV['SLACK_CLIENT_ID'],
|
51
|
+
redirect_uri: ENV['REDIRECT_URI'],
|
52
|
+
scope: ENV['SCOPE'],
|
53
|
+
user_scope: ENV['USER_SCOPE']
|
54
|
+
}
|
55
|
+
|
56
|
+
url = "https://slack.com/oauth/v2/authorize?#{query.to_query}"
|
57
|
+
puts "Opening browser at #{url}."
|
58
|
+
system 'open', url
|
59
|
+
|
60
|
+
server.start
|
data/lib/slack/config.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Slack
|
3
|
+
module Events
|
4
|
+
module Config
|
5
|
+
extend self
|
6
|
+
|
7
|
+
ATTRIBUTES = %i[
|
8
|
+
signing_secret
|
9
|
+
signature_expires_in
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
attr_accessor(*Config::ATTRIBUTES)
|
13
|
+
|
14
|
+
def reset
|
15
|
+
self.signing_secret = ENV['SLACK_SIGNING_SECRET']
|
16
|
+
self.signature_expires_in = 5 * 60
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def configure
|
22
|
+
block_given? ? yield(Config) : Config
|
23
|
+
end
|
24
|
+
|
25
|
+
def config
|
26
|
+
Config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Slack::Events::Config.reset
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slack
|
4
|
+
module Events
|
5
|
+
class Request
|
6
|
+
class MissingSigningSecret < StandardError; end
|
7
|
+
|
8
|
+
class TimestampExpired < StandardError; end
|
9
|
+
|
10
|
+
class InvalidSignature < StandardError; end
|
11
|
+
|
12
|
+
attr_reader :http_request,
|
13
|
+
:signing_secret,
|
14
|
+
:signature_expires_in
|
15
|
+
|
16
|
+
def initialize(http_request, options = {})
|
17
|
+
@http_request = http_request
|
18
|
+
@signing_secret = options[:signing_secret] || Slack::Events.config.signing_secret
|
19
|
+
@signature_expires_in =
|
20
|
+
options[:signature_expires_in] || Slack::Events.config.signature_expires_in
|
21
|
+
end
|
22
|
+
|
23
|
+
# Request timestamp.
|
24
|
+
def timestamp
|
25
|
+
@timestamp ||= http_request.get_header('HTTP_X_SLACK_REQUEST_TIMESTAMP')
|
26
|
+
end
|
27
|
+
|
28
|
+
# The signature is created by combining the signing secret with the body of the request
|
29
|
+
# Slack is sending using a standard HMAC-SHA256 keyed hash.
|
30
|
+
def signature
|
31
|
+
@signature ||= http_request.get_header('HTTP_X_SLACK_SIGNATURE')
|
32
|
+
end
|
33
|
+
|
34
|
+
# Signature version.
|
35
|
+
def version
|
36
|
+
'v0'
|
37
|
+
end
|
38
|
+
|
39
|
+
# Request body.
|
40
|
+
def body
|
41
|
+
@body ||= begin
|
42
|
+
input = http_request.body
|
43
|
+
input.rewind
|
44
|
+
body = input.read
|
45
|
+
input.rewind
|
46
|
+
body
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns true if the signature coming from Slack has expired.
|
51
|
+
def expired?
|
52
|
+
timestamp.nil? || (Time.now.to_i - timestamp.to_i).abs > signature_expires_in
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns true if the signature coming from Slack is valid.
|
56
|
+
def valid?
|
57
|
+
raise MissingSigningSecret unless signing_secret
|
58
|
+
raise InvalidSignature unless signature
|
59
|
+
|
60
|
+
digest = OpenSSL::Digest.new('SHA256')
|
61
|
+
signature_basestring = [version, timestamp, body].join(':')
|
62
|
+
hex_hash = OpenSSL::HMAC.hexdigest(digest, signing_secret, signature_basestring)
|
63
|
+
computed_signature = [version, hex_hash].join('=')
|
64
|
+
Utils::Security.secure_compare(computed_signature, signature)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Validates the request signature and its expiration.
|
68
|
+
def verify!
|
69
|
+
raise TimestampExpired if expired?
|
70
|
+
raise InvalidSignature unless valid?
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/slack/logger.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'logger'
|
2
3
|
|
3
4
|
module Slack
|
4
5
|
class Logger < ::Logger
|
5
6
|
def self.default
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
return @default if @default
|
8
|
+
|
9
|
+
logger = new STDOUT
|
10
|
+
logger.level = Logger::WARN
|
11
|
+
@default = logger
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
module Slack
|
3
3
|
module Messages
|
4
4
|
module Formatting
|
@@ -24,6 +24,71 @@ module Slack
|
|
24
24
|
end
|
25
25
|
end)
|
26
26
|
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Escape a message.
|
30
|
+
# @see https://api.slack.com/reference/surfaces/formatting#escaping
|
31
|
+
#
|
32
|
+
def escape(message)
|
33
|
+
message
|
34
|
+
.gsub('&', '&')
|
35
|
+
.gsub('>', '>')
|
36
|
+
.gsub('<', '<')
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Format a DateTime or Time object as a date and time in a Slack message
|
41
|
+
# @see https://api.slack.com/reference/surfaces/formatting#date-formatting
|
42
|
+
#
|
43
|
+
def date(time, format: '{date_num} {time_secs}', link: nil, text: nil)
|
44
|
+
args = [time.to_i, format, link].compact
|
45
|
+
"<!date^#{args.join('^')}|#{text || time}>"
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Embed a link to a Slack channel in a message by channel ID
|
50
|
+
# @see https://api.slack.com/reference/surfaces/formatting#linking-channels
|
51
|
+
#
|
52
|
+
def channel_link(channel_id)
|
53
|
+
"<##{channel_id}>"
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Embed a link to a user in a message by user ID
|
58
|
+
# @see https://api.slack.com/reference/surfaces/formatting#mentioning-users
|
59
|
+
#
|
60
|
+
def user_link(user_id)
|
61
|
+
"<@#{user_id}>"
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Embed a link to a group in a message by group ID
|
66
|
+
# @see https://api.slack.com/reference/surfaces/formatting#mentioning-groups
|
67
|
+
#
|
68
|
+
def group_link(group_id)
|
69
|
+
"<!subteam^#{group_id}>"
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Embed a URL with custom link text in a message
|
74
|
+
# @see https://api.slack.com/reference/surfaces/formatting#linking-urls
|
75
|
+
#
|
76
|
+
def url_link(text, url)
|
77
|
+
"<#{url}|#{text}>"
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Converts text from basic markdown into Slack's mishmash
|
82
|
+
# @see https://api.slack.com/reference/surfaces/formatting#basic-formatting
|
83
|
+
#
|
84
|
+
def markdown(text)
|
85
|
+
text
|
86
|
+
.gsub(/(?<!\*)\*([^*\n]+)\*(?!\*)/, '_\1_') # italic
|
87
|
+
.gsub(/\*\*\*(.*?)\*\*\*/, '*_\1_*') # bold & italic
|
88
|
+
.gsub(/\*\*(.*?)\*\*/, '*\1*') # bold
|
89
|
+
.gsub(/~~(.*?)~~/, '~\1~') # strikethrough
|
90
|
+
.gsub(/\[(.*?)\]\((.*?)\)/, '<\2|\1>') # links
|
91
|
+
end
|
27
92
|
end
|
28
93
|
end
|
29
94
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Slack
|
2
3
|
module RealTime
|
3
4
|
module Api
|
@@ -6,12 +7,14 @@ module Slack
|
|
6
7
|
# Sends a message to a channel.
|
7
8
|
#
|
8
9
|
# @option options [channel] :channel
|
9
|
-
# Channel to send message to. Can be a public channel, private group or IM channel.
|
10
|
+
# Channel to send message to. Can be a public channel, private group or IM channel.
|
11
|
+
# Can be an encoded ID, or a name.
|
10
12
|
# @option options [Object] :text
|
11
13
|
# Text of the message to send. See below for an explanation of formatting.
|
12
14
|
def message(options = {})
|
13
|
-
|
14
|
-
|
15
|
+
raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
|
16
|
+
raise ArgumentError, 'Required arguments :text missing' if options[:text].nil?
|
17
|
+
|
15
18
|
send_json({ type: 'message', id: next_id }.merge(options))
|
16
19
|
end
|
17
20
|
end
|