Landbot.Core
The core class — constructor, properties, and methods for sending and reading messages.
The Landbot.Core class is the entry point to the SDK. Construct it with a bot config object (see Install for how to fetch one), then use the instance to send and read messages.
Constructor
Landbot.Core
Landbot.Core(config)
Parameters:
- config: Object
Create a Landbot.Core instance.
Properties
config
Type: Object
The config object the instance was created with.
events
Type: Object
Event emitter instance. See Events.
pipelines
Type: Object
Pipelines instance. See Pipelines.
Methods
init
init()
Returns:
- Promise
Core initialization. Returns a Promise that resolves with data.messages — the conversation history for this bot session (welcome bundle + any previous conversation if persistent storage is enabled).
core.init().then(function (data) {
console.log(data.messages);
});
Note
data.messagescan be empty. On bots without persistent storage, or on fresh sessions where the welcome arrives via pipelines rather than as a history bundle,data.messagesresolves to[]. Don't rely oninit()alone to seed your UI — subscribe to$readableSequence(or another pipeline) before callinginit()so the welcome messages are caught by your subscription regardless of whether the Promise carries them.
destroy
destroy()
Destroy the Landbot.Core instance and all its listeners. Call this when the host UI is being torn down to free resources.
Warning Don't reuse a destroyed instance. Post-destroy calls don't throw —
sendMessagesilently resolves andpipelines.*.subscribeaccepts the call without delivering any messages. Looks like it worked, but nothing happens. To start a new conversation, construct a freshCorewith the same config.A fresh
Coredoes not continue the previous conversation — it re-runs the welcome flow with a new message key. Sessions are not sticky across instances.
sendMessage
sendMessage(message)
Parameters:
- message: Object
Returns:
- Promise
Sends a message to the bot from the client side. See Messages for the supported message structures.
core.sendMessage({ message: 'Hey bro!' });
getLastMessages
getLastMessages(amount)
Parameters:
- amount: Number
Returns:
- Promise
Return the last amount messages stored in the database.
core
.getLastMessages(25)
.then(function (data) {
console.log(data);
});
Warning Requires persistent storage on the bot. If the bot was configured with storage disabled (the
storage_offflag in its config), bothgetLastMessagesandgetMoreMessagesthrow:
TypeError: Cannot read properties of null (reading '_query')
>
> The error is the SDK reaching for a Firestore reference that was never initialised. Before relying on these methods, verify the fetched config has `storage_off: false` — or wrap calls in `try { … } catch { … }` and degrade gracefully when storage isn't available.
### getMoreMessages
**getMoreMessages(amount)**
Parameters:
- amount: *Number*
Returns:
- *Promise*
Return `amount` messages stored in the database. An internal increasing counter lets this function be called repeatedly to retrieve older and older messages — a typical infinite-scroll back-pagination pattern.
```javascript
core
.getMoreMessages(25)
.then(function (data) {
console.log(data);
});
Same persistent-storage requirement applies as getLastMessages — see that warning.