Answer the question
In order to leave comments, you need to log in
How can I make the chat bot automatically respond and not after I run the file with the code?
import requests
import os
API_link = 'https://api.telegram.org/bot1153670351:AAH7AOmF6Q4bMavkiRs-6Kq3cXXX-Swfg08'
updates = requests.get(API_link+'/getUpdates?offset=-1').json()
print(updates)
message = updates["result"][0]["message"]
chat_id = message["from"]["id"]
text = message["text"]
if text == "hi":
send_message = requests.get(API_link + f"/sendMessage?chat_id={chat_id}&text=Hi Arsen")
else:
send_message = requests.get(API_link + f"/sendMessage?chat_id={chat_id}&text=I don`t know this command")
Answer the question
In order to leave comments, you need to log in
Make receiving updates in a loop? In general, it is better to use libraries, for example, PyTelegramBotAPI
There are libraries for this, for example, pyTelegramBotApi, and you need to write a bot using hardcode if you need maximum performance, and never store the bot's TOKEN in the code, look at what environment variables are
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question