Home python How to get a phone number of the user? Telegrambot

How to get a phone number of the user? Telegrambot




Bot asks user data and records data in turn in notepad. But for some reason does not record the phone number. What is the problem? I use PyTelegramBotapi

import telbot
From Telebot Import Types
Import OS, Signal, Pickle, Sys
Bot = Telbot.Telebot ('Token')
@ Bot.Message_Handler (Commands = ['Start'])
Def User (Message):
  Sent = Bot.Send_Message (Message.chat.id, Hello, how can I contact you? ")
  Bot.register_next_Step_Handler (Sent, Services)
  Doc = Open ('Client.txt', 'A')
@ Bot.Message_Handler (Content_Types = ['Text'])
  user_markup = telbot.types.replyKeyboardMarkup (one_time_keyboard = True)
  user_markup.row ('BUY', 'SELL')
  USLugi = Bot.Send_Message (Message.from_user.id, "What services are you interested in?", Reply_markup = User_Markup)
  Bot.register_next_Step_Handler (USLugi, Telephone)
  Doc = Open ('Client.txt', 'A')
  Doc.Write ("Customer Name - {Name} \ N" .format (name = Message.Text))
  Keyboard = Types.ReplyKeyboardMarkup (one_time_keyboard = True)
  REG_BUTTON = TYPES.KEYBOARDBUTTON (text = "Send phone number", Request_Contact = True)
  Keyboard.add (reg_button)
  Nomer = Bot.Send_Message (Message.chat.id, 'Leave Your Contact Number In order for our manager to contact you.', Reply_markUp = Keyboard)
  bot.register_next_step_handler (NOMER, SAVE)
  Doc = Open ('Client.txt', 'A')
  Doc.Write ("Service - {service} \ n" .format (Service = Message.Text))
Def Save (Message):
  Bot.Send_Message (message.chat.id, 'thanks for the appeal. We will contact you soon.')
  Doc = Open ('Client.txt', 'A')
  Doc.Write ("Phone - {Telephon} \ N" .format (Telephon = Message.Text))
  Doc.Close ()
if __name__ == '__main__':
   bot.infinity_polling (none_stop = true)

Answer 1, Authority 100%

Because not Message.Text , and message.contact.phone_number

doc.write ("phone {telephon} \ n" .format (Telephon = Message.contact.phone_Number))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions