0
@dp.message_handler(state=Proverka.phone, content_types=['contact'])
async def step1(msg:types.Contact, state: FSMContext,):
    if (msg.contact.phone_number or msg.text) in bonuses.keys():
        global text
        text=bonuses[msg.contact.phone_number or msg.text]
        await state.update_data(phone=msg.contact.phone_number)
        await msg.answer("Введите номер карты")
        await Proverka.code.set()
    else:
        await msg.answer("Нет такого номера.")
        await state.finish()
    

Как совмещать message.text и message.contact.phone_number в aiogram. Отправить в State либо номер телефона который был взять из Contact, либо введенный в ручном режиме. Спасибо.

1 ответ 1

0

Где-то вот так
@dp.message_handler(state=Proverka.phone, content_types=['contact', 'text']
UPD Так будет получше

@dp.message_handler(state=Proverka.phone, content_types=['contact', 'text'])
async def step1(msg: typing.Union[types.Contact, types.Message], state: FSMContext):
    contact = msg.contact.phone_number if msg.contact else msg.text
1
  • async def step1(msg:types.Contact,.... а сюда надо что ни будь добавить? 13 июн 2022 в 7:17

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.