MCPcopy Create free account
hub / github.com/eternnoir/pyTelegramBotAPI / Middleware

Class Middleware

examples/middleware/class_based/basic_example.py:10–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8# from telebot.handler_backends import CancelUpdate, SkipHandler
9
10class Middleware(BaseMiddleware):
11 def __init__(self):
12 self.update_types = ['message']
13 def pre_process(self, message, data):
14 data['foo'] = 'Hello' # just for example
15 # we edited the data. now, this data is passed to handler.
16 # return SkipHandler() -> this will skip handler
17 # return CancelUpdate() -> this will cancel update
18 def post_process(self, message, data, exception=None):
19 print(data['foo'])
20 if exception: # check for exception
21 print(exception)
22
23@bot.message_handler(commands=['start'])
24def start(message, data: dict): # you don't have to put data parameter in handler if you don't need it.

Callers 1

basic_example.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…