Example Codes
Delivery Time
In this example, we use the Execute JavaScript block to calculate the delivery time based on the customer’s region.
- First, within the automation structure, we ask the customer to send the abbreviation corresponding to the state they live in. For example: Send “SP” for those who live in São Paulo.
- Next, we save the customer’s response in the variable
payload.state
.
- In Execute JavaScript, we use the variable
payload.state
to run the code that checks the delivery time based on the region provided by the client.
- Finally, the result of the code will be saved in the variable
payload.deadline
, which is sent to the client in the last message indicating the delivery time according to the informed region.
Note: In the example, we also implement error handling in the code, so if the abbreviation provided by the client does not correspond to any Brazilian state, an error message will be displayed requesting them to try again.