|
import os |
|
from flask import Flask, request |
|
import telebot |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') |
|
|
|
|
|
bot = telebot.TeleBot(TELEGRAM_TOKEN) |
|
|
|
|
|
@bot.message_handler(commands=['start']) |
|
def send_welcome(message): |
|
bot.reply_to(message, "Привет! Я твой Telegram бот!") |
|
|
|
|
|
@bot.message_handler(func=lambda message: True) |
|
def echo_all(message): |
|
bot.reply_to(message, f"Ты сказал: {message.text}") |
|
|
|
|
|
@app.route(f'/{TELEGRAM_TOKEN}', methods=['POST']) |
|
def webhook(): |
|
json_str = request.get_data(as_text=True) |
|
update = telebot.types.Update.de_json(json_str) |
|
bot.process_new_updates([update]) |
|
return "OK", 200 |
|
|
|
|
|
@app.route('/') |
|
def index(): |
|
return 'Telegram bot is running!', 200 |
|
|
|
if __name__ == '__main__': |
|
app.run(host='0.0.0.0', port=5000) |
|
|