Python telegram bot:访问联系信息

时间:2017-09-28 09:31:57

标签: python django telegram python-telegram-bot

以下代码请求用户定位和联系:

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-botdjango-telegrambot

1 个答案:

答案 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对象发送到您的机器人。您可以使用MessageHandlerFilters.contact过滤器抓住它。

import xxxxx    or    from xxxxx import yyyyy