您好我有一个代码,此代码发送联系人
keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=False)
reg_button = types.KeyboardButton(text="...", request_contact=True)
keyboard.add(reg_button)
keyboard.row('...')
response = bot.send_message(message.chat.id,'...',
reply_markup=keyboard)
print(response.contact) # response.contact = None here
为什么要保存文件或数据库中的联系人。请帮助:)
答案 0 :(得分:0)
#bot sends the received data to the channel
@bot.message_handler(content_types=['contact','location']) def send_welcome(message):
first_name = message.from_user.first_name.decode("utf-8")
user_id = message.from_user.id
username = message.chat.username
chat_id = message.chat.id
if message.contact:
pn = message.contact.phone_number
cf = message.contact.first_name
bot.send_message(YOUR_CHANNEL_ID, "#contact [{0}](https://telegram.me/{1})".format(user_id, username), parse_mode="Markdown", disable_web_page_preview=True)
bot.send_contact(YOUR_CHANNEL_ID, phone_number=pn, first_name=cf)
if message.location:
bot.send_message(YOUR_CHANNEL_ID, "#location [{0}](https://telegram.me/{1})".format(user_id, username), parse_mode="Markdown", disable_web_page_preview=True)
bot.send_location(YOUR_CHANNEL_ID, message.location.latitude, message.location.longitude)