Deploy and run your Telegram bot on Azure-based serverless architecture. This simple platform will handle bot requests /start
and /stop
to register Telegram conversation in a Storage Account blob so that it can be used to send messages to chats.
- (Optional) Get a custom domain. Freenom is a good starting point to obtain a domain for free.
- Deploy infrastructure on Azure: edit the file
.cicd/parameters/dev.json
, then run a deployment on ARM. You can use Azure CLI or Az Powershell. You will now have a resource group with a Key Vault, a Storage Account, an Azure Function and some other resources. - Follow the instructions to create a new Telegram bot and retrieve the bot token.
- Edit the Azure Function configuration and add an entry
cfg-secret-telegram-bot-token
with the token, or create a secret in the Key Vault calledtelegram-bot-token
. - Set up the bot to use webhooks on the bot endpoint, you can use the script
setup.py
after editing it. If you don't want to use a certificate, comment out that part. - Deploy the Azure Function.
To run locally create a file local.settings.json
in the bot
folder. Set it up in this way:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "{CONNECTION_STRING_TO_STORAGE_ACCOUNT}",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobs.BotEndpoint.Disabled": "false",
"cfg-config-core-mainkeyvault": "az-serverless-bot",
"cfg-config-core-mainstorage": "az-serverless-bot",
"cfg-secret-telegram-bot-token": "{TELEGRAM_BOT_TOKEN}"
}
}
Run the Azure Function and use ngrok to obtain a temporary public endpoint that exposes the local endpoint. Update the Telegram bot to send updates accordingly.