Using Webhook method to setup Telegram Bot through Flask.
- Python 3
- Flask
- Telegram
- Request
- Ngrok (optional)
Note: It is recommended to use Ngrok to speed up development prior to hosting it on Heroku or any cloud services.
- Go to
@botfatheron Telegram to create a bot handle. - Type
/newbotto create a new bot. - Name your bot e.g. EXAMPLE
- Username of your bot e.g EXAMPLEBOT - This is the @username handle that can be search by users on Telegram
- Once done, copy the token generated and add to the script
TOKENvariable.
- Change
WEBHOOK_URLto the hosting URL (this must be HTTPS). - Update Telegram by browsing to
{webook_url}/setwebhooke.g. webhook_url = https:///setwebhook/
- Go to
@botfatheron Telegram - Type
/mybot, and select on your created bot e.g. EXAMPLEBOT - Go to 'Bot Settings' -> 'Group Privacy', and select on 'Turn off'
After installing Ngrok, run ./ngrok http 5000 (with 5000 being the default port for Flask).
Ngrok will return provide a publicly accessible URL for the running script, add the URL to the script WEBHOOK_URL variable.
Run python3 bot.py to start running and using the bot.