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 app and connect it to Yandex Cloud
  • Register the Slack app
  • Set up a link between Slack and Yandex Cloud
  • Test the link between Slack and Yandex Cloud
  • Get a token and a secret for the app
  • Create functions
  • Function for messaging
  • Function for responding to commands
  • Edit the API gateway
  • Add a command to Slack
  • Test the Slack bot
  • How to delete the resources you created
  1. Tutorials
  2. Developing a Slack bot

Creating a Slack chat bot

Written by
Yandex Cloud
Updated at May 7, 2025
  • Getting started
    • Required paid resources
  • Set up your environment
  • Create an app and connect it to Yandex Cloud
    • Register the Slack app
    • Set up a link between Slack and Yandex Cloud
    • Test the link between Slack and Yandex Cloud
  • Get a token and a secret for the app
  • Create functions
    • Function for messaging
    • Function for responding to commands
  • Edit the API gateway
  • Add a command to Slack
  • Test the Slack bot
  • How to delete the resources you created

In this tutorial, you will learn how to use serverless technologies 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 the app.
  4. Create functions.
  5. Edit the API gateway.
  6. Add commands to Slack.
  7. Test the 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 app and connect it to Yandex CloudCreate an app and connect it to Yandex Cloud

Register the Slack appRegister the Slack app

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

  2. Create an app:

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

    1. In the app control 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 control menu, select Settings → Install App and click Install to Workspace → Allow.

Set up a link between Slack and Yandex CloudSet up 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 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's service domain.
  2. Select the ServerlessBotApp app.
  3. In the app control menu, select Features → Event Subscriptions.
  4. Enable the Enable Events option.
  5. In the Request URL field, paste the API gateway address and wait for the Verified entry to appear.
  6. Under Subscribe to bot events, click Add Bot User Event and select the message.im event.
  7. Click Save Changes.

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

Select the ServerlessBotApp app:

  1. In the app control 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 control 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 configure the bot's reactions to user actions in 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.

Function for messagingFunction for messaging

  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

Function for responding to commandsFunction for responding to commands

  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

Edit the API gatewayEdit the API gateway

To make sure the bot starts responding to user messages, link the created functions to the app. To do this, edit 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 their list is always visible to the user.

Note

A command will not work if the relevant method is not configured for it in the API gateway.

  1. Select the ServerlessBotApp app.

  2. In the app control 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 any short description of the command.
    • Click Save.
  4. Re-install the application: in the app control menu, select Settings → Install App and click Reinstall to Workspace → Allow.

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

Test the Slack botTest the Slack bot

Open the Slack client and select a chat with the ServerlessBotApp bot under Apps.

  1. To test the for-slack-bot-small-talk function:
    • Send the :wave: message to the chat. The bot must respond with: Hi there, @<username>!.
    • Send the knock knock message 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 in 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