Skip to main content
LangBot’s pipeline generates events during runtime for plugins to hook into and process. Each plugin can only have one event listener (components/event_listener/default.yaml), but can register any number of events within it.

Adding Event Listener Component

Execute the command lbp comp EventListener in the plugin directory. Creating an event listener component doesn’t require any configuration.
This will generate default.yaml and default.py files in the components/event_listener/ directory. The .yaml file defines the basic information for the event listener, and the .py file is the event listener handler:

Manifest File: Event Listener

Since each plugin can only have one event listener, no modifications are needed in the manifest file.

Plugin Processing

The following code is generated by default (components/event_listener/default.py). You need to register and implement event processing logic in the initialize method of the DefaultEventListener class.
Adding listeners for specific events:
This code registers a listener for the PersonMessageReceived (receiving any message from private chat) event, prints the event context (EventContext) information when the event is triggered, and calls the event context API to reply with a message. EventContext stores common context information for this event trigger, while EventContext.event is an object of PersonMessageReceived (or other corresponding event types), storing detailed information about the event.

Event Registration

Event registration is implemented through the @self.handler decorator, with the decorator parameter being the event type. All monitorable events are defined in langbot_plugin.api.entities.builtin.events.

What’s Next

You have learned the basic information about event listeners. Next, you can: