English

⌘K
  1. Home
  2. English
  3. Flow Designer
  4. Execute some code

Execute some code

With the crafter.ai platform, you can have your chatbot execute code to clean a text from special characters entered by users, or to perform calculations, modify values, and so on.

To start using this feature, go to the flow designer and choose the option shown in the figure:

the chatbot executes some code

You will be able to decide whether to use Python or Javascript.

how to select javascript or python programming languages chatbot

At this point, by clicking on the gear icon you can directly access the editor:

ide chatbot programming interface

To read the value of the slots previously filled by the bot you can use the slots dictionary:

# reads the value of a slot and saves it in a variable
slot1 = slots["slot1"]
slot2 = slots["slot2"]

To modify or delete the value of the slots, you must define a variable with the name of the slot and assign it the desired value. The name of the slots to modify or delete must also be indicated in “Saved variables”. The value assigned to a slot must be representable in JSON (numbers, strings, lists, dictionaries, None)

# assigns a new value to slot1
slot1 = "new value"

# deletes slot2
slot2 = None

# creates the slot slot3 assigning it a new value
slot3 = "new value"

EXAMPLE OF USE

In this example we are going to create an order status check for an ecommerce and we will use the “bot runs some code” function to clean the string of any special characters before making an API call and returning the order status.

how to get order number to evaluate

At this point we will write the string cleaning code:

clean a chatbot text string

Now that the string is clean of any special characters we can call our API to check the status of the user’s order:

call an external API after cleaning the string