Recently, I have made so many telegram bots that I was extremely overwhelmed with how to write them, how to host them, and, in principle, I have developed a beautiful template for quickly creating them.
I can immediately suggest looking at what you get at the end of this tutorial. To do this, I launched a bot with a code identical to the template.
It is also worth noting that the hosting in this example is free, but it is enough for a reasonable load.
And I'll say right away that everything will be in python further ... Here ... He said. I will not beat around the bush anymore, we only have 5 minutes ( remember, huh? ). Let's get started!
Step-by-step instruction
1) Create a repository on github from my template
2) Register on Heroku
3) Create a new application
4) Link our repository to the Heroku project
5) Set up automatic deployment
6) We look at the address where our bot will hang
7) Setting up environment variables
KEY |
VALUE |
BOT_TOKEN |
Bot token |
WEBHOOK_TOKEN |
A random string of letters for safety |
ADMIN_PASSWORD |
Another random string of letters for safety |
HOST |
The address obtained in step 6 (for example fancy-panda.herokuapp.com ). Pay attention to the format! |
IS_PRODUCTION |
True |
LOG_BOT_TOKEN |
, |
ADMIN_ID |
user_id, ( @userinfobot) |
8)
9) 6 . - : fancy-panda.herokuapp.com/?password=<ADMIN_PASSWORD>
10) webhook, fancy-panda.herokuapp.com/set_webhook?password=<ADMIN_PASSWORD>
, , , "".
, , , . :
@bot.message_handler(commands=["id"])
def get_id(message):
logger.info(f'</code>@{message.from_user.username}<code> used /id')
bot.send_message(message.chat.id, f"user_id = {message.chat.id}")
, ... ( )
, . wifi_qr_bot, QR- WiFi. , (, ), .
, . . , tg-logger. , , . , . ...