import os
import requests
from flask import Flask
from telegram import Update, Bot
from telegram.ext import CommandHandler, CallbackContext, ApplicationBuilder

app = Flask(__name__)
TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'  # Замените на ваш токен

async def start(update: Update, context: CallbackContext) -> None:
    await update.message.reply_text('Привет! Используйте /decode <vin> для декодирования VIN или /check <vin> для проверки VIN.')

def decode_vin(update: Update, context: CallbackContext) -> None:
    vin = context.args[0] if context.args else None
    if vin:
        response = requests.get(f'http://localhost:5000/search?vin={vin}')
        update.message.reply_text(response.text)
    else:
        update.message.reply_text('Пожалуйста, укажите VIN.')

def check_vin(update: Update, context: CallbackContext) -> None:
    vin = context.args[0] if context.args else None
    if vin:
        response = requests.get(f'http://localhost:5000/detail/{vin}.html')
        update.message.reply_text(response.text)
    else:
        update.message.reply_text('Пожалуйста, укажите VIN.')

def main() -> None:
    application = ApplicationBuilder().token(TOKEN).build()
    dispatcher = application.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))
    dispatcher.add_handler(CommandHandler("decode", decode_vin))
    dispatcher.add_handler(CommandHandler("check", check_vin))

    application.run_polling()

if __name__ == '__main__':
    main()
