Search code examples
pythoninputtelegrambinance

Python Telegram, How to save user input as string


I am making a Telegram trading bot that will create an order after receiving a string from the user. How can I make the bot receive that string?


Solution

  • You can use the text handler. It passes a dictionary to the function. The dictionary contains a lot of useful information such as the message text, user's name, and id, etc.

    @bot.message_handler(content_types=["text"])
    def handle_text(message):
    
        print(message)
        your_str = message.text
    

    You may also consider the documentation and the examples in particular.