Landbot.Widget

Base class shared by every Landbot widget. Constructor, properties, methods, and events.

Base class. All landbot widgets inherit from Landbot.Widget.

Constructor

Landbot.Widget

Landbot.Widget(config)

Parameters:

  • config: Object

This is not the common way to create a Landbot Widget, but all widgets extend from this class, so they can call its methods.

Properties

config

Type: Object

The config object is initially passed with configUrl and populated remotely to get the full customization from the builder platform.

core

Type: Landbot.Core

All landbot widgets use a Landbot.Core instance internally doing all the "backend stuff".

window

Type: Object

The window object associated to the widget frame. If not embedded, window.top === this.window.

document

Type: Object

The document object associated to the widget frame. window and document are exposed here to get access to the DOM and other features in landbot javascript execution.

Methods

sendMessage

sendMessage(message)

Parameters:

  • message: Object

Returns:

  • Promise

Sends a message to the bot from the client side. See Messages for more info about message structures.

setCustomData

setCustomData(data)

Parameters:

  • data: Object

Set variables. Go to Setting variables to see an example.

onLoad

onLoad(func)

Parameters:

  • func: Function

Pass a function to be executed just after the widget initialization and rendering.

var myLandbot = new Landbot.Native({ ... });

myLandbot.onLoad(function() {
  console.log('Load complete!');
})

destroy

destroy()

Destroy widget instance and remove all of its DOM elements and listeners.

Events

"load"

Listening to the "load" event has the same effect as using the "onLoad" method from the widget instance.

"new_message"

New message received event. It's a core event

"proactive_open"

Show proactive event.

"proactive_close"

Closed proactive event.

"send_message"

Sending message event.

"widget_open"

Widget opening (livechat, popup) event.

"widget_close"

Widget closing (livechat, popup) event.

Examples of widget events

var myLandbot = new Landbot.Livechat({ ... });

myLandbot.core.events.on('load', function() {
  console.log('Load complete!');
});

myLandbot.core.events.on('widget_open', function() {
  console.log('Landbot livechat was opened!');
});

myLandbot.core.events.on('proactive_close', function() {
  console.log('Livechat proactive message was closed!');
});