File size: 1,165 Bytes
30cf6f7
e96e484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
import requests
from flask import Flask, render_template

app = Flask(__name__)

# Replace 'YOUR_BOT_TOKEN' with your actual bot token
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')

@app.route('/')
def home():
    return render_template('index.html')

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(host='0.0.0.0',port=7860)