Skip to main content

Initialize a Socket-Mode Connection

Slack's Socket Mode allows Slack apps to use Slack's Events API and interactive features — without the AutoKitteh server having to expose public webhooks for incoming HTTP callbacks from Slack. Instead, AutoKitteh initiates a stateful WebSocket connection.

Overview

info

When should you use "Socket Mode"?

  • AutoKitteh projects that need to be deployed behind a firewall, or have security constraints that don't allow exposing static HTTP endpoints
  • AutoKitteh projects that require special Slack permissions and events (either broader or narrower than the AutoKitteh server's generic OAuth-based Slack app)
  • AutoKitteh projects that require custom slash commands

When should you not use "Socket Mode"?

  • AutoKitteh projects without the limitations above, i.e. the AutoKitteh server's generic OAuth-based Slack app is configured and sufficient, so there's no need to create another Slack app from scratch

  • Production-grade, high-availability AutoKitteh projects

    Attention

    There are production risks and limitations associated with "Socket Mode" connections:

    • WebSocket connections need to remain open all the time, unlike HTTP requests to a passive webhook which are transactional:

      • This limits the total number of available connections per server

      • This precludes stateless failover and load balancing across servers

    • Ensuring that AutoKitteh doesn't miss Slack events while refreshing a WebSocket connection requires more than one WebSocket connections per Slack connection - this is not implemented yet in AutoKitteh

    • Supporting high loads of incoming Slack events requires a dynamic pool of WebSocket connections - this is not implemented yet in AutoKitteh

    • Slack allows no more than 10 open WebSocket connections per app at the same time

Create a Slack App

  1. Click here: create a new Slack app

  2. Select the option "From an app manifest"

    Screenshot 1: Create an app
  3. Pick a workspace to develop the app in, and click the green "Next" button

    Screenshot 2: Pick a workspace
  4. Switch from JSON to YAML

    Screenshot 3: Default YAML app manifest
  5. Replace the default app manifest YAML with this:

display_information:
name: AutoKitteh Demo App

features:
bot_user:
display_name: AutoKitteh
always_online: true
slash_commands:
- command: /autokitteh
description: Send command to AutoKitteh
should_escape: true
- command: /ak
description: Send command to AutoKitteh
should_escape: true

oauth_config:
scopes:
bot:
- app_mentions:read
- bookmarks:read
- bookmarks:write
- channels:history
- channels:manage
- channels:read
- chat:write
- chat:write.customize
- chat:write.public
- commands
- dnd:read
- groups:history
- groups:read
- groups:write
- im:history
- im:read
- im:write
- mpim:history
- mpim:read
- mpim:write
- reactions:read
- reactions:write
- users.profile:read
- users:read
- users:read.email

settings:
event_subscriptions:
bot_events:
- app_home_opened
- app_mention
- app_uninstalled
- channel_archive
- channel_created
- channel_deleted
- channel_history_changed
- channel_id_changed
- channel_left
- channel_rename
- channel_unarchive
- group_archive
- group_deleted
- group_history_changed
- group_left
- group_rename
- group_unarchive
- im_history_changed
- member_joined_channel
- message.channels
- message.groups
- message.im
- message.mpim
- reaction_added
- reaction_removed
- tokens_revoked
interactivity:
is_enabled: true
org_deploy_enabled: false
socket_mode_enabled: true
token_rotation_enabled: false
  1. You may edit these details within the YAML app manifest:

    • display_information.name
    • features
      • bot_user.display_name
      • slash_commands - add/edit/remove commands according to your preferences
    • oauth_config.scopes.bot - remove any scopes (i.e. permissions) that you don't want AutoKitteh to have
      • Warning: don't remove the scope users:read, AutoKitteh requires it to determine Slack app IDs by calling the API method bots.info
    • settings.event_subscriptions.bot_events - add/remove bot events according to your preferences
  2. Click the green "Next" button

  3. Click the green "Create" button

    Screenshot 4: Review summary and create your app

Install the Slack App

  1. Click the green "Install to Workspace" button

    Screenshot 5: Install to Workspace
  2. Click the green "Allow" button

    Screenshot 6: Approve scopes

Post-Creation Settings

  1. In the app's "Basic Information" page, scroll down to the "App-Level Tokens" section

    Screenshot 7: App-Level Tokens
  2. Click the "Generate Token and Scopes" button

    Screenshot 8: Generate an app-level token
    • Type a name for the token
    • Click the "Add Scope" button
    • Select the connections:write scope
    • Click the green "Generate" button
  3. Click the "Copy" button to copy the app-level token (xapp-...) for later, and click the "Done" button

    Screenshot 9: Copy the app-level token
  4. Click "Install App" under "Settings" in the left panel, and then click the "Copy" button to copy the bot token (xoxb-...) for later

    Screenshot 10: Bot user OAuth token
  5. Click "App Home" under "Features" in the left panel

    Screenshot 11: App Home
  6. Scroll down the page to the "Show Tabs" section, and check the checkbox "Allow users to send Slash commands and messages from the messages tab"

    Screenshot 12: Allow users to send slash commands

Initialize an AutoKitteh Connection

  1. Paste the bot token (xoxb-...) from step 4 in the Post-Creation Settings section above

  2. Paste the app-level token (xapp-...) from step 3 in the Post-Creation Settings section above

  3. Click the "Save Connection" button