Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • URL shortener
    • Ingesting data into storage systems
    • Storing application runtime logs
    • Deploying a web application using the Java Servlet API
    • Developing a Slack bot
    • Developing a Telegram bot
    • Developing a Telegram bot with AI agent support
    • Developing a custom integration in API Gateway
    • Developing CRUD APIs for movie services
    • Building a CI/CD pipeline in GitLab
    • GitLab Runner execution in Serverless Containers
    • Configuring CI/CD between Cloud Functions and SourceCraft
    • Configuring CI/CD between Cloud Functions and GitHub
    • Setting up CI/CD in SourceCraft to deploy an application in Serverless Containers using GitHub Actions
    • Working with an API gateway via WebSocket
    • Building an interactive serverless application using WebSocket
    • Automatically copying objects from one Object Storage bucket to another
    • Visualizing logs in Grafana using the Cloud Logging plugin
    • Canary release of Cloud Functions
    • Interactive debugging of Cloud Functions
    • Creating a Node.js function using TypeScript
    • Running a containerized app in Serverless Containers
    • Streaming Yandex Cloud Postbox events to Data Streams and analyzing them with DataLens
    • Using API Gateway to set up speech synthesis in SpeechKit
    • Connecting to YDB from a Cloud Functions function in Python
    • Connecting to a YDB database from a Cloud Functions function in Node.js
    • API Gateway protection with Smart Web Security
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Automatic data upload to Yandex SpeechSense using Yandex Workflows
    • Configuring responses in Cloud Logging and Yandex Cloud Functions
    • Setting up Workflows integration with Tracker, YandexGPT, and Yandex Cloud Postbox
    • Developing functions in Functions Framework and deploying them to Yandex Serverless Containers
    • Creating a Yandex Cloud Postbox address and checking domain ownership with Terraform
    • Creating an AI agent with Yandex Cloud Functions
    • Configuring Postfix to send emails via Yandex Cloud Postbox
    • Yandex Cloud Postbox integration with external systems via webhooks

In this article:

  • Getting started
  • Required paid resources
  • Set up your environment
  • Create an application and connect it to Yandex Cloud
  • Register your Slack app
  • Configure a link between Slack and Yandex Cloud
  • Test the link between Slack and Yandex Cloud
  • Get a token and a secret for your app
  • Create functions
  • Messaging function
  • Command response function
  • Modify the API gateway
  • Add a command to Slack
  • Test your Slack bot
  • How to delete the resources you created
  1. Serverless technologies
  2. Developing a Slack bot

How to create a Slack chat bot

Written by
Yandex Cloud
Updated at August 14, 2025
  • Getting started
    • Required paid resources
  • Set up your environment
  • Create an application and connect it to Yandex Cloud
    • Register your Slack app
    • Configure a link between Slack and Yandex Cloud
    • Test the link between Slack and Yandex Cloud
  • Get a token and a secret for your app
  • Create functions
    • Messaging function
    • Command response function
  • Modify the API gateway
  • Add a command to Slack
  • Test your Slack bot
  • How to delete the resources you created

In this tutorial, you will learn how to use serverless technology to create a Slack bot that will run commands in a chat and respond to user messages.

To create a bot:

  1. Set up your environment.
  2. Create an application and connect it to Yandex Cloud.
  3. Get a token and a secret for your app.
  4. Create functions.
  5. Modify the API gateway.
  6. Add commands to Slack.
  7. Test your Slack bot.

Getting startedGetting started

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The cost of bot support includes:

  • Fee for using the API gateway (see Yandex API Gateway pricing).
  • Fee for using functions (see Yandex Cloud Functions pricing).

Set up your environmentSet up your environment

  1. Download the file archive required to create a bot.
  2. If you do not have a folder yet, create one.
  3. Create a service account named sa-slack and assign it the editor role for your folder.

Create an application and connect it to Yandex CloudCreate an application and connect it to Yandex Cloud

Register your Slack appRegister your Slack app

  1. Log in to Slack. To create a bot, make sure you have workspace admin permissions.

  2. Create an app:

    1. Click Create an App.
    2. Select From scratch.
    3. In the App Name field, enter the name for your app: ServerlessBotApp.
    4. Select the available workspace and click Create App.
  3. Grant permissions to ServerlessBotApp:

    1. In the app menu, select Features → OAuth & Permissions.
    2. Under Scopes → Bot Token Scopes, click Add an OAuth Scope and add the following permissions: chat:write, commands, and im:history.
  4. Install the application: in the app menu, select Settings → Install App and click Install to Workspace → Allow.

Configure a link between Slack and Yandex CloudConfigure a link between Slack and Yandex Cloud

  1. Create a function named for-slack-bot-challenge. Make sure it is private.

  2. Create a function version:

    1. Specify the following settings:

      • Runtime environment: python312.
      • Entry point: index.handler.
      • Timeout: 5.
      • Service account: Service account you created earlier (sa-slack).
    2. Create a file named index.py and paste into it the contents of the 0_for-slack-bot-challenge.py file from the archive.

  3. Create an API gateway:

    1. Enter for-slack-bot as the name.

    2. In the Specification field, add the POST method configuration to the paths parameter:

      paths:
        /:
          get:
            x-yc-apigateway-integration:
              type: dummy
              content:
                '*': Hello, World!
              http_code: 200
              http_headers:
                Content-Type: text/plain
          post:
            x-yc-apigateway-integration:
              type: cloud_functions
              function_id: <function_ID>
              service_account_id: <service_account_ID>
              operationId: slack-challenge
      

      Where:

      • function_id: for-slack-bot-challenge function ID.
      • service_account_id: sa-slack service account ID.

