Demo Telegram Bot YandexGPT
A Telegram bot on the Yandex Cloud serverless stack assisted by YandexGPT to reply to questions from users.
Features
- Written in Python with the python-telegram-bot library.
- Does not maintain conversation context.
- Supports skill updates.
What goes into the cost of using the bot
- Fee for access to YandexGPT (see YandexGPT pricing).
- Fee for function invocation count, computing resources allocated to run the function, downtime of provisioned instances, and outgoing traffic (see Yandex Cloud Functions pricing).
- Fee for the number of requests to the created API gateways and outbound traffic (see Yandex API Gateway pricing).
- Fee for the number of requests to standard and FIFO queues and outgoing traffic (see Yandex Message Queue pricing).
- Fee for storing and requesting secrets (see Yandex Lockbox pricing).
-
Register your bot in Telegram and get a token:
- Start the
@BotFatherbot and select the/newbotcommand. - Name your bot, e.g.,
Serverless Echo Telegram Bot. This is the name users will see when talking to the bot. - Name your bot, e.g.,
ServerlessHelloTelegramBot. You can use it to find the bot in Telegram. The username must end withBotor_bot.
In case of success, you will get a welcome message and the bot’s token.
- Start the
-
Create a service account and assign it the
adminrole for the folder. -
Create a Yandex Lockbox secret with keys for the bot and YandexGPT:
-
Under Create secret, in the Name field, specify the secret name, e.g.,
tg_bot_token. -
Under Secret data:
- Select Custom as the secret type.
- To create a key for the bot, specify
BOT_TOKENin the Key field. - In the Value field, specify the bot token you got earlier.
- To create two keys for YandexGPT, specify
GPT_FOLDER_IDandGPT_API_KEYin the Key field. - In the Value field, specify
FOLDER_IDandAPI_KEY, respectively.
Learn how to get an API_KEY for YandexGPT in Authentication with the Yandex Foundation Models API.
-
-
In the management console, go to the folder where you want to deploy the application.
-
Select Cloud Apps.
-
I n the left-hand panel, select Marketplace.
-
Select Demo Telegram Bot YandexGPT and click Use.
-
Specify the following:
- Application name.
- Optionally, application description.
- Service account with the
adminrole for the folder, or select Auto to have the service account created when installing the application. This service account will be used to create the application resources. - ID of the Yandex Lockbox secret you created earlier.
-
Click Install.
-
In the Checking changes window that opens, click Confirm and wait for the installation to complete.
-
On the Overview page, find the
API gatewayunder Application resources, go to the gateway page, and copy the service domain link. -
To bind the function to the Telegram bot, run a request. Replace
<bot_token>with your Telegram bot token, and<API_gateway_domain>with a link to your API gateway’s service domain.-
For Linux/macOS
curl \ --request POST \ --url https://api.telegram.org/bot<bot_token>/setWebhook?url=https://<API_gateway_domain>/echo -
For Windows (cmd)
curl ^ --request POST ^ --url "https://api.telegram.org/bot<bot_token>/setWebhook?url=https://<API_gateway_domain>/echo" -
For Windows (PowerShell)
curl.exe ` --request POST ` --url https://api.telegram.org/bot<bot_token>/setWebhook?url=https://<API_gateway_domain>/echo
Result:
{"ok":true,"result":true,"description":"Webhook was set"} -
-
Send the
/startcommand to the bot in Telegram. Now you can start asking it questions. -
You can conveniently continue developing the bot by cloning the SourceCraft repository cloudapp-tgbot-yandexg and setting up integration with the deployed Cloud App according to the instructions in README.md
Yandex Cloud technical support is available 24/7. The types of requests you can submit and the relevant response times depend on your pricing plan. You can switch to the paid support plan in the management console. You can learn more about the technical support terms and conditions here.
| Resource type | Quantity |
|---|---|
| Service accounts | 4 |
| Service account static access key | 1 |
| Access rights for folder | 7 |
| Message queue | 1 |
| Serverless function | 1 |
| Cloud Functions trigger | 1 |
| API gateway | 1 |