skip to Main Content

Example messages

  • /weather 90210
  • /weather Beverley Hills, CA, US

My CommandHandler is as follows:

weather_hanlder = CommandHandler('weather', weather_get_results)
dp.add_handler(weather_handler)

I want everything after /weather to be passed to my weather_get_results(PASS STRING IN HERE) function.

I have looked through telegram’s documentation and examples and haven’t had much luck. Any help would be greatly appreciated. I feel like I’m missing something obvious.

2

Answers


  1. Chosen as BEST ANSWER

    This is probably the wrong way to do this but I managed to find the data in update...

    def weather_get_results(update, context):
        weather_command_text = update['message']['text'][9::]
        weather_search = weather_command_text
    

  2. So, the arguments are actually in the context parameter passed to the callback!

    context.args specifically; it’s the list of arguments you send through with the command. in your example, context.args[0] would be ‘Beverley’.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search