chatgpt-api/docs/slack.md

6.9 KiB

Slack Agentic Service

Intro

Slack is a popular messaging platform for teams. This service provides a simple interface for sending notification messages to Slack channels as part of an Agentic workflow, and optionally to block until a response is received. It is implemented using the Slack Web API.

Pre-requisites

Ensure the following environment variable are set:

  • SLACK_API_KEY: Slack API key
  • SLACK_DEFAULT_CHANNEL: ID of Slack channel to send messages to unless otherwise specified

You may provide these alternatively when instantiating the service via the apiKey and defaultChannel options of the SlackClient constructor.

How to Retrieve an API Key

  1. Go to https://api.slack.com/apps

  2. Click "Create New App".

  3. Use the second option "From an app manifest" so we can reuse a YAML configuration with the required permissions. If you prefer to use the first option, you will need to manually add the required permissions later on under "OAuth & Permissions".

  4. Click on the dropdown menu to select the workspace the application should belong to and click "Next".

  5. Copy the below YAML content into the editor to overwrite the defaults:

    display_information:
      name: AgenticBot
    features:
      bot_user:
        display_name: AgenticBot
        always_online: false
    oauth_config:
      scopes:
        bot:
          - channels:history
          - channels:read
          - chat:write
          - chat:write.public
          - channels:join
    settings:
      org_deploy_enabled: false
      socket_mode_enabled: false
      token_rotation_enabled: false
    

    Feel free to choose a different name and change the scopes as needed. The scopes above are the minimum required for the Agentic Slack service to function. Click "Next" when you are done.

  6. Review the OAuth scopes and enabled features and proceed by clicking "Create"

  7. Click "Install to Workspace" to install your application to your workspace:

  8. Almost there! To obtain the API key for the Agentic Service, click "OAuth & Permissions" in the left navigation menu of the Slack Dashboard of your application and scroll down to the "OAuth Tokens for Your Workspace" section.

  9. Click "Copy" to copy the Bot User OAuth API Key to your clipboard.

How to Retrieve Channel ID

  1. Right-click the channel name in the left sidebar to which you want to send messages. Below, we use the private channel of the created app to avoid cluttering other channels and to not have others receive and respond to messages sent by an Agentic workflow. However, you may use any channel the created Slack application has access to.

  2. Click on "View app details" or "View channel details" in the dropdown menu.

  3. Click on the "Copy channel id" icon button next to the "Channel ID" to copy the ID to your clipboard.