untitled-2198brownhaven_zillow_feed.ts13 matches
1617/**
18* Simplified proof-of-concept function to test API connectivity
19* This should return an immediate result we can inspect
20*/
3334try {
35log("Starting API test with Airtable");
3637// Test the most basic API call to verify connectivity
38const testUrl = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}?maxRecords=1`;
39log("Testing connection with URL", testUrl);
4044// First test - just check if we can connect at all
45const testResponse = await fetch(testUrl, { headers });
46log(`API response status: ${testResponse.status} ${testResponse.statusText}`);
4748if (!testResponse.ok) {
49const errorText = await testResponse.text();
50log("API Error", errorText);
51throw new Error(`API Error: ${testResponse.status} - ${errorText}`);
52}
535758// Now try with the view specified
59const viewUrl = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}?view=${VIEW_NAME}&maxRecords=1`;
60log("Testing with view specified", viewUrl);
6162const viewResponse = await fetch(viewUrl, { headers });
63log(`View API response status: ${viewResponse.status} ${viewResponse.statusText}`);
6465if (!viewResponse.ok) {
66const errorText = await viewResponse.text();
67log("View API Error", errorText);
68throw new Error(`View API Error: ${viewResponse.status} - ${errorText}`);
69}
707677// If we got here, we can fetch records successfully
78log("API connectivity test successful");
7980return {
81success: true,
82message: "API connectivity test successful",
83logs: debugLog,
84firstRecord: viewJson.records && viewJson.records[0] ? viewJson.records[0] : null,
mandateworkflowDefinition.ts1 match
83},
84config: { // Example of static config for a step, if fetchAgent could use it
85"static_api_key": "ui-test-fetch-key",
86"item_limit_from_initial": { source: "initial", field: "itemCount" } // Note: Engine currently doesn't resolve sources in step.config
87},
30do {
31// Using view ID in the URL
32const url = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_NAME}?view=${VIEW_NAME}&pageSize=100${
33offset ? `&offset=${offset}` : ""
34}`;
42if (!res.ok) {
43const errorText = await res.text();
44console.error(`API Error (${res.status}): ${errorText}`);
45throw new Error(`Airtable API error: ${res.status} - ${errorText}`);
46}
47
MiniAppStarterneynar.ts2 matches
1const baseUrl = "https://api.neynar.com/v2/farcaster/";
23export async function fetchNeynarGet(path: string) {
7"Content-Type": "application/json",
8"x-neynar-experimental": "true",
9"x-api-key": "NEYNAR_API_DOCS",
10},
11});
MiniAppStarterindex.tsx2 matches
19}));
2021app.get("/api/counter/get", async c => c.json(await db.get("counter")));
22app.get("/api/counter/increment", async c => c.json(await db.set("counter", (await db.get("counter") || 0) + 1)));
2324app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
MiniAppStarterimage.tsx3 matches
8485const loadEmoji = (code) => {
86// const api = `https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/${code.toLowerCase()}.svg`
87const api = `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_color.svg`;
88return fetch(api).then((r) => r.text());
89};
90
MiniAppStarterApp.tsx3 matches
53<div className="">✷ Farcaster mini app manifest + webhook + embed metadata</div>
54<div className="">✷ Farcaster notifications (storing tokens, sending recurring notifications, ...)</div>
55<div className="">✷ Neynar API integration for Farcaster data</div>
56<div className="">✷ Hosted on Val Town (instant deployments on save)</div>
57<div className="">
6768function Database() {
69const queryFn = () => fetch("/api/counter/get").then((r) => r.json());
70const { data, refetch } = useQuery({ queryKey: ["counter"], queryFn });
71return (
73{/* <h2 className="font-semibold">Database Example</h2> */}
74<div className="">Counter value: {data}</div>
75<Button variant="outline" onClick={() => fetch("/api/counter/increment").then(refetch)}>
76Increment
77</Button>
roseysendDailyBrief.ts8 matches
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
101const telegramToken = Deno.env.get("TELEGRAM_TOKEN");
102106}
107108if (!apiKey) {
109console.error("Anthropic API key is not configured.");
110return;
111}
122123// Initialize Anthropic client
124const anthropic = new Anthropic({ apiKey });
125126// Initialize Telegram bot
162163// disabled title for now, it seemes unnecessary...
164// await bot.api.sendMessage(chatId, `*${title}*`, { parse_mode: "Markdown" });
165166// Then send the main content
169170if (content.length <= MAX_LENGTH) {
171await bot.api.sendMessage(chatId, content, { parse_mode: "Markdown" });
172// Store the briefing in chat history
173await storeChatMessage(
198// Send each chunk as a separate message and store in chat history
199for (const chunk of chunks) {
200await bot.api.sendMessage(chatId, chunk, { parse_mode: "Markdown" });
201// Store each chunk in chat history
202await storeChatMessage(
53You'll need to set up some environment variables to make it run.
5455- `ANTHROPIC_API_KEY` for LLM calls
56- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.
8## Hono
910This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
1112## Serving assets to the frontend
20### `index.html`
2122The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
2324We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
2526## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
3132Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.