Python电报漫游器:访问联系信息 [英] Python telegram bot: Access to contact information
问题描述
以下代码要求用户提供位置和联系方式:
Following code requests location and contact from user:
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
My question is how can I access to phone number after user clicks on send_contact button?
PS: I am using python-telegram-bot and django-telegrambot
推荐答案
我不确定 django-telegrambot
.但是,如果我没记错的话,您的 reply_markup
是 python-telegram-bot
下的那个.按下按钮后,用户的电话号码将作为 MessageHandler
和 Filters.contact
过滤器.
I am not sure with django-telegrambot
. But if I'm not wrong your reply_markup
is the one under python-telegram-bot
. When the button is pressed, the user's phone number will be sent to your bot as a Contact
object. You can catch it with a MessageHandler
and a Filters.contact
filter.
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))
这篇关于Python电报漫游器:访问联系信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!