以下代码请求用户定位和联系:
def contact(bot, update):
dp = DjangoTelegramBot.dispatcher
con_keyboard = KeyboardButton(text="send_contact", request_contact=True)
loc_keyboard = KeyboardButton(text="send_location", request_location=True)
custom_keyboard = [[ con_keyboard ,loc_keyboard]]
reply_markup = ReplyKeyboardMarkup(custom_keyboard)
bot.sendMessage(update.message.chat_id,
text="Would you mind sharing your location and contact with me",
reply_markup=reply_markup)
我的问题是用户点击send_contact按钮后如何访问电话号码?
PS:我正在使用python-telegram-bot和django-telegrambot
答案 0 :(得分:5)
我不确定django-telegrambot
。但如果我没有错,reply_markup
就是python-telegram-bot
下的from telegram.ext import MessageHander, Filters
def contact_callback(bot, update):
contact = update.effective_message.contact
phone = contact.phone_number
dispatcher.add_handler(MessageHandler(Filters.contact, contact_callback))
。按下按钮后,用户的电话号码将作为Contact
对象发送到您的机器人。您可以使用MessageHandler
和Filters.contact
过滤器抓住它。
import xxxxx or from xxxxx import yyyyy