AI_BTC / app.py
Dooratre's picture
Update app.py
ddc8825 verified
raw
history blame
1.02 kB
import requests
import time
# Replace 'YOUR_BOT_TOKEN' with your actual bot token
bot_token = '7405960993:AAH1YTmoam4-Afk_QHsAcAObrdXwAlzfsaQ'
def send_message(chat_id, text):
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
params = {'chat_id': chat_id, 'text': text}
response = requests.get(url, params=params)
print(response.json())
def handle_message(message):
chat_id = message['chat']['id']
text = message['text']
if text == '/start':
send_message(chat_id, 'Hi')
def main():
offset = None
while True:
url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
params = {'offset': offset}
response = requests.get(url, params=params)
data = response.json()
if data['ok']:
for update in data['result']:
offset = update['update_id'] + 1
if 'message' in update:
handle_message(update['message'])
time.sleep(1)
if __name__ == '__main__':
main()