Table of Contents

Resume flow based on external process with Landbot API (Request, Set, Go)

Ana Updated by Ana

There are flows, that need an external process to be done to resume before the user can proceed. And at the same time, that process might be conditioned. For example a payment processed that is being done outside Landbot.

Here we will explain the basic concepts you can use to make this flow possible:

1st - Request

First of all we have a flow where we request the data that we will need, in this example name and email:

After, before we trigger the request, we need to set up a Set Variable block, with the variable that we will set with the value from the external service. The best approach is to use an empty object:

Here we use the variable @data type ARRAY, which will be an empty object

Right after we add the Webhook block that will trigger all the process.

It is paramount, to pass in this request 3 properties, that we will need later in to the Set and Go steps:

1. Bot id

You can find the bot id in the url of the builder, in the example below we can see that is the 1010178

2. Block id (you can do it later)

We need to indicate to the bot, where to resume from the flow. To do that we will select the Formula block that we will use later. Press 3 dots on that block to copy the Block id:

In this case the id of this Formula block is "Nkqgn6xkf"

3. Customer Id

Last the customer_id is the value of the variable @id

So we can use this data in the body of our webhook, among the rest of the required data:

Obviously you can adapt the payload to your API requirements.

After the Webhook block, we are going to display a message to the user, that they should wait until the process is resolved:

As you can see, the last block is not connected. The "jump to" the other block, to continue, will be done from your custom externa service using Landbot API

2nd - Set

To set the values, from the external service we will use the API method called "customerFields -Change", as we are not creating such variable, it will be the PUT method.

We created previously the @data variable to hold the data, therefore the request will be as follows:

curL:

curl --location --request PUT 'https://api.landbot.io/v1/customers/:customer_id/fields/data/' 
\--header 'Content-Type: application/json'
\--header 'Authorization: Token {{YOUR API TOKEN}}'
--data-raw '{ "type": "object", "extra": {}, "value": {"status":{{status}}}}'

3rd - Go

To "go", to resume the flow, we need another API method, this time will be the Customers - Assign bot method:

As you can see here, we will need the customer_id, the bot_id and the block_id. Below we will is code you can use. Note also that "launch" value should be true.

curl --location --request PUT 'https://api.landbot.io/v1/customers/:customer_id/assign_bot/:bot_id/' 
\--header 'Content-Type: application/json'
\--header 'Authorization: Token {{YOUR API TOKEN}}'
\--data-raw '{ "launch": true, "node": "{{block_id}}"}'

Now, that we have the variable @data, and the bot is "going" we can extract the data from the variable @data, to do so, the best approach will be using the Formula block, right where the flow continues:

And finally, once we have the flow going, and we extracted the value of "status" and store it in a Landbot variable called @status, we can use for example a Conditional block to decide which message are we going to show to the user:

How did we do?

MessageHooks - Landbot Webhooks

Contact