Introduction

A Code block can be used for any complex/custom use cases which the other blocks are not able to satisfy. Some of the example use-cases:

  1. Parsing API Response: Write code to parse response of any API called using the Rest API block.
  2. Calling Complex APIs: Use custom code to call complex APIs where the Rest API block can't do the job.
  3. Custom Validations: Write business-specific validations for user's input like validating order ids, PAN card no., social security no., etc. 


Concepts

  • User Actions: You will be able to perform two user actions from the code:
    • Send Message: You can create any the message using your custom logic and then can send that message to the user.
    • Set Property: You can also set/save properties to reflect in the user-profile. These properties can be used later to personalize the conversations.
  • Other Actions: Apart from these you can also take other actions like making API calls, parsing JSON, etc.
  • Error Email: An email will be sent to this email address, whenever any error/exception comes while compiling/executing the code.


Writing Code

When you use the Code block, you will have to write a function/method with the logic you want to implement. You don't have to worry about anything else like class, import, etc.


Currently, you can write code in two languages. Please click on the language of your choice to learn how to write code using the Code block: