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
    • ML Services
    • 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
      • Implementing an AI assistant with search capabilities for PDF files with complex formatting
      • Integrating Qwen3 into Visual Studio Code as a coding assistant
      • Creating an AI assistant for Telegram

In this article:

  • Getting started
  • Required paid resources
  • Set up your infrastructure
  • Create a folder
  • Create a service account for the DataSphere project
  • Add the service account to the project
  • Create an API key for the service account
  • Create a Telegram bot
  • Create secrets
  • Clone the repository
  • Run the notebook
  • Test the bot
  • How to delete the resources you created
  1. Machine learning and artificial intelligence
  2. Using Yandex AI Studio generative models
  3. Creating an AI assistant for Telegram

Creating a Telegram bot with RAG and function calling

Written by
Yandex Cloud
Updated at September 23, 2025
  • Getting started
    • Required paid resources
  • Set up your infrastructure
    • Create a folder
    • Create a service account for the DataSphere project
    • Add the service account to the project
  • Create an API key for the service account
  • Create a Telegram bot
  • Create secrets
  • Clone the repository
  • Run the notebook
  • Test the bot
  • How to delete the resources you created

Language models can maintain conversation context and perform knowledge base search using Yandex Cloud ML SDK, RAG, and AI Assistant API.

In this tutorial, you will create a wine sales chat assistant based on the YandexGPT 5 model. The assistant relies on function calling and RAG to access the database of wines and regions as well as the price list indicating wines in stock. You will configure the assistant in a Yandex DataSphere notebook and interact with it via Telegram.

To create an AI assistant for Telegram:

  1. Set up your infrastructure.
  2. Create an API key for the service account.
  3. Create a Telegram bot.
  4. Create secrets.
  5. Clone the repository.
  6. Test the bot.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Before getting started, register in Yandex Cloud, set up a community, and link your billing account to it.

  1. On the DataSphere home page, click Try for free and select an account to log in with: Yandex ID or your working account with the identity federation (SSO).
  2. Select the Yandex Identity Hub organization you are going to use in Yandex Cloud.
  3. Create a community.
  4. Link your billing account to the DataSphere community you are going to work in. Make sure you have a linked billing account and its status is ACTIVE or TRIAL_ACTIVE. If you do not have a billing account yet, create one in the DataSphere interface.

Required paid resourcesRequired paid resources

The infrastructure support cost for creating an AI assistant includes:

  • Fee for using DataSphere computing resources.
  • Fee for text generation by the model.

Set up your infrastructureSet up your infrastructure

Log in to the Yandex Cloud management console and select the organization you use to access DataSphere. On the Yandex Cloud Billing page, make sure you have a billing account linked.

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

Note

If you are using an identity federation to work with Yandex Cloud, you might not have access to billing details. In this case, contact your Yandex Cloud organization administrator.

Create a folderCreate a folder

Management console
  1. In the management console, select a cloud and click Create folder.
  2. Name your folder, e.g., data-folder.
  3. Click Create.

Create a service account for the DataSphere projectCreate a service account for the DataSphere project

You need to create a service account to access the model from the notebook.

Management console
  1. Navigate to data-folder.
  2. On the left-hand panel, click All services and select Identity and Access Management, or find it using the search bar on the dashboard.
  3. Click Create service account.
  4. Enter a name for the service account, e.g., gpt-user.
  5. Click Add role and assign the ai.languageModels.user role to the service account.
  6. Click Create.

Add the service account to the projectAdd the service account to the project

To enable the service account to access the model from the notebook, add it to the list of project members.

Management console
  1. Select the project in your community or on the DataSphere home page in the Recent projects tab.

  2. In the Members tab, click Add member.
  3. Select the gpt-user account and click Add.

Create an API key for the service accountCreate an API key for the service account

To enable the service account to access the model, create an API key.

Management console
  1. In the management console, navigate to data-folder.
  2. On the left-hand panel, click All services and select Identity and Access Management, or find it using the search bar on the dashboard.
  3. In the left-hand panel, select Service accounts.
  4. In the list that opens, select the gpt-user service account.
  5. In the top panel, click Create new key and select Create API key.
  6. In the Scope field, select yc.ai.languageModels.execute.
  7. Click Create.
  8. Save the ID and secret key.

Create a Telegram botCreate a Telegram bot

  1. Open a chat with @botfather.
  2. Follow the prompts to choose a name and nickname for your Telegram bot.
  3. After the bot is created successfully, you will receive a link to the chat with your bot and a token. Save them for the next steps.

Create secretsCreate secrets

To use the API key, folder ID, and bot access token from the notebook, create secrets with the relevant values.

  1. Select the project in your community or on the DataSphere home page in the Recent projects tab.

  2. Under Project resources, select Secret.
  3. Click Create.
  4. In the Name field, enter the name for the secret: api_key.
  5. In the Value field, paste the key ID.
  6. Click Create.
  7. Similarly, create two more secrets: folder_id with the folder ID and tg_token with the Telegram bot token.

Clone the repositoryClone the repository

  1. Select the project in your community or on the DataSphere home page in the Recent projects tab.

  2. Click Open project in JupyterLab and wait until loading is complete.
  3. On the left-hand panel, under File Browser, create or select the folder to store the repository clone and navigate to it.
  4. In the top menu, click Git and select Clone a Repository.
  5. In the window that opens, enter the repository URI, https://github.com/yandex-cloud-examples/yc-ai-wine-assistant.
  6. Enable the Download the repository option and click Clone.

Run the notebookRun the notebook

The notebook code connects to the model, provides it with the relevant functions, and configures the Telegram bot.

  1. Navigate to the cloned repository folder.
  2. Open the advanced-assistant.ipynb notebook.
  3. Run the notebook cells one by one. Do not run cells in the Deleting unused resources section until you finish using the bot.
  4. The last cell under Creating a wine assistant in Telegram will get your bot ready to run.

Test the botTest the bot

  1. Open the chat with your bot using the link you got earlier.

  2. Click START.

  3. Enter your query in the message input field. Here is an example:

    What wine pairs well with white chocolate?
    

    Result:

    White chocolate may go well with white and rosé dessert or fortified wines. Consider options like Chardonnay, Sémillon, Riesling, or Viognier. If you are interested in a specific wine, I can check its availability and price in our price list.
    

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

To stop paying for the resources you created, delete the project.

Was the article helpful?

Previous
Integrating Qwen3 into Visual Studio Code as a coding assistant
© 2025 Direct Cursus Technology L.L.C.