How to capture user's phone number and location using Telegram Bot API?

Hafidz Zulkifli picture Hafidz Zulkifli · Apr 20, 2016 · Viewed 11.1k times · Source

I'm currently playing with telegram bot api via the telegram python package. So far I don't have any problem creating custom keyboards with the following code:

bot.sendMessage(chat_id, text="Where are you now? " "/cancel to abort", reply_markup=ReplyKeyboardMarkup([['Home', 'Office']], one_time_keyboard=True))

Basically the above will give me two button, "Home" and "Office".

I'm now trying to capture user's phone number and location, which should be doable based on the Telegram API Bot documentation at https://core.telegram.org/bots/api#keyboardbutton. However I'm really having a hard time figuring out how to get it to work.

Any ideas?

Answer

Leandro Toledo picture Leandro Toledo · May 29, 2016

here is an example:

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

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

Hope it helps!