How can I retrieve a user's name using a Telegram Bot?

I’m developing a Telegram bot that uses a handler to respond to commands. My goal is to capture either the user’s name or their ID when they execute a specific command.

MY CODE

import telebot  # Telegram Bot API

bot = telebot.TeleBot(<YourBotToken>)

@bot.message_handler(commands=['details'])
def greet_user(message):
    user_info = message.from_user  # Access user details
    print(user_info)
    bot.reply_to(message, 'Hello!')

bot.polling()

Currently, the information retrieved pertains only to the bot itself. How can I access the details of the user triggering the handler? What method should I implement to achieve this?

NOTE:
My bot has been integrated with a Telegram group, and I’ve ensured to safeguard my Telegram Token within my MVC.

You should also check if you are using the correct version of the python-telegram-bot library, as API methods might differ between versions. Make sure that your bot is set up with the necessary permissions to access user information in group settings. Another thing you could try is printing out the content of message itself to see exactly what data you can access, which will help you ensure you’re capturing user information correctly. Sometimes, it might also depend on whether your bot is the one initiating the conversation in private chats.