Table of Contents

Trigger a Global Keyword with JS (web v3)

Pau Sanchez Updated by Pau Sanchez

Global Keywords allows you to set paths, based on a specific Keyword. Thanks to Landbot SDK we can trigger a Message via Javascript, that can trigger the sending of a message, that will trigger the global Keyword and redirect the use to the specific step

To know more about Global keywords, please check this

Order of actions:

  1. Code block triggers function
  2. Function triggers SDK
  3. SDK sends message with keyword
  4. Global Keyword Triggered
  5. Flow redirected

Flow in the builder:

In the bot:

  1. We need to set up the function that will trigger the SDK sending message:

<script>
let landbotScope = this;
this.onLoad(function() {
landbotScope.window.messageUser = function() {
landbotScope.sendMessage({ type: 'button', message: 'welcome'})
}
});
</script>

Note, you can customise the input to be sent. In the example above we send the keyword "welcome"

  1. To trigger the "messageUser" function we just create, we will add a Code block with the following code:
this.window.messageUser()

Obviously you can pass variables from the bot:

this.window.messageUser('@{variable}')

It's important that this code block is not connected after with any other block, or the messages will be displayed without order

How did we do?

How to display an HTML Table and a List in Landbot v3 web

Create Dynamic Shopping Cart with JS and CSS

Contact