AI_BTC / app.py
Dooratre's picture
Update app.py
e96e484 verified
raw
history blame
1.17 kB
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)