llm-chatbot/bot.py
2025-09-14 17:15:48 +00:00

32 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import asyncio
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
from telegram.ext import Application, CommandHandler, ContextTypes
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
WEBAPP_URL = os.getenv("WEBAPP_URL", "https://yourdomain.com/webapp") # из .env или дефолт
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Обработка команды /start"""
keyboard = [
[InlineKeyboardButton("🚀 Открыть чат", web_app=WebAppInfo(url=WEBAPP_URL))]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
"Привет! Нажми кнопку ниже, чтобы открыть WebApp 👇",
reply_markup=reply_markup
)
def main():
# Создаём приложение
app = Application.builder().token(TELEGRAM_TOKEN).build()
# Добавляем обработчик команды /start
app.add_handler(CommandHandler("start", start))
# Запускаем (асинхронно работает внутри run_polling)
print("🚀 Бот запущен. Нажми /start в чате с ним.")
app.run_polling()
if __name__ == "__main__":
main()