Use Google Cloud Functions to set directly new values to Landbot variables

Sometimes we might need to transform, create or give a value to a Landbot variable and use it immediately. Currently to do this set the value of a Landbot variable with Javascript, a part from the Landbot-custom-data method, needs a user input, like a Text question or a button, before we can use that variable to be displayed or used for example in a Conditional Block

Here, you can find another approach that allow you to use a new value without the need of a user input.

In this example, we are going to ask for a date and, if the user has selected a weekend, we will force the user to select another date showing again the date picker.

If you need more information about setting up Google Cloud Functions, please check here for the Google official guide to use the Console

Below the flow:

  1. Select Date Question (in this case we will use the MM/DD/YYYY format);

  1. Add a Webhook block (add a fake url, so we can Save temporarily we will change it later on);

  1. Set up a Conditional block with the desired value, in this case will be @isweekend;

  1. If True (Green Dot) we will create a flow to continue as normal.
  2. If False (Red Output) we will display a Error Message suggesting to select another date and connect it to the date question.
  3. At this point we will need a Google Cloud Function, here we will create the script that will check the day of the week and return True or False (as a String, Landbot doesn't recognise Boolean values, and transforms true to True and false to False);

  1. Once the Function is deployed, we can get the Endpoint from the Trigger section;

  1. Now, we return to the Webhook block to test the Endpoint with the body, so we can get variable where we are going to store the @isweekend value;

And we will Test to set up the Landbot variable;

  1. Once the Save response is set up correctly, we can set the body with the variable from the Date question and Save the Webhook;

  1. Finally we can run the bot:


How did we do?