R
R
Ruslan2018-04-11 21:25:18
Python
Ruslan, 2018-04-11 21:25:18

Telegram bot in python, how to solve the problem with a request_contact request from a user on a mobile device?

Hello everyone, actually there is a problem when calling the button and then sharing the user's contact information. From the desktop client, everything works fine, but from mobile devices, the button simply does not work, nothing happens when pressed. Maybe I'm doing something wrong?
The phone function, you can ignore the second handler, but I’ll still add whether the problem lies in it.

#auth_user
@bot.message_handler(commands=['status'])
def phone(message):
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button_phone = types.KeyboardButton(text="Отправить номер телефона", request_contact=True)
    keyboard.add(button_phone)
    bot.send_message(message.chat.id, "Для получения данных по договору мне необходим Ваш номер телефона привязанный к договору", reply_markup=keyboard)

@bot.message_handler(content_types=['contact'])
def read_contact_phone(message):
  phone_usm = message.contact.phone_number
  try:
    with connection.cursor() as cursor:
      sql = 'SELECT * FROM all_abons_bot WHERE phone=%s'
      cursor.execute(sql,(phone_usm,))
      result = cursor.fetchone()
      if result is not None:
        phone_user_db = result['phone']
        title_user = result['title']
#				login_user = result['login']
#				passwd_user = result['passwd']
        balance_contract = result['balance_contract']
#				balance_bonus = result['balance_bonus']
        status_option = result['status_option']
        if status_option > 0:
          act = 'опция активна'
        else:
          act = 'нет активных опций'
        phone_usm == phone_user_db
        bot.send_message(message.chat.id, 'Номер вашего договора : ' + ' ' + title_user + '\n'
#				'Логин VPN : ' + ' ' + login_user + '\n' 
#				'Пароль  VPN : ' + passwd_user + '\n'
        'Баланс договора : ' + ' ' + str(balance_contract) + ' руб.' + '\n'
#				'Бонусный баланс : ' + ' ' + str(balance_bonus) + ' бал.' + '\n'
        'Тарифные опции : ' + ' ' + str(act),reply_markup=hideBoard)
      else:
        bot.send_message(message.chat.id,'Я не нашел подходящего договора!\n'
          'Возможно Ваш телефон не привязан к договору\n' ,reply_markup=hideBoard)

  finally:
        connection.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
crenod, 2021-01-14
@crenod

3 years is not the limit for an answer.
From the desktop, the contact is sent with +, from the phone - without a plus.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question