Test the link between Slack and Yandex CloudTest the link between Slack and Yandex Cloud

  1. Copy the for-slack-bot API gateway service domain.
  2. Select the app you created: ServerlessBotApp.
  3. In the app menu, select Features → Event Subscriptions.
  4. Check Enable Events.
  5. In the Request URL field, paste the API gateway address and wait for Verified to appear.
  6. Under Subscribe to bot events, click Add Bot User Event and select message.im.
  7. Click Save Changes.

Get a token and a secret for your appGet a token and a secret for your app

Select the app you created: ServerlessBotApp.

  1. In the app menu, select Settings → Basic Information.
  2. Copy the Signing Secret value from the App Credentials section: this value will be used for the SLACK_SIGNING_SECRET environment variable.
  3. In the app menu, select Features → OAuth & Permissions.
  4. In the OAuth Tokens for Your Workspace section, copy the Bot User OAuth Token value: it will be used for the SLACK_BOT_TOKEN environment variable.

Create functionsCreate functions

Using functions, you can set up the bot’s responses to user actions within the chat. In this tutorial, you will create the following functions:

  • For messaging between the bot and the user.
  • For getting the bot's response to a simple command.

Messaging functionMessaging function

  1. Create a function named for-slack-bot-small-talk. Make sure it is private.

  2. Create a function version:

    1. Specify the following settings:

      • Runtime environment: python312.
      • Entry point: index.handler.
      • Timeout: 5.
      • Service account: Service account you created earlier (sa-slack).
    2. Create a file named requirements.txt and specify these libraries in it:

      slack_sdk
      slack_bolt
      boto3
      
    3. Create a file named index.py and paste into it the contents of the 1_for-slack-bot-small-talk.py file from the archive.

    4. Add these environment variables:

      • SLACK_BOT_TOKEN.
      • SLACK_SIGNING_SECRET.

Command response functionCommand response function

  1. Create a function named for-slack-bot-hello-from-serverless. Make sure it is private.

  2. Create a function version:

    1. Specify the following settings:

      • Runtime environment: python312.
      • Entry point: index.handler.
      • Timeout: 5.
      • Service account: Service account you created earlier (sa-slack).
    2. Create a file named requirements.txt and specify these libraries in it:

      slack_sdk
      slack_bolt
      boto3
      
    3. Create a file named index.py and paste into it the contents of the 2_for-slack-bot-hello-from-serverless.py file from the archive.

    4. Add these environment variables:

      • SLACK_BOT_TOKEN.
      • SLACK_SIGNING_SECRET.

Modify the API gatewayModify the API gateway

To make sure the bot starts responding to user messages, link the created functions to your app. To do this, update the for-slack-bot API gateway specification and add the POST method configurations to the paths parameter:

  /:
    post:
      x-yc-apigateway-integration:
        type: cloud_functions
        function_id: <function_1_ID>
        service_account_id: <service_account_ID>
        operationId: small-talk
  /hello-from-serverless:
    post:
      x-yc-apigateway-integration:
        type: cloud_functions
        function_id: <function_2_ID>
        service_account_id: <service_account_ID>
        operationId: hello-from-serverless

Where:

  • service_account_id: sa-slack service account ID.
  • <function_1_ID>: for-slack-bot-small-talk function ID.
  • <function_2_ID>: for-slack-bot-hello-from-serverless function ID.

Add a command to SlackAdd a command to Slack

Using commands, you can set up the bot's actions in the chat. Commands start with / and users can always see their full list.

Note

The command will not work without the relevant method configured in the API gateway.

  1. Select the app you created: ServerlessBotApp.

  2. In the app menu, select Features → Slash Commands and click Create New Command.

  3. Add a command for the for-slack-bot-hello-from-serverless function:

    • In the Command field, enter /hello-from-serverless.
    • In the Request URL field, paste the url from the for-slack-bot API gateway specification, adding the /hello-from-serverless command URL to it.
    • In the Short descriptions field, enter a brief description for the command.
    • Click Save.
  4. Re-install the application: in the app menu, select Settings → Install App and click Reinstall to Workspace → Allow.

  5. Enable users to send messages: in the app menu, select Features → App Home and enable Allow users to send Slash commands and messages from the messages tab under Show Tabs.

Test your Slack botTest your Slack bot

Open Slack and select a chat with ServerlessBotApp under Apps.

  1. To test the for-slack-bot-small-talk function:
    • Send :wave: to the chat. The bot should respond with Hi there, @<username>!.
    • Send knock knock to the chat. The bot should respond with Who's there?.
  2. To test the for-slack-bot-hello-from-serverless function, send the /hello-from-serverless command to the chat. The bot should respond with Thanks!.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  • Delete the API gateway.
  • Delete the functions.

Was the article helpful?

Previous
Deploying a web application using the Java Servlet API
Next
Developing a Telegram bot
© 2025 Direct Cursus Technology L.L.C.