NimarkoGram Docs
RU
Docs/Event callbacks

Event callbacks

Subscribe to send events and read the current account context.

On this pageSubscribe on loadReturn a resultOther events

Subscribe on load

Defining a callback alone does not register it. For the send event, call add_on_send_message_hook() in on_plugin_load. The example logs only the account slot when the user sends a message.

Python
from base_plugin import BasePlugin, HookResult

class SendLog(BasePlugin):
    def on_plugin_load(self):
        self.add_on_send_message_hook()

    def on_send_message_hook(self, account, params):
        self.log(f"Send event for account {account}")
        return HookResult()

Return a result

HookResult() uses the DEFAULT strategy and continues normal event handling. This is appropriate for an observer. Keep the callback brief because it runs on the message-send path.

Other events

add_hook(name) and remove_hook(name) manage a subscription by event name. pre_request_hook receives the request before processing, post_request_hook receives the response and error, and on_update_hook receives an incoming update. Use the account argument of the current call in all three. For app startup and pause events, see Lifecycle.