Events
Event emitter for internal Core signals and your own custom events.
Landbot.Core's events module is a general-purpose event bus, not a whitelist of SDK-internal signals. Subscribe to and emit arbitrary event names — anything you put in events.emit('foo', payload) reaches any events.on('foo', …) listener. The SDK uses the same bus internally to broadcast lifecycle events (init, new_message), and you can listen to those alongside your own.
Access it via core.events.
Methods
on
on(event, listener)
Parameters:
- event: String
- listener: Function
Register a listener for the named event.
core.events.on('my_event', function (data) {
console.log(data);
});
off
off(event, listener)
Parameters:
- event: String
- listener: Function
Remove a previously registered listener. The listener must be the same function reference you passed to on.
core.events.off('my_event', myListener);
once
once(event, listener)
Parameters:
- event: String
- listener: Function
Register a listener that fires exactly once and is then automatically removed.
core.events.once('my_event', function (data) {
console.log(data);
});
emit
emit(event, value)
Parameters:
- event: String
- value: ***
Trigger the named event with the given payload. Useful for cross-component communication when your UI shares a single Core instance.
core.events.emit('my_channel', {
test: true,
});
removeAllListeners
removeAllListeners(event)
Parameters:
- event: String
Drop every listener registered against the named event.
core.events.removeAllListeners('my_event');
Pre-built events
The SDK emits these events itself.
init
Emitted when core.init() has finished and the instance is ready.
core.events.on('init', function () {
console.log('Landbot core initialized');
});
new_message
Triggered every time a new message is received. Don't listen to this directly unless you're prepared to deal with messages arriving out of order in a burst. For sequential, render-ready delivery, use pipelines instead.
core.events.on('new_message', function (message) {
console.log(message);
});