Table of Contents

Trigger Event if User Abandons Chat

Abby Updated by Abby

Trigger Event with Pipedream

If a user abandons a chat there are several actions we can take to get them to re-engage.

Here we will use Pipedream, where we will set a delay to a custom amount of time, then after that time has passed we will launch the bot assigning the user to a conditions block, this conditions block will check if the variable 'flow completed' is false, if so we have several options, if we've already obtained their email address we can add a 'Send an email' block to send them an email and re-engage them

For WhatsApp we could add a 'Send an HSM' block after the condition 'flow completed' has been verified

The flow:

At the beginning of our flow we have the variable 'flow_complete' that equals false, if you change the name of this variable you will need to change condition block as well

At the end of our flow we will change 'flow_complete' to true, this means we won't send any follow up if they reach this point, we will simply close the chat

Pipedream:

The first module we use here is a trigger, this takes in the user ID from Landbot (we'll get to that later)

This is what the configuration will look like:

Next we'll copy the unique URL that it gives us:

Let's go back to the bot, we'll add a Trigger Automation block with the following test values:

We'll test this using 'Test webhook trigger' just to be sure we've got the right URL, it should return a 200 in Landbot, and the results should look like this in Pipedream:

Let's press continue

Next we'll add the workflow_delay module, we can select seconds, minutes, or hours. I've selected 23 hours for the bot in production, however for testing I've selected 8 seconds

Let's press continue.

Next we'll add an HTTP PUT request module, here you'll add the following url:

https://api.landbot.io/v1/customers/{{steps.trigger.event.body.id}}/assign_bot/XXXXXX/

Make sure that {{steps.trigger.event.body.id}} is correctly pointing to the ID you sent in the trigger

You'll also need the bot ID (this is the ID in the url of your bot), and the block ID of the condition (see photo below)

We'll need two keys, launch true and node XXXXX:

For the block ID you'll add the key launch and the value will be the Conditions block ID

You'll add the bot ID to the end of the url (https://api.landbot.io/v1/customers/{{steps.trigger.event.body.id}}/assign_bot/BOT_ID_HERE/):

The last step is to add the headers, you will need your API key for this:

Get your API Token from here.

Trigger Event with Zapier

This workaround requires a paid Zapier account

If a user abandons a chat there are several actions we can take to get them to re-engage.

Here we will use Zapier, where we will set a delay to a custom amount of time, then after that time has passed we will launch the bot assigning the user to a conditions block, this conditions block will check if the variable 'flow completed' is false, if so we have several options, in this example we'll add a 'Send an HSM' block after the condition 'flow completed' has been verified

In order to follow up with WhatsApp the user must be opted-in, to do this you can simply include an opt-in block at the beginning of the flow - if the users are already opted-in you don't need to take any further action

The flow:

At the beginning of our flow we have the variable 'flow_complete' that equals false, if you change the name of this variable you will need to change condition block as well

At the end of our flow we will change 'flow_complete' to true, this means we won't send any follow up if they reach this point, we will simply close the chat

Zapier:

The first module we use here is a webhook, this takes in the user ID from Landbot (we'll get to that later)

This is what the configuration will look like:

Next we'll copy the unique URL that it gives us:

Let's go back to the bot, we'll add a Trigger Automation block with the following test values:

The ID should be a real customer ID, you can find this in the chats section under their name

We'll test this using 'Test webhook trigger' just to be sure we've got the right URL, it should return a 200 in Landbot, and the results should look like this in Zapier:

Let's press continue

Next we'll add the delay by Zapier module, then we select 'delay for' we can select minutes, or hours. I've selected 23 hours for the bot in production, however for testing I've selected 2 minutes

Let's press continue and test this step.

Next we'll add another webhook module, this time we'll select PUT

here you'll add the following url:

https://api.landbot.io/v1/customers/XCUSTOMER IDX/assign_bot/XBOT IDX/

Make sure that XCUSTOMER IDX is correctly pointing to the ID you sent in the trigger, you can click on the plus icon and add it from the 'catch hook' step:

You'll also need the bot ID (this is the ID in the url of your bot), and the block ID of the condition (see photo below)

We'll select payload type JSON, then we'll add two data value sets, launch true and node XXXXX:

For the block ID you'll add the key launch and the value will be the Conditions block ID

You'll add the bot ID to the end of the url (https://api.landbot.io/v1/customers/XCUSTOMER_IDX/assign_bot/BOT_ID_HERE/):

The last step is to add the headers, you will need your API key for this:

Get your API Token from here.

Alternative: Node.JS (Pipedream)

You will need a developer to help you with this

If you would like to do more custom actions you can use the below workflow, this involves code and you will likely need a developer or someone technical to help you set it up

In this example, we wait 48 hours after the chat has been initiated, then use Pipedream to check the Landbot API to see if the variable we added for 'flow completed' is false, if so we send a follow up message with an HSM template

However, if we set the timer to 23 hours (within the 24 hour window) you could also assign them to a webhook block to create a ticket in Zendesk or Intercom, or simply send a message without the need to use HSM

The flow:

We can make our flow as complicated, or as simple as we'd like, the important things here are the variables and the Trigger Automation block

At the beginning of our flow we need a variable 'completedflow' that equals false, if you change the name of this variable you will need to change the code in Pipedream, so unless you have a developer it's not advised to change the name here

At the end of our flow we will change 'completedflow' to true, this means we won't send any follow up if they reach this point

Let's go to Pipedream now (you can use this Pipedream template to get started)

Pipedream:

The first module we use here is a trigger, this takes in the user ID from Landbot (we'll get to that later)

This is what the configuration will look like:

Next we'll copy the unique URL that it gives us:

Let's go back to the bot, we'll add a Trigger Automation block with the following test values:

We'll test this using 'Test webhook trigger' just to be sure we've got the right URL, it should return a 200 in Landbot, and the results should look like this in Pipedream:

Let's press continue

Next we'll add the workflow_delay module, we can select seconds, minutes, or hours. I've selected 48 hours for the bot in production, however for testing I've selected 8 seconds

Let's press continue.

Next we'll add a Node.JS module, here you'll need to add your own API Token where you see XXXXXX, and change the HSM template ID for the one you choose to send.

Get your API Token from here.

You can paste the following code in the Node module to send a Template:

import axios from 'axios';
export default defineComponent({
async run({ steps, $ }) {
const customerID = steps.trigger.event.body.id;
const res = await axios.get('https://api.landbot.io/v1/customers/' + customerID + '/', {
headers: { 'Authorization': 'Token XXXXXXXXXXXXXX' }});
let completedFlow = res.data.customer.completedflow;
console.log(completedFlow);
if(completedFlow == 'false'){
let auth = 'XXXXXXXXXXXXXXXXXX';
const options = {headers: {'Content-Type': 'application/json','Authorization': 'Token ' + auth}};
return await axios.post(`https://api.landbot.io/v1/customers/${customerID}/send_template/`, {"template_id": 3424,"template_params": { "header": { "params": [] }, "body": { "params": [] }, "buttons":[ { "params": [] } ] },"template_language": "en"} , options)
}
else{
}
}
})

Let's test, deploy and start using our workaround!

In addition to send a Template, you can perform other actions using the Landbot API:

  1. In case you need just to Send a Text, use this code instead:
import axios from 'axios';
export default defineComponent({
async run({ steps, $ }) {
const customerID = steps.trigger.event.body.id;
const res = await axios.get('https://api.landbot.io/v1/customers/' + customerID + '/', {
headers: { 'Authorization': 'Token XXXXXXXXXXXXXX' }});
let completedFlow = res.data.customer.completedflow;
console.log(completedFlow);
if(completedFlow == 'false'){
let auth = 'XXXXXXXXXXXXXXXXXX';
const options = {headers: {'Content-Type': 'application/json','Authorization': 'Token ' + auth}};
return await axios.post(`https://api.landbot.io/v1/customers/${customerID}/send_text/`, { "message": "Hello" } , options)
}
else{
}
}
})

  1. If you'd like to Close the Conversation you can use this snippet:
import axios from 'axios';
export default defineComponent({
async run({ steps, $ }) {
const customerID = steps.trigger.event.body.id;
const res = await axios.get('https://api.landbot.io/v1/customers/' + customerID + '/', {
headers: { 'Authorization': 'Token XXXXXXXXXXXXXX' }});
let completedFlow = res.data.customer.completedflow;
console.log(completedFlow);
if(completedFlow == 'false'){
let auth = 'XXXXXXXXXXXXXXXXXX';
const options = {headers: {'Content-Type': 'application/json','Authorization': 'Token ' + auth}};
return await axios.put(`https://api.landbot.io/v1/customers/${customerID}/archive/`, options)
}
else{
}
}
})

  1. If you want to Assign the customer to a specific point in the bot flow you can use this snippet:
import axios from 'axios';
export default defineComponent({
async run({ steps, $ }) {
const customerID = steps.trigger.event.body.id;
const bot_id = XXXXX;
const block_id = XXXXX;
const res = await axios.get('https://api.landbot.io/v1/customers/' + customerID + '/', {
headers: { 'Authorization': 'Token XXXXXXXXXXXXXX' }});
let completedFlow = res.data.customer.completedflow;
console.log(completedFlow);
if(completedFlow == 'false'){
let auth = 'XXXXXXXXXXXXXXXXXX';
const options = {headers: {'Content-Type': 'application/json','Authorization': 'Token ' + auth}};
return await axios.put(`https://api.landbot.io/v1/customers/${customerID}/assign_bot/${bot_id}/`, { "launch": true, "node": block_id} }, options)}
else{
}
}
})

How did we do?

Recognise the users input when sending a Message Template with buttons

Calculate Distances in WhatsApp

Contact