import random
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
verification_codes = {}
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Введите свой номер телефона (в формате +123456789):')
def receive_phone(update: Update, context: CallbackContext) -> None:
phone_number = update.message.text
# Генерация кода
code = random.randint(1000, 9999)
verification_codes[phone_number] = code
update.message.reply_text(f'Ваш код: {code}. Введите его для подтверждения.')
def verify_code(update: Update, context: CallbackContext) -> None:
user_code = update.message.text
user_phone = context.user_data.get('phone_number')
if user_phone in verification_codes and verification_codes[user_phone] == int(user_code):
update.message.reply_text('Верификация прошла успешно!')
del verification_codes[user_phone]
else:
update.message.reply_text('Неверный код. Попробуйте еще раз.')
def main() -> None:
updater = Updater("TVOY-TOKEN")
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, receive_phone))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, verify_code))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()