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 the chatbot executes some code](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/the-chatbot-executes-some-code.webp?resize=1024%2C614&ssl=1)
You will be able to decide whether to use Python or Javascript.
![how to select javascript or python programming languages chatbot how to select javascript or python programming languages chatbot](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/how-to-select-javascript-or-python-programming-languages-chatbot-.webp?resize=560%2C658&ssl=1)
At this point, by clicking on the gear icon you can directly access the editor:
![ide chatbot programming interface ide chatbot programming interface](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/ide-chatbot-programming-interface.webp?resize=1024%2C555&ssl=1)
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 how to get order number to evaluate](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/how-to-get-order-number-to-evaluate-1024x429.webp?resize=1024%2C429&ssl=1)
At this point we will write the string cleaning code:
![clean a chatbot text string clean a chatbot text string](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/clean-a-chatbot-text-string.webp?resize=1024%2C559&ssl=1)
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 call an external API after cleaning the string](https://i0.wp.com/crafter.ai/wp-content/uploads/2024/06/call-an-external-API-after-cleaning-the-string.webp?resize=1024%2C520&ssl=1)