Simple Telegram bot example on aiogram framework using Yandex Cloud with Webhook
-
First create a bot with telegram "BotFather" and copy
TOKENto your notes -
Go to Yandex Cloud Console
-
Create Yandex Service account in Yandex Cloud with roles
editorandserverless.functions.invoker -
Create Yandex Cloud Function in Yandex Cloud:
- choose programming language, in our case it will be Python
- copy and paste the code from
index.pyto fileindex.pyin Yandex Cloud Function Editor - create file
requirements.txtin Yandex Cloud Function Editor - copy and paste data from
requirements.txtto filerequirements.txtin Yandex Cloud Function Editor - select below Yandex Service account you created earlier
- add variable
TOKENand put your token data there - click
Create function
-
You are back to your Yandex Cloud Function view:
- check the box
Public function✅ - copy the link
PUBLIC_FUNCTION_URLto your public function in notes
- check the box
-
You need to create Webhook:
- put your
TOKENandPUBLIC_FUNCTION_URLin template below 👇 - template:
https://api.telegram.org/botTOKEN/setWebhook?url=PUBLIC_FUNCTION_URL - put this link to your browser and press
enter - you will get this message:
{"ok":true,"result":true,"description":"Webhook was set"}
- put your
-
Send
/startmessage to your bot. Everything should work 🙂