|
import requests |
|
|
|
|
|
bot_token = '6990801595:AAE79xNVO1D_0SeWZlzYLE57Suwfp9GyKT8' |
|
|
|
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) |
|
return 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']) |
|
|
|
if __name__ == '__main__': |
|
main() |