Table of Contents

How to redirect visitors to a URL (web only)

Pau Sanchez Updated by Pau Sanchez

There are many reasons why you might want to redirect the user to another url. Here are different methods you can use in your bot to send your user to your desired destination

  1. Create a send message block with the text for the link
  2. Select the text you want to be a hyperlink

  1. Select the 3 dots (...) in the right bottom corner
  2. Select the link option

  1. A text input will be displayed. Type the url where you'll want a new tab to be opened and press the check option
  2. Now you will see the text with the link in blue

You can use Landbot variables too:


If you are planning to use variables, and expect that the value of the variable might contain spaces or other special characters, make sure to use the Encode() method with the Formula block before using the variable in the redirection, otherwise the url might fail.

In case you want to customise with HTML, you can do something like:

Check this <a href="@{newurl}" target="_blank">link</a>

Here @newurl is the link where we want the user to be redirected

Flow redirection same tab

In case we want the user to be redirected in the same tab as the bot

  1. First, we will create with a Set Variable the url where we want to redirect the user:
Do not use the variable @url as it's a Landbot system variable

  1. This step is optional, but it's good practice to tell the user that they're going to be redirected

  1. Then we use a Code block that will trigger the redirection function

Here is the code:

let landbotScope = this;
landbotScope.window.gotto("@{newurl}")

  1. Finally, we will go to the Desing > Custom Code > Add JS section to set up the function that will make the redirection

Here is the code:

<script>
let landbotScope = this;
this.onLoad(function() {
landbotScope.window.gotto = function(url) {
window.location.href = url
}
})
</script>

Other custom solutions:

With 5 seconds (5000 miliseconds) of delay before redirection:

<script>
let landbotScope = this;
this.onLoad(function() {
landbotScope.window.gotto = function(url) {
setTimeout(()=>{window.location.href = url}, 5000)
}
})
</script>

Open a new tab (this method might be restricted by some browsers):

<script>
let landbotScope = this;
this.onLoad(function() {
landbotScope.window.gotto = function(url) {
window.open(url, "_blank");
}
})
</script>

Goodbye block

This method is useful if you want to redirect the user at the end of the conversation

  1. Create a Goodbye Block
  2. Switch the "Redirect to url" option

  1. Type the url

You can use Landbot variables too:



If you are planning to use variables, and expect that the value of the variable might contain spaces or other special characters, make sure to use the Encode() method with the Formula block before to use the variable in the redirection, otherwise the url might fail.

Special redirections:

With redirections you can do more than just redirect to another url, here are some examples:

Link to Call phone number:

Instead of a regular url:

https://landbot.io

Use

tel:+3411223344

or with variables:

tel:@{phone}

Send Email

Instead of a regular url:

https://landbot.io

Use

mailto:feedback@landbot.io

or with variables:

mailto:@{email}

Whatsapp message:

Instead of a regular url:

https://landbot.io

Use

https://api.whatsapp.com/send?phone=34123123123

or with variables:

https://api.whatsapp.com/send?phone=@{phone}

Redirect user to PDF:

In this case, it's simple, just use the URL where the file is hosted, like this:

https://www.ikea.com/es/en/files/pdf/eb/42/eb42a602/cocinascolor-19-hfb-07-esp_1.pdf

Remember! If you are planning to use variables, and expect that the value of the variable might contain spaces or other special characters, make sure to use the Encode() method with the Formula block before to use the variable in the redirection, otherwise the url might fail.

How did we do?

How to calculate the number of days between two selected dates

Airtable usecase: Create an event registration bot with limited availability

Contact