如何使用Telegram Bot API捕获用户的电话号码和位置?

时间:2016-04-20 05:43:54

标签: python-telegram-bot

我目前正在通过电报python包播放电报bot api。到目前为止,我在使用以下代码创建自定义键盘时没有任何问题:

  

bot.sendMessage(chat_id,                          text ="你现在在哪里? "                               " /取消中止",                          reply_markup = ReplyKeyboardMarkup([[' Home',' Office']],one_time_keyboard = True))

基本上上面会给我两个按钮," Home"和" Office"。

我现在正试图捕获用户的电话号码和位置,这应该是基于https://core.telegram.org/bots/api#keyboardbutton的Telegram API Bot文档可行的。但是,我真的很难弄清楚如何让它发挥作用。

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

这是一个例子:

reply_markup = telegram.ReplyKeyboardMarkup([[telegram.KeyboardButton('Share contact', request_contact=True)]])

bot.sendMessage(CHAT_ID, 'Example', reply_markup=reply_markup)

希望它有所帮助!

答案 1 :(得分:1)

来自电报导入(KeyboardButton)

... ... ...

location_keyboard = KeyboardButton(text="send_location",  request_location=True)           #creating location button object
contact_keyboard = KeyboardButton('Share contact', request_contact=True)  #creating contact button object
custom_keyboard = [[ location_keyboard, contact_keyboard ]] #creating keyboard object
reply_markup = ReplyKeyboardMarkup(custom_keyboard) 
update.message.reply_text(
                "Would you mind sharing your location and contact with me?", 
                reply_markup=reply_markup)