File size: 1,022 Bytes
c3e172c
ddc8825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abee9b3
 
ddc8825
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()