Adding Event Listener Component
Execute the commandlbp comp EventListener in the plugin directory. Creating an event listener component doesn’t require any configuration.
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 theinitialize method of the DefaultEventListener class.
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:- Check the
List of Monitorable EventsandEvent Context APIsin the documentation Pipeline Events - Check out Plugin Common APIs
