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?q=fetch&page=131&format=json

For typeahead suggestions, use the /typeahead endpoint:

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

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

Found 9685 results for "fetch"(1210ms)

weathergeocode.ts2 matches

@anand_gโ€ขUpdated 1 week ago
95
96 try {
97 // Simulating fetch here - in a real implementation this would be:
98 // const response = await fetch(`${this.baseUrl}/search?${params}`);
99 console.log(`Making request to: ${this.baseUrl}/search?${params}`);
100

weatherindex.ts2 matches

@anand_gโ€ขUpdated 1 week ago
29});
30
31// HTTP vals expect an exported "fetch handler"
32// This is how you "run the server" in Val Town with Hono
33export default app.fetch;

Discord_Bot_Servicessignup-alerts-service.tsx15 matches

@ktodazโ€ขUpdated 1 week ago
2import { withErrorHandling } from "https://esm.town/v/ktodaz/Discord_Bot_Services/error-handling.tsx";
3import { blob } from "https://esm.town/v/std/blob";
4import { fetch } from "https://esm.town/v/std/fetch";
5
6// Hardcoded list of role IDs that are allowed to be toggled
31 // Get role information using error handling wrapper
32 const roles = await withErrorHandling(
33 "fetchGuildRoles",
34 async () => {
35 const token = Deno.env.get("DISCORD_BOT_TOKEN");
36 const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
37 headers: {
38 Authorization: `Bot ${token}`,
40 });
41 if (!roleResponse.ok) {
42 throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
43 }
44 return roleResponse.json();
52 // Get member info using error handling wrapper
53 const member = await withErrorHandling(
54 "fetchGuildMember",
55 async () => {
56 const token = Deno.env.get("DISCORD_BOT_TOKEN");
57 const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
58 headers: {
59 Authorization: `Bot ${token}`,
61 });
62 if (!memberResponse.ok) {
63 throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
64 }
65 return memberResponse.json();
78 async () => {
79 const token = Deno.env.get("DISCORD_BOT_TOKEN");
80 const toggleResponse = await fetch(
81 `https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${roleId}`,
82 {
158 }
159
160 // Fetch all roles from the guild with error handling
161 const allRoles = await withErrorHandling(
162 "fetchGuildRolesForAlerts",
163 async () => {
164 const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
165 headers: {
166 Authorization: `Bot ${token}`,
169
170 if (!roleResponse.ok) {
171 throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
172 }
173
212 const focusedValue = interaction.data.options[0].value?.toLowerCase() || "";
213
214 // Fetch toggleable roles
215 const { success, roles, error } = await getSignupAlertsRoles(guildId);
216
219 type: 8, // Autocomplete result
220 data: {
221 choices: [{ name: "Error: " + (error || "Could not fetch roles"), value: "error" }],
222 },
223 });
257 type: 8,
258 data: {
259 choices: [{ name: "Error fetching roles", value: "error" }],
260 },
261 });
1// toggle-server-helper-pings-service.ts - Service for handling server helper ping toggle functionality
2import { fetch } from "https://esm.town/v/std/fetch";
3
4// Hardcoded role IDs
26
27 // First, get the member to check if they have any of the server helper roles
28 const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
29 headers: {
30 Authorization: `Bot ${token}`,
33
34 if (!memberResponse.ok) {
35 throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
36 }
37
50
51 // Get the role information to include in the response
52 const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
53 headers: {
54 Authorization: `Bot ${token}`,
57
58 if (!roleResponse.ok) {
59 throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
60 }
61
71 const action = hasRole ? "removed" : "added";
72
73 const toggleResponse = await fetch(
74 `https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${SERVER_HELPER_PINGS_ROLE_ID}`,
75 {

Discord_Bot_Servicestoggle-role-service.tsx19 matches

@ktodazโ€ขUpdated 1 week ago
1// toggle-role-service.ts - Service for handling role toggle functionality
2import { withErrorHandling } from "https://esm.town/v/ktodaz/Discord_Bot_Services/error-handling.tsx";
3import { fetch } from "https://esm.town/v/std/fetch";
4
5// Hardcoded list of role IDs that are allowed to be toggled
22
23 // Get guild information to check for owner
24 const guildResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}`, {
25 headers: {
26 Authorization: `Bot ${token}`,
29
30 if (!guildResponse.ok) {
31 throw new Error(`Failed to fetch guild data: ${guildResponse.status}`);
32 }
33
36
37 // Get member to check for administrator permissions
38 const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
39 headers: {
40 Authorization: `Bot ${token}`,
43
44 if (!memberResponse.ok) {
45 throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
46 }
47
48 const member = await memberResponse.json();
49
50 // Fetch all roles in the guild
51 const rolesResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
52 headers: {
53 Authorization: `Bot ${token}`,
56
57 if (!rolesResponse.ok) {
58 throw new Error(`Failed to fetch roles data: ${rolesResponse.status}`);
59 }
60
122 const token = Deno.env.get("DISCORD_BOT_TOKEN");
123 // First, get the role information to include in the response
124 const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
125 headers: {
126 Authorization: `Bot ${token}`,
128 });
129 if (!roleResponse.ok) {
130 throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
131 }
132 const roles = await roleResponse.json();
135
136 // Get the member to check if they have the role
137 const memberResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${userId}`, {
138 headers: {
139 Authorization: `Bot ${token}`,
141 });
142 if (!memberResponse.ok) {
143 throw new Error(`Failed to fetch member data: ${memberResponse.status}`);
144 }
145 const member = await memberResponse.json();
149 const method = hasRole ? "DELETE" : "PUT";
150 const action = hasRole ? "removed" : "added";
151 const toggleResponse = await fetch(
152 `https://discord.com/api/v10/guilds/${guildId}/members/${userId}/roles/${roleId}`,
153 {
209 // Use the error handling wrapper for the API call
210 const allRoles = await withErrorHandling(
211 "fetchGuildRoles",
212 async () => {
213 const token = Deno.env.get("DISCORD_BOT_TOKEN");
214 const roleResponse = await fetch(`https://discord.com/api/v10/guilds/${guildId}/roles`, {
215 headers: {
216 Authorization: `Bot ${token}`,
219
220 if (!roleResponse.ok) {
221 throw new Error(`Failed to fetch role data: ${roleResponse.status}`);
222 }
223
254 const focusedValue = interaction.data.options[0].value?.toLowerCase() || "";
255
256 // Fetch toggleable roles
257 const { success, roles, error } = await getToggleableRoles(guildId);
258
261 type: 8, // Autocomplete result
262 data: {
263 choices: [{ name: "Error: " + (error || "Could not fetch roles"), value: "error" }],
264 },
265 });
290 type: 8,
291 data: {
292 choices: [{ name: "Error fetching roles", value: "error" }],
293 },
294 });

slacktest.ts2 matches

@dinavinterโ€ขUpdated 1 week ago
217// -------------------------------
218
219app.function("fetch_user_details", async ({ payload, context: { client, functionExecutionId } }) => {
220 try {
221 // Requires users:read scope
241 await client.functions.completeError({
242 function_execution_id: functionExecutionId!,
243 error: `Failed to respond to fetch_user_details function event (${e})`,
244 });
245 }

mandateagents.ts23 matches

@salonโ€ขUpdated 1 week ago
2import { XMLParser } from "https://esm.sh/fast-xml-parser@4.2.5"; // For parsing RSS/Atom feeds
3import { AgentContext, AgentInput, AgentOutput } from "https://esm.town/v/salon/mandate/interfaces.ts";
4import { fetch } from "https://esm.town/v/std/fetch";
5import { OpenAI } from "https://esm.town/v/std/openai";
6
51}
52
53// Fetch Agent (Now fetches and parses RSS feeds for headlines)
54export async function fetchAgent(
55 input: AgentInput<{ url_from_input?: string; maxHeadlines?: number }>, // Added maxHeadlines
56 context: AgentContext,
71
72 const DEFAULT_RSS_URL = "https://feeds.npr.org/1001/rss.xml"; // NPR Top Stories as default
73 const urlToFetch = payload?.url_from_input ?? config?.rssFeedUrl ?? DEFAULT_RSS_URL;
74 const maxHeadlines = Number(payload?.maxHeadlines ?? config?.maxHeadlines ?? 5);
75
76 log("INFO", "FetchAgent", `Workspaceing headlines from ${urlToFetch}, max: ${maxHeadlines}`);
77
78 try {
79 const resp = await fetch(urlToFetch);
80 const fetchedContentType = resp.headers.get("content-type")?.toLowerCase() || "";
81 const rawResponseText = await resp.text();
82
84 let errorBody = rawResponseText;
85 if (errorBody.length > 500) errorBody = errorBody.substring(0, 500) + "...";
86 throw new Error(`Workspace failed: ${resp.status} ${resp.statusText}. URL: ${urlToFetch}. Body: ${errorBody}`);
87 }
88
94 // Attempt to parse as RSS/Atom if content type suggests XML, or if it's a known RSS URL pattern/default
95 if (
96 fetchedContentType.includes("xml") || fetchedContentType.includes("rss") || urlToFetch.endsWith(".xml")
97 || urlToFetch.endsWith(".rss") || urlToFetch === DEFAULT_RSS_URL
98 ) {
99 try {
154
155 if (parsedSuccessfully) {
156 log("INFO", "FetchAgent", `Successfully parsed ${headlines.length} headlines from "${feedTitle}".`);
157 } else {
158 parsingMessage = "RSS/Atom structure not as expected or no items found.";
159 log("WARN", "FetchAgent", parsingMessage);
160 }
161 } catch (parseError: any) {
162 parsingMessage = `Failed to parse XML/RSS content. Error: ${parseError.message}`;
163 log("WARN", "FetchAgent", `${parsingMessage} from URL: ${urlToFetch}`);
164 }
165 } else {
166 parsingMessage =
167 `Content type "${fetchedContentType}" is not XML/RSS. Not attempting RSS parse. Raw text will be available.`;
168 log("INFO", "FetchAgent", parsingMessage);
169 }
170
172 headlines,
173 feedTitle,
174 sourceUrl: urlToFetch,
175 ...(parsingMessage && !parsedSuccessfully ? { message: parsingMessage } : {}),
176 };
182 data: outputData,
183 rawText: rawResponseText,
184 contentType: fetchedContentType,
185 },
186 };
187 } catch (e: any) {
188 log("ERROR", "FetchAgent", `Workspace or processing failed: ${e.message}`, e);
189 return {
190 mandateId,
194 headlines: [],
195 feedTitle: "Error",
196 sourceUrl: urlToFetch,
197 message: `Workspace or processing failed: ${e.message}`,
198 },
205}
206
207// Combiner Agent (Adapted to handle new headline structure from FetchAgent)
208export async function combinerAgent(
209 input: AgentInput<{
210 summary?: string;
211 // Expecting externalData to potentially contain the output of fetchAgent
212 externalData?: {
213 headlines?: Array<{ title: string; link: string; summary: string; publishedDate: string }>;
227 try {
228 const summaryText = payload.summary ?? "N/A";
229 let externalDataDescription = "External Data: Not Fetched/Available or not in expected format.";
230
231 if (
247 }
248 });
249 } else if (payload.externalData?.message) { // If fetchAgent had a message (e.g. parsing error but still some info)
250 externalDataDescription = `External Data Information: ${payload.externalData.message} (Source: ${
251 payload.externalData.sourceUrl || "Unknown"

untitled-3323new-file-8432.tsx7 matches

@AP123โ€ขUpdated 1 week ago
20 if (/^https?:\/\/(?:[^/]+\.)?reddit\.com\/.*\/comments\/[a-z0-9]+/i.test(feedUrl)) {
21 try {
22 return json(await fetchRedditPost(feedUrl, limit));
23 }
24 catch (err) {
25 console.error(err);
26 return json({ error: "Reddit fetch failed", details: String(err) }, 500);
27 }
28 }
37 feedUrl = u.toString();
38 }
39 const xml = await fetch(feedUrl, { headers: { "User-Agent": "val-town-rss2json" } }).then(r => r.text());
40 const raw = await parseStringPromise(xml, { explicitArray: false });
41 const feed = raw.feed ?? raw.rss?.channel;
60
61// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
62// FULL-DATA fetch for a single Reddit submission
63// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
64async function fetchRedditPost(postUrl: string, limit: number) {
65 const pathname = new URL(postUrl).pathname.replace(/\/$/, "");
66 const headers = {
71
72 // 1๏ธโƒฃ try api.reddit.com (no Cloudflare)
73 let txt = await fetch(`https://api.reddit.com${pathname}?limit=${limit}&raw_json=1`, { headers })
74 .then(r => r.text());
75 if (txt.trim().startsWith("<")) { // got HTML โžœ fallback
76 // 2๏ธโƒฃ try old.reddit.com
77 txt = await fetch(`https://old.reddit.com${pathname}.json?limit=${limit}&raw_json=1`, {
78 headers: { "User-Agent": "val-town-faceless-video/1.0" },
79 }).then(r => r.text());

pollinaterpbldemo.tsx4 matches

@armadillomikeโ€ขUpdated 1 week ago
9
10 useEffect(() => {
11 async function fetchSensorData() {
12 try {
13 // Simulated sensor data with realistic bee habitat conditions
19 setLastUpdated(new Date());
20 } catch (error) {
21 console.error("Error fetching sensor data", error);
22 }
23 }
24
25 fetchSensorData();
26 const intervalId = setInterval(fetchSensorData, 5000);
27 return () => clearInterval(intervalId);
28 }, []);

rdo-dailies-webhookmain.ts4 matches

@mmoriharaโ€ขUpdated 1 week ago
1import { discordWebhook } from "https://esm.town/v/mmorihara/coherentVioletFinch";
2
3const strings = await fetch("https://esm.town/v/mmorihara/rdo-dailies-webhook@8-dev/data.json").then(r => r.json());
4
5const templates: { [key: string]: (goalText: string, goalNum: number) => string } = {
82}
83
84async function fetchDailies() {
85 const response = await fetch("https://api.rdo.gg/challenges/index.json");
86 return response.json();
87}
141
142export async function main() {
143 const dailies = await fetchDailies();
144 const formatted = formatDailies(dailies);
145

agentplex-deal-flow-email-fetch1 file match

@anandvcโ€ขUpdated 1 day ago

proxyFetch2 file matches

@vidarโ€ขUpdated 3 days ago