How To Obtain Username, First Name Or Last Name Of A Telegram User With Python-Telegram-Bot?

Sadegh Alirezaie picture Sadegh Alirezaie · Dec 6, 2016 · Viewed 17.2k times · Source

I'm Creating A Telegram Bot Using Python-Telegram-Bot

I Know That update.message.chat_id Returns The User's Chat ID, But I Need To Know How To Get User's Username Or First Name And/Or Last Name.

I've Found This On Telegram's Documentation But I Don't Know How To Use It ( I Tried bot.getChat(update.message.chat_id) But No Result)

Answer

Dudnikof picture Dudnikof · Dec 9, 2016

All infomation about user (as username, id, first/last name and profile photos) available from telegram.User object. You can easily get it using telegram.Message

user = update.message.from_user
print('You talk with user {} and his user ID: {} '.format(user['username'], user['id']))