AI chat: How do I conditionally run an API based on a user's response?

Using OpenAI/ChatGPT, I can provide available time slots and other context that allows the assistant to supply available times; however, I'm not sure how to process the response in a way that can confidently trigger the API to schedule a visit.

Use case: Allow a user to book an appointment through SMS/chat. Steps:

  1. User: "Hi, I'd like to book a visit. Do you have availability Friday?"
  2. Assistant: "Yes, we have availability Friday at 2pm or 3pm. If that doesn't work we also have Monday at 10am available"
  3. User: "I'll take Friday at 3pm"

Desired Outcome:

  • Determine the correct time slot chosen by the user
  • Book the user

Hello @cjharlin! This is a pretty cool use case! How does your chat interface work? I would trigger a Retool Workflow when the user selects their time and send the user's response (e.g. "I'll take Friday at 3PM") to the Workflow.

Then, you can use Retool AI to parse the user response using an AI Actions query. I'd say there are two options for this.

  1. Use a Generate text AI Action and use a prompt of something along the lines of "Convert this statement from a user into a datetime timestamp. The format must be a unix timestamp.
    OR
  2. Use a Extract entities AI Action select date, time, and/or day as your entities to extract.

Once this is done, add a conditional block to the Workflow to confirm that the AI block outputted the date/time in the correct format. If it was correct, add a REST API (or whatever resource you need) block that calls your API with the date/time. If it was not in the correct format, add some error handling (such as sending yourself an email that it failed).

Let me know if you have any questions.

1 Like