You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+30-23Lines changed: 30 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,53 +314,60 @@ Now, we need to define a function that should process a specific type of update:
314
314
>>> def start(bot, update):
315
315
... bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
316
316
317
-
We want this function to be called on a Telegram message that contains the ``/start`` command, so we need to register it in the dispatcher::
317
+
We want this function to be called on a Telegram message that contains the ``/start`` command. To do that, we have to use a ``CommandHandler`` object and register it in the dispatcher::
The last step is to tell the ``Updater`` to start working::
322
324
323
325
>>> updater.start_polling()
324
326
325
-
Our bot is now up and running (go ahead and try it)! It's not doing anything yet, besides answering to the ``/start`` command. Let's add another handler function and register it::
327
+
Our bot is now up and running (go ahead and try it)! It's not doing anything yet, besides answering to the ``/start`` command. Let's add another handler that listens for regular messages. We're using the `MessageHandler` here to echo to all text messages::
Let's add some functionality to our bot. We want to add the ``/caps`` command, that will take some text as parameter and return it in all caps. We can get the arguments that were passed to the command in the handler function simply by adding it to the parameter list::
339
+
Let's add some functionality to our bot. We want to add the ``/caps`` command, that will take some text as parameter and return it in all caps. We can get the arguments that were passed to a command in the handler function::
People might try to send commands to the bot that it doesn't understand, so we can use a ``RegexHandler`` to recognize all commands that were not recognized by the previous handlers. **Note:** This handler has to be added last, else it will be triggered before the ``CommandHandler``s had a chance to look at the update::
362
+
363
+
>>> def unknown(bot, update):
364
+
... bot.sendMessage(chat_id=update.message.chat_id, text="Sorry, I didn't understand that command.")
0 commit comments