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
+78-78Lines changed: 78 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -57,9 +57,9 @@ Table of contents
57
57
58
58
- `Getting started`_
59
59
60
-
1. `The Updater class`_
60
+
1. `API`_
61
61
62
-
2. `API`_
62
+
2. `telegram.ext`_
63
63
64
64
3. `JobQueue`_
65
65
@@ -174,85 +174,11 @@ This library uses the `logging` module. To set up logging to standard output, pu
174
174
175
175
at the beginning of your script.
176
176
177
-
--------------------
178
-
_`The Updater class`
179
-
--------------------
180
-
181
-
The ``Updater`` class is the new way to create bots with ``python-telegram-bot``. It provides an easy-to-use interface to the ``telegram.Bot`` by caring about getting new updates from telegram and forwarding them to the ``Dispatcher`` class. We can register handler functions in the ``Dispatcher`` to make our bot react to Telegram commands, messages and even arbitrary updates.
182
-
183
-
As with the old method, we'll need an Access Token. To generate an Access Token, we have to talk to `BotFather <https://telegram.me/botfather>`_ and follow a few simple steps (described `here <https://core.telegram.org/bots#botfather>`_).
184
-
185
-
First, we create an ``Updater`` object::
186
-
187
-
>>> from telegram import Updater
188
-
>>> updater = Updater(token='token')
189
-
190
-
For quicker access to the ``Dispatcher`` used by our ``Updater``, we can introduce it locally::
191
-
192
-
>>> dispatcher = updater.dispatcher
193
-
194
-
Now, we need to define a function that should process a specific type of update::
195
-
196
-
>>> def start(bot, update):
197
-
... bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
198
-
199
-
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::
The last step is to tell the ``Updater`` to start working::
204
-
205
-
>>> updater.start_polling()
206
-
207
-
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::
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::
Check out more examples in the `examples folder <https://github.com/python-telegram-bot/python-telegram-bot/tree/master/examples>`_!
250
-
251
177
------
252
178
_`API`
253
179
------
254
180
255
-
Note: Using the ``Bot`` class directly is the 'old' method, but some of this is still important information, even if you're using the ``Updater`` class!
181
+
Note: Using the ``Bot`` class directly is the 'old' method, but almost all of this is still important information, even if you're using the ``telegram.ext`` submodule!
256
182
257
183
The API is exposed via the ``telegram.Bot`` class.
258
184
@@ -339,13 +265,87 @@ There are many more API methods, to read the full API documentation::
339
265
340
266
$ pydoc telegram.Bot
341
267
268
+
---------------
269
+
_`telegram.ext`
270
+
---------------
271
+
272
+
The ``telegram.ext`` submodule is built on top of the bare-metal API. It provides an easy-to-use interface to the ``telegram.Bot`` by caring about getting new updates with the ``Updater`` class from telegram and forwarding them to the ``Dispatcher`` class. We can register handler functions in the ``Dispatcher`` to make our bot react to Telegram commands, messages and even arbitrary updates.
273
+
274
+
We'll need an Access Token. __Note:__ If you have done this in the previous step, you can use that one. To generate an Access Token, we have to talk to `BotFather <https://telegram.me/botfather>`_ and follow a few simple steps (described `here <https://core.telegram.org/bots#botfather>`_).
275
+
276
+
First, we create an ``Updater`` object::
277
+
278
+
>>> from telegram.ext import Updater
279
+
>>> updater = Updater(token='token')
280
+
281
+
For quicker access to the ``Dispatcher`` used by our ``Updater``, we can introduce it locally::
282
+
283
+
>>> dispatcher = updater.dispatcher
284
+
285
+
Now, we need to define a function that should process a specific type of update::
286
+
287
+
>>> def start(bot, update):
288
+
... bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
289
+
290
+
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::
The last step is to tell the ``Updater`` to start working::
295
+
296
+
>>> updater.start_polling()
297
+
298
+
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::
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::
0 commit comments