Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/image-url.jpg%20%22Image%20title%22?q=api&page=44&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 11775 results for "api"(470ms)

myApi1 file match

@dgiulian•Updated 1 year ago

myApi1 file match

@thyme•Updated 1 year ago

myApi1 file match

@deverts•Updated 1 year ago

myApi1 file match

@dcalsky•Updated 1 year ago

fetchValTownAPI2 file matches

@pomdtr•Updated 1 year ago

myApi1 file match

@patrickwire•Updated 1 year ago

myApi1 file match

@domru•Updated 1 year ago

myApi1 file match

@marydotdev•Updated 1 year ago

testApi2 file matches

@andreterron•Updated 1 year ago

myApi1 file match

@timur•Updated 1 year ago

Flarum-Discussion-To-PlainTextapp.tsx2 matches

@tyler71•Updated 38 mins ago
120async function getDiscussionPosts(discussionId: string): Promise<PostT[]> {
121 // Used to get the list of post id's for the discussion.
122 const discussionRes = await fetch(`${server}/api/discussions/${discussionId}`);
123 const discussionResJson = await discussionRes.json();
124
132
133 await Promise.all(chunks.map(async (c: string[]) => {
134 const postRes = await fetch(`${server}/api/posts?filter[id]=${c.join(",")}`);
135 const postJson = await postRes.json();
136

whatsapp-callbackindex.tsx20 matches

@yawnxyz•Updated 39 mins ago
8// Environment variables should be set in your Val Town val's settings
9const WHATSAPP_WEBHOOK_VERIFY_TOKEN = Deno.env.get("WHATSAPP_WEBHOOK_VERIFY_TOKEN");
10const WHATSAPP_GRAPH_API_TOKEN = Deno.env.get("WHATSAPP_GRAPH_API_TOKEN");
11const WHATSAPP_BUSINESS_ID = Deno.env.get("WHATSAPP_BUSINESS_ID");
12
42// --- Helper Functions ---
43async function sendWhatsAppMessage(phoneNumber, businessId, text, originalMessageId) {
44 if (!WHATSAPP_GRAPH_API_TOKEN || !businessId) {
45 console.error("WhatsApp API token or business ID is missing. Cannot send message.");
46 return;
47 }
54 method: "POST",
55 headers: {
56 "Authorization": `Bearer ${WHATSAPP_GRAPH_API_TOKEN}`,
57 "Content-Type": "application/json",
58 },
120 console.log(`[initiateChat] Sending to CF Orchestrator (${CLOUDFLARE_WORKER_ORCHESTRATOR_URL}/initiate-async-chat) for ${userIdentifier}:`, JSON.stringify(mcpPayload, null, 2));
121
122 const mcpApiResponse = await fetch(`${CLOUDFLARE_WORKER_ORCHESTRATOR_URL}/initiate-async-chat`, {
123 method: "POST",
124 headers: { "Content-Type": "application/json" },
126 });
127
128 if (!mcpApiResponse.ok) {
129 const errorText = await mcpApiResponse.text();
130 console.error(`[initiateChat] Error from CF Orchestrator for ${clientRequestId}: ${mcpApiResponse.status} ${mcpApiResponse.statusText}`, errorText);
131 await sendWhatsAppMessage(userIdentifier, businessPhoneNumberId, "Sorry, I couldn't start a session with the assistant.", originalMessageId);
132 return { error: true, details: errorText };
133 } else {
134 const mcpResponseData = await mcpApiResponse.json();
135 console.log(`[initiateChat] Response from CF Orchestrator for ${clientRequestId} (Status ${mcpApiResponse.status}):`, mcpResponseData);
136 return { error: false, data: mcpResponseData };
137 }
234 console.log(`[PROCESS] Initiating async for ${userPhoneNumber} (hash: ${queryHash || 'N/A'}).`);
235
236 if (WHATSAPP_GRAPH_API_TOKEN && business_phone_number_id) {
237 await initiateChatWithMCPOrchestrator(userQuery, userPhoneNumber, originalMessageId, business_phone_number_id);
238 try { // Mark as read
239 console.log(`Marking read for ${userPhoneNumber} (msg_id: ${originalMessageId})`);
240 const markReadResp = await fetch(`https://graph.facebook.com/v18.0/${business_phone_number_id}/messages`, {
241 method: "POST", headers: {"Authorization": `Bearer ${WHATSAPP_GRAPH_API_TOKEN}`, "Content-Type": "application/json"},
242 body: JSON.stringify({messaging_product: "whatsapp", status: "read", message_id: originalMessageId}),
243 });
246 } catch (e) { console.error(`Failed to mark read for ${userPhoneNumber}:`, e); }
247 } else {
248 console.error("WHATSAPP_GRAPH_API_TOKEN or business_phone_number_id missing.");
249 }
250 } else if (waMessage) {
283 // This means for direct GET, you'd need to monitor this Val's `/cf-worker-updates` or provide one.
284
285 const userIdentifier = "direct_api_user_" + crypto.randomUUID();
286 const clientRequestId = crypto.randomUUID(); // Not used by initiateChat directly, but good practice
287
386// Handle sending the welcome message
387app.post("/send-welcome", async (c) => {
388 if (!WHATSAPP_GRAPH_API_TOKEN || !WHATSAPP_BUSINESS_ID) {
389 console.error("WhatsApp API token or Business ID is not configured.");
390 return c.json({ error: "Server configuration error: WhatsApp API token or Business ID is missing." }, 500);
391 }
392
416 method: "POST",
417 headers: {
418 "Authorization": `Bearer ${WHATSAPP_GRAPH_API_TOKEN}`,
419 "Content-Type": "application/json",
420 },
431 );
432
433 const responseData = await response.json().catch(() => ({ error: { message: "Received non-JSON response from WhatsApp API" } })); // Ensure responseData is an object
434
435 if (!response.ok) {
436 console.error(`Error sending template message to ${phoneNumber}: ${response.status} ${response.statusText}`, responseData);
437 return c.json({ error: `WhatsApp API Error: ${responseData.error?.message || response.statusText}`, details: responseData }, response.status > 0 ? response.status : 500);
438 }
439
apiv1
papimark21