Install Recase

Install Recase in your project by running the following command:

npx recaseai init

A workflow.ts file will be created in your project. This is where we’ll write our workflow.

Defining inputs

Inputs are the fields that are required to run your workflow. In this case, we’ll need:

  1. A payment ID
  2. A query to answer about the payment
export default recase.workflow({
  id: "Query payment details",
  inputs: {
    paymentId: {
      name: "Payment ID",
      type: "string",
    },
    query: {
      name: "Query",
      type: "string",
    },
  }
});

Building the workflow

Now we’ll write our script to get the payment details from Supabase and answer the query.

import recase from "recaseai";
import { createClient } from "@supabase/supabase-js";

// Initialize Supabase client
const supabase = createClient(
  process.env.SUPABASE_URL || '',
  process.env.SUPABASE_KEY || ''
);

export default recase.workflow({
  //Workflow name and inputs as defined above
  id: "Query payment details",
  inputs: {
    paymentId: {
      name: "Payment ID",
      type: "string",
    },
    query: {
      name: "Query",
      type: "string",
    },
  },

  run: async ({ inputs }: any) => {

    // Query payment details from Supabase
    const { data: paymentData, error } = await supabase
      .from('payments')
      .select('*')
      .eq('payment_id', inputs.paymentId)
      .single();

    if (error) {
      throw new Error(`Failed to fetch payment: ${error.message}`);
    }

    // Use LLM to analyze payment data and answer query
    const answer = await recase.llm({
      message: `Given this payment information: ${JSON.stringify(paymentData)}
                Please answer this question: ${inputs.query}`,
      model: 'claude-3-5'
    });

    recase.log("Answer: ", answer);
  },
});

Deploying

To deploy our workflow, we’ll use the recase deploy command in your terminal.

npx recase deploy --file workflow.ts

You can create and deploy multiple workflow files in your project.

Running your workflow

Workflows can be run via the Recase UI, via API or invoked via natural language on Slack. Here we’ll connect to Slack and run the workflow from there.

1

Connect to Slack

Go to your Recase dashboard and click “Connect to Slack”. Follow the prompts to authorize Recase in your workspace.

2

Run workflow with slash command

In any Slack channel, type /rc followed by your request. Recase will search for a matching workflow and execute it. For example: /rc why was payment_239478239 declined?

3

View workflow results

Recase will confirm the workflow has started. View the workflow logs in the Recase Dashboard, and the issue in Linear.

Questions? Chat to us about anything at founders@recaseai.com 😄