Retool AI Actions for workflows quickstart
Learn how to use AI Actions in workflows to interact with AI models.
With Retool AI, you can build AI-powered workflows. AI actions enable you to interact with AI models using your data and perform a range of actions, such as:
- Generate, classify, and summarize text.
- Generate images.
- Generate chat responses.
AI actions are available to in both apps and workflows. The following guide explains how to create a workflow that is triggered by a webhook whenever a customer submits a returns request. It uses AI to determine if the customer is requesting a refund or replacement, then responds to the customer with relevant information using Retool Email.
For the purposes of this guide, you can trigger the workflow manually or using a curl
command to simulate the receipt of a message.
To get started, sign in to your Retool organization, navigate to the Workflows tab, then click Create new > Workflow.
1. Configure the trigger
You can configure a workflow to trigger automatically whenever it receives a webhook notification. The workflow can use the data from the event's payload and perform actions with it.
For testing purposes, you can specify a sample payload in the Test JSON Parameters of the Start block. When run manually, the workflow uses this information as an event payload.
- Replacement
- Refund
{
"message": "Subject: Issue with Certain Keys on VelocityX Pro Keyboard Support Ticket: 6000989 Customer Name: John Doe Email Address: john.doe99@notreal.com Shipping Address: 4127 Pine Street, Springfield, MA, 01101 Order Number: 345678-VXP Contact Number: (123) 456-7890 Issue: I received my brand new VelocityX Pro keyboard (Order Number: 345678-VXP) two days ago and I've started noticing that a few keys are intermittently not working while using. The keys R, T, Y, and Enter key are the problematic ones specifically. This is causing me a lot of disruption during my work as I use the keyboard extensively. Troubleshooting done so far: I attempted reinstalling the keyboard drivers and also tried plugging it into a different computer but the issue persists. I request your assistance in resolving this problem. I don't know whether I received a defective piece or this is a more widespread problem with this model. I’m happy to provide you with more information if necessary. Looking forward to hearing from you soon. Regards, John Doe.",
"test": true
}
{
"message": "Subject: Refund Request for Malfunctioning VelocityX Pro Keyboard Dear Support Team, I am writing to you with an urgent issue I am experiencing with the VelocityX Pro Keyboard that I recently purchased from your website. Some keys are not functioning as expected which is highly inconvenient and considerably impacts my usage. Order Details: Order Number: #VX456320 Item: VelocityX Pro Keyboard Delivery Date: June 15th, 2022 The problem began soon after the first few uses. The keys 'Q', 'E', 'J', and 'Space Bar' have stopped working completely, and some others occasionally miss keystrokes. I have tried unplugging and re-plugging as well as checking for drivers update, but nothing has worked. Given the above issue, I can't continue using this keyboard as needed for my daily work. Therefore, I would like to return it and request a refund as per your product return policy. Customer Information: Name: Jane Doe Email: JaneDoe@example.com Phone: (202) 555-0176 Please advise on the return process at your earliest convenience. I would appreciate a timely resolution to this matter, as it is causing significant disruption to my work. Thank you, and I am looking forward to your swift response on this matter. Best regards, Jane Doe.",
"test": true
}
These examples include test=true
to indicate that it's a test payload. This is used to control the recipient email address during testing.
2. Classify the message
Click the green button on the Start block to add a new connected workflow block, then select AI Action. You can use JavaScript and reference values almost anywhere in Retool using {{ }}
notation. Select the Classify text action and set the Input to {{ startTrigger.data.message }}
. This references the received event payload (or test payload) so it can be used with the AI Action. Double-click the block's name and set it to classifyMessage
.
Add replacement
and refund
to the Classification labels to instruct the AI model in how the message should be classified. When run, the AI model analyzes the message and determines if the customer is asking for a refund or replacement. When run, the AI model returns a category
key with a value of either replacement
or refund
.
3. Add conditional logic
The workflow should perform two different actions based on the classification. From classifyMessage
, add a Branch block and set the if statement to classifyMessage.data === 'replacement'
. This only allows the workflow to continue if the customer requests a replacement.
Since the workflow needs to perform different actions, click Add Condition to add an Else If statement, and set this to classifyMessage.data.category === 'refund'
This adds two paths to the workflow, each of which runs only if their condition is met.
4. Extract replacement information
If the customer requests a replacement, the workflow should identify relevant information from the message. The Extract entities from text AI Action can get specific information about provided text and return it as key-value pairs. In this case, this action extracts the relevant information needed to process a return.
Starting at the If statement, add another AI Action block and select Extract entities from text. Workflow blocks can reference data from any previously run block. Set the Input field to {{ startTrigger.data.message }}
, then enter the following values into the Entities to extract field.
customer name
email address
shipping address
order number
phone number
reason for return
Rename the block to getReturnsInfo
. When run, the query extracts this information from the message body.
5. Send an email to the customer
Retool enables you to send notifications using Slack, Microsoft Teams, Twilio, and more.
You can use Retool Email to send email notifications without the need for a custom SMTP server. The workflow responds to the customer with information depending on the reason.
You can reference the customer's email address using {{ getReturnsInfo.data['customer name'] }}
. To aid with testing, use a ternary operator to use your own email address if test=true
is in the event payload. This ensures you can test the workflow. Replace YOUR_EMAIL_ADDRESS
with your own email address.
- Replacement
- Refund
Add a Resource query block that is connected to getReturnsInfo and select the Retool Email resource. Since you can reference data from any previously run block using {{ }}
notation, you can reference the extracted text using values such as {{ getReturnsInfo.data['customer name'] }}
.
To: {{ startTrigger.data.test ? YOUR_EMAIL_ADDRESS : getReturnsInfo.data['email address'] }}
Reply-To: returns@example.com
Subject: RMA for order #{{ getReturnsInfo.data['order number'] }}
Hi {{ getReturnsInfo.data['customer name'] }},
Thank you for contacting us. To exchange your purchase,
please return the item to:
1234 Main Street
San Francisco
CA 94103
Once received, we will ship a replacement to:
{{ getReturnsInfo.data['shipping address'] }}
Thanks,
VelocityX
Add a Resource query block that is connected to the Else if statement of the Branch block and select the Retool Email resource.
To: {{ startTrigger.data.test ? YOUR_EMAIL_ADDRESS : getReturnsInfo.data['email address'] }}
Reply-To: returns@example.com
Subject: Refund request for order #{{ getReturnsInfo.data['order number'] }}
Hi {{ getReturnsInfo.data['customer name'] }},
Thank you for contacting us. To receive a refund,
please return the item to:
1234 Main Street
San Francisco
CA 94103
Once received, we will refund the purchase back
to the original payment method.
Thanks,
VelocityX
Test your workflow
Click Run to run the workflow. If you set Test JSON parameters to use the replacement message, you should receive an email with replacement instructions. If you used the refund message, you should receive an email with refund details.
You can also test your workflow with a CLI using cURL.
- CLick the ⚡︎ button in the sidebar to open the Triggers panel.
- Click ▼ in the Copy button and select Copy as cURL.
- Paste the copied command into your CLI.
The cURL command includes the contents of Test JSON Parameters to replicate a webhook event. Run the command to trigger the workflow and receive the desired message.
Wrap up
You have now built an AI-powered workflow that:
- Receives information using webhook events.
- Classifies a return request based on whether a refund or replacement is requested.
- Conditionally sends an email with either refund or replacement instructions.