Search code examples
pythontelegram-botpython-telegram-bot

How can I fetch sender info from "update" value


I am trying to get sender information from the 'update' parameter, what is returned from it? I am using the 'python-telegram-bot' package

def startBot(update, context):
    update.message.reply_text('HI I am ww helper')

def main():
    updater = Updater(TOKEN, use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", startBot))

Solution

  • You can get a reference to the sender as update.message.from_user

    def startBot(update, context):
        print("USER:", update.message.from_user.first_name)
        update.message.reply_text('HI I am ww helper')
    

    You can find the Documentation for Update object in the official API as well as in the library for future references.