Landbot client core. Connects to the messaging database and the landbot app servers.
Choose a way to get started with landbot-core.
npm install @landbot/core
Import it in your app.
import LandbotCore from '@landbot/core';
const core = new LandbotCore({
...config
});
-
init
. Core initialization. Returns a Promise that resolves with initialization data and previous conversation messages.
core.init().then(function (data) {
console.log(data.messages);
});
-
sendMessage
. Send a message. See the docs for more messaging info.
core.sendMessage({ message: 'Hey bro!' });
It's hard to get an ordered flow of messages when they are dropped from an external service almost instantly. Thanks to pipelines, you can create a listener for incoming messages in your application.
-
$sequence
. Used to get a sequential flow of messages.
core.pipelines.$sequence.subscribe(function (message) {
console.log(message);
});
-
$readableSequence
. Used to get a sequential flow of messages, including an extra delay between each one. Each delay is obtained from its previous message, improving readability.
core.pipelines.$readableSequence.subscribe(function (message) {
console.log(message);
});
-
$typingSequence
. Used to get a sequential flow of messages with their typing states. Each tick includes information about typing state, delay and message content.
core.pipelines.$typingSequence.subscribe(function (data) {
if (data) {
console.log(data);
}
});
-
"new_message"
. Triggered when a new message is received. Don't listen to this event unless you want to deal with a bunch of unordered messages. Use pipelines to get a correct flow of messages and render it on your app.
core.events.on('new_message', function (message) {
console.log(message);
});
-"database.error"
. Triggered when an error occurred in database.
core.events.on('database.error', function (data) {
console.error(data);
});