mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Update with middleware handler
This commit is contained in:
parent
36a228da92
commit
b912e4dbaf
18
README.md
18
README.md
@ -223,6 +223,24 @@ In bot2.0 update. You can get `callback_query` in update object. In telebot use
|
|||||||
def test_callback(call):
|
def test_callback(call):
|
||||||
logger.info(call)
|
logger.info(call)
|
||||||
```
|
```
|
||||||
|
#### Middleware Handler
|
||||||
|
|
||||||
|
A middleware handler is a function that allows you to modify requests or the bot context as they pass through the
|
||||||
|
Telegram to the bot. You can imagine middleware as a chain of logic connection handled before any other handlers are
|
||||||
|
executed.
|
||||||
|
|
||||||
|
```python
|
||||||
|
@bot.middleware_handler(update_types=['message'])
|
||||||
|
def modify_message(bot_instance, message):
|
||||||
|
# modifying the message before it reaches any other handler
|
||||||
|
message.another_text = message.text + ':changed'
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
def start(message):
|
||||||
|
# the message is already modified when it reaches message handler
|
||||||
|
assert message.another_text == message.text + ':changed'
|
||||||
|
```
|
||||||
|
There are other examples using middleware handler in the [examples/middleware](examples/middleware) directory.
|
||||||
|
|
||||||
#### TeleBot
|
#### TeleBot
|
||||||
```python
|
```python
|
||||||
|
Loading…
x
Reference in New Issue
Block a user