Skip to main content
In this example, we use the Execute JavaScript block to calculate the delivery time based on the customer’s region.
  1. 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.
Example of Delivery Time: image 1
  1. Next, we save the customer’s response in the variable payload.state.
Example of Delivery Time: image 2
  1. 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.
Example of Delivery Time: image 3
  1. 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.