Execute
Executes a custom piece of code or tabular operation.
Execute Cards allow you to run custom JavaScript code within your bot’s workflow, providing a powerful way to extend the functionality of your bot beyond the built-in actions and logic. These Cards enable you to perform complex calculations, manipulate data, call external APIs, or execute any other custom logic directly within the bot flow.
Generate code with AI
The Execute Code card allows you to generate code using AI, so you don't have to write it all from scratch. At the top of the code editor, place the prompt for which you'd like to generate code, like fetching data from an API or manipulating a certain user input, and AI will generate code for you.
You're then free to edit this code further, or ask AI to make revisions to it.
Execute Cards Overview
Run Custom Logic
Execute Code Cards allow you to write JavaScript code to handle tasks that are not covered by standard Cards. This includes processing user input, transforming data, or implementing unique business logic.
Dynamic Interactions
Use Execute Code Cards to make your bot’s behavior dynamic. For example, you can use them to adjust responses based on user data, perform calculations, or interact with external services in real-time.
API Integrations
These Cards can be used to call external APIs, handle responses, and process the data within your bot. This capability allows seamless integration with third-party services directly through JavaScript.
Access to Bot State
You can interact with the bot’s state, modify variables, and store information that can be used later in the conversation flow. This allows your bot to maintain context and provide more personalized interactions.
Error Handling
Implement custom error handling within your code to manage exceptions, ensure robust operations, and gracefully handle unexpected situations during execution.
Table Cards
Execute cards also allow you to perform operations on the data you have stored in a Table.
Info
Table cards do not directly display their result. You'll need to first save the data in variables to be able to use them in the conversation.
Get Record
To retrieve a specific record from a table, use the Get Record card. For example, you might use the Get Record operation to retrieve a user's profile information based on their unique user ID. Here's how to do it:
- Add the
Get Record
card to the desired node - Select the table you want to get the record from.
- Select the record ID you want to retrieve. You can either select a default ID or use variables. For example, if you want to get a user's profile information, you can specify their user ID as the unique identifier here.
- Choose the result variable that will store the record data. (This variable needs to have the Object type since table records are objects.)
- Now you use the variable in subsequent cards to access the record data.
Insert Record
To create a new record in a table, use the Insert Record card. This operation can be particularly useful when you need to store new information, such as a new user's details or a newly completed transaction. Here's how to do it:
- Add the
Insert Record
card to the desired node - Select the table where you want to insert the record.
- Define a value for each field. You can either define a value manually or use variables.
- You're done, once the conversation goes through this card, the record will be created in the table.
Update Record
To update a record in a table, use the Update Record card. For example, you might use this operation to update a user's profile information or to update the status of a transaction. Here's how to do it:
- Add the
Update Record
card to the desired node - Select the table where you want to update the record in.
- Select the record ID you want to update. You can either select a default ID or use variables. For example, if you want to update a user's profile information, you can specify their user ID as the unique identifier.
- Click on "Add properties to update" and select the columns you want to change. For each column, you can define a value manually or use variables.
- You're done, once the conversation goes through this card, the record will be updated in the table.
Delete Record
The Delete Record operation enables you to remove a specific record from a table based on a unique identifier. For instance, you might use this operation to delete a user's data if they choose to deactivate their account. Here's how to do it:
- Add the
Delete Record
card to the desired node - Select the table where you want to delete the record from.
- Select the ID of the record you want to delete. You can either select a default ID or use variables.
- You're done, once the conversation goes through this card, the record will be deleted from the table.
Reminder
Be careful when using this card. Ensure you are deleting the correct record and that you no longer need it. Deleted records cannot be recovered!
Find Records
The Find Records operation allows you to search for and fetch multiple records that match certain criteria. This operation is beneficial when you need to handle multiple related records at once, such as fetching all transactions made by a specific user. Here's how to do it:
- Add the
Find Records
card to the desired node - Select the table where you want to find records.
- Define your filter criteria in natural language. You can also use variables to make this query dynamic like:
Price is below ${workflow.maxPrice}
. - Choose the result variable that will store the records data. (This variable needs to have the Array type because multiple table records are stored in arrays)
- Now you can use the variable in subsequent cards to access the records data.
Tip
Tables provide a robust way to manage data within your chatbot, offering flexibility to handle a wide variety of scenarios that involve data persistence, retrieval, and manipulation.
Updated 3 months ago