Demo Telegram Bot
A Telegram bot on a Yandex Cloud serverless stack that returns the same message sent by the user. Implemented on Node.js with the Telegraf.js library.
You can modify the Telegram bot’s skills as you see fit.
The cost of resources for the application includes:
- Fee for the number of function calls, computing resources allocated to executing the function, and outgoing traffic (see Yandex Cloud Functions pricing).
- Fee for the number of requests to the API gateway and outgoing traffic (see Yandex API Gateway pricing).
- Fee for standard queue requests (see Yandex Message Queue pricing).
- Secret storage and request fees (see Yandex Lockbox).
-
Register your bot in Telegram and get a token:
- Start the
BotFatherbot and send it the/newbotcommand. - Enter a name for your bot, such as
Serverless Echo Telegram Bot. This is the name users will see when talking to the bot. - Specify a username for your bot, such as
ServerlessHelloTelegramBot. You can use the username to search for the bot in Telegram. The user name must end with...Botor..._bot.
Your Telegram bot’s token will be displayed.
- Start the
-
Create a Yandex Lockbox secret. In the Key field, enter
TG_TOKEN, and in the Value field, enter the returned Telegram bot token. -
In the management console, select the folder where you want to deploy the application.
-
Select Cloud Apps.
-
On the left-hand panel, select Marketplace.
-
Select Demo Telegram Bot and click Use.
-
Specify the following:
- Application name.
- (Optional) 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 previously created Yandex Lockbox secret.
-
Click Install and wait for the installation to complete.
-
On the Overview page, find the API gateway under 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 the
<bot token>with the Telegram bot token and the<API gateway domain>with a link to the API gateway’s service domain.Linux and macOSWindows (cmd)Windows (PowerShell)curl \ --request POST \ --url https://api.telegram.org/bot<bot token>/setWebhook?url=<API_gateway_domain>/echocurl ^ --request POST ^ --url "https://api.telegram.org/bot<bot token>/setWebhook?url=<API_gateway_domain>/echo"curl.exe ` --request POST ` --url https://api.telegram.org/bot<bot token>/setWebhook?url=<API_gateway_domain>/echoResult:
{"ok":true,"result":true,"description":"Webhook was set"} -
Write to the bot on Telegram.
Yandex Cloud technical support responds to requests 24 hours a day, 7 days a week. The types of requests available and their response time depend on your pricing plan. You can activate paid support in the management console. Learn more about requesting technical support.
| Resource type | Quantity |
|---|---|
| Service accounts | 4 |
| Static access key | 1 |
| Folder members | 7 |
| Message Queue | 1 |
| Serverless function | 1 |
| Trigger | 1 |
| API gateway | 1 |