Skip to main content

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:

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.

Sample replacement request
{
"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
}

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

Send other types of notifications

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.

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'] }}.

Example message

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

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.

  1. CLick the ⚡︎ button in the sidebar to open the Triggers panel.
  2. Click in the Copy button and select Copy as cURL.
  3. 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.