How to encode a variable
It is common that some inputs from the users need to be processed so that they can be recognised as valid URLs by any API.
You will see in some URLs, that when you are using two words with a space, it becomes something like this: firstname%20lastname, you can do it manually but it will be painful. To fix it, here I have a solution step by step.
- Once you selected the variable in Landbot that needs to be encoded, we will add a Code block:
- In the Code block we will add the following code, where "toencode" is the variable that you want to have encoded, and "encodedvariable" is the new variable where the encoded value will be set. You can also change the names as you need.
- Now, we have a new variable called @encodedvariable, but it's value cannot be used inside Landbot yet. To be used we need to add a user input, like a Buttons type of question. Here we have an example of how it can be set:
- Once we pass the user input, then when we can use our new encode variable in a url or a webhook