Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,73 @@ async function runFlow() {
runFlow();
```

## Run a Flow with Tweet Data

Flow inputs can include arrays and nested objects. This example loads a
[TweetClaw](https://github.com/Xquik-dev/tweetclaw) JSON export and passes the
tweet text into a flow for enrichment, routing, or review:

```typescript
import { readFile } from "node:fs/promises";
import { GumloopClient } from "gumloop";

type TweetRecord = {
text?: unknown;
};

function getTweetRecords(exportData: unknown): unknown {
if (Array.isArray(exportData)) {
return exportData;
}

if (exportData && typeof exportData === "object") {
const root = exportData as Record<string, unknown>;
if ("tweets" in root) {
return root.tweets;
}
if ("data" in root) {
return root.data;
}
if ("results" in root) {
return root.results;
}
return [root];
}

return [];
}

async function loadTweetText(path: string): Promise<string[]> {
const exportData = JSON.parse(await readFile(path, "utf8")) as unknown;
const records = getTweetRecords(exportData);

if (!Array.isArray(records)) {
return [];
}

return records.flatMap((item): string[] => {
const tweet = item as TweetRecord;
return typeof tweet.text === "string" ? [tweet.text] : [];
});
}

const client = new GumloopClient({
apiKey: "your_api_key",
userId: "your_user_id",
});

async function runTweetFlow() {
const output = await client.runFlow("your_flow_id", {
tweets: await loadTweetText("tweetclaw-export.json"),
source: "TweetClaw",
});

console.log(output);
}

runTweetFlow();
```

## Project-Level Usage

If you're working within a Gumloop project, you can initialize the client with a project ID:
Expand Down