Working with Tables
In Botpress, tables allow you to store and manage structured data that can be used in the conversation flow. The data in these tables can be read and written using Execute Code cards or Table cards. This guide provides an overview of how to use Table cards to create, read, update, delete, and find records in tables.
Table cards do not directly display the result. You'll need to first save the result in a variable and then use it in the conversation.
Retrieve a Record
To retrieve a specific record from a table, use the Get Record card. This is useful when you know the record ID. Here's how to do it:
- Select the table from which you want to retrieve the record.
- Select the record ID you want to retrieve. You can either select a default ID or use variables.
- Choose the result variable that will store the record data. (This variable needs to be an Object type as table records are objects.)
Add a New Record
To insert a new record into a table, use the Insert Record card. Here's how:
- Select the table where you want to insert the record.
- Define a value for each column. You can either define a value manually or use variables.
Update an Existing Record
To update a record in a table, use the Update Record card. Here's how:
- Select the table where the record is located.
- Select the record ID you want to update. You can either select a default ID or use variables.
- 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.
Delete a Record
To delete a record from a table, use the Delete Record card. Here's how:
- Select the table where the record is located.
- Select the record ID you want to delete. You can either select a default ID or use variables.
Be careful when using this card. Ensure you are deleting the correct record and that you no longer need this record. Deleted records cannot be recovered.
Find Records
To retrieve multiple records based on specific criteria, use the Find Records card. Here's how:
- Select the table where you want to find records.
- Define your criteria with a filter expression in natural language. You can also use variables for dynamic queries.
- Choose the result variable that will store the records data. (This variable needs to be an Array type as table records are arrays.)