@landbot/core
TypeScript icon, indicating that this package has built-in type declarations

3.3.0 • Public • Published

Landbot - Core

Landbot client core. Connects to the messaging database and the landbot app servers.

Getting started

Choose a way to get started with landbot-core.

ES6

npm install @landbot/core

Import it in your app.

import LandbotCore from '@landbot/core';

const core = new LandbotCore({
  ...config
});

Methods

  • 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!' });

Pipelines

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);
  }
});

Events

  • "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);
});

Examples

Dependents (0)

Package Sidebar

Install

npm i @landbot/core

Weekly Downloads

146

Version

3.3.0

License

MIT

Unpacked Size

37.9 kB

Total Files

60

Last publish

Collaborators

  • eduardo.ruiz
  • osama.nehme
  • david.gomz