Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Cloud Functions
  • Comparison with other Yandex Cloud services
    • All tutorials
    • Creating a skill for Alice
    • Deploying a web application
    • Creating a skill for Alice and a website with authorization
    • Writing data from a device into a database
    • Writing load balancer logs to PostgreSQL
    • Developing a Slack bot
    • Developing a Telegram bot
    • Connecting to a YDB database from a Python function
    • Connecting to a YDB database from a function in Node.js
    • Converting a video to a GIF in Python
    • Creating a Node.js function using TypeScript
    • Developing a custom integration
    • Creating a budget trigger that invokes a function to stop a VM
    • Creating an interactive serverless application using WebSocket
    • Automatically copying objects from one Object Storage bucket to another
    • Running computations on a schedule in DataSphere
    • Interactive debugging of functions
    • Regular asynchronous recognition of audio files from Object Storage
    • Canary release of a Cloud Functions function
    • Deploying a fault-tolerant architecture with preemptible VMs
    • Creating triggers that invoke a function to stop a VM and send a Telegram notification
    • Loading data from Yandex Direct to a data mart enabled by Yandex Managed Service for ClickHouse® using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Status monitoring of geographically distributed devices
    • Sensor reading monitoring and event notifications
    • Emulating multiple IoT devices
    • Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them using Yandex DataLens
    • URL shortener
    • Yandex Tracker: data export and visualization
    • Running computations in DataSphere using the API
    • Developing a Telegram bot for text and audio recognition
    • Configuring responses in Yandex Cloud Logging and Cloud Functions
    • Developing functions in Functions Framework and deploying them to Yandex Serverless Containers
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

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. Tutorials
  2. Developing a Slack bot

How to create a Slack chat bot

Written by
Yandex Cloud
Updated at June 3, 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 in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register 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 to operate in.

Learn more about clouds and folders.

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
Writing load balancer logs to PostgreSQL
Next
Developing a Telegram bot
Yandex project
© 2025 Yandex.Cloud LLC