151 async function loadEmails() {
152 try {
153 const response = await fetch('/api/emails');
154 const emails = await response.json();
155
195 const id = btn.getAttribute('data-id');
196 if (confirm('Are you sure you want to delete this scheduled email?')) {
197 await fetch(\`/api/emails/\${id}\`, { method: 'DELETE' });
198 loadEmails();
199 }
221
222 try {
223 const response = await fetch('/api/emails', {
224 method: 'POST',
225 headers: {
270 return c.json(emails);
271 } catch (error) {
272 return c.text("Error fetching emails: " + error.message, 500);
273 }
274});
315
316// This is the entry point for HTTP vals
317export default app.fetch;
6
71. The script runs daily as a cron job
82. It fetches the Whole Foods search page for GT Synergy Kombucha
93. It analyzes the page to detect if the product is on sale
104. If a sale is detected (and wasn't detected in the previous check), it sends an email notification
1import { email } from "https://esm.town/v/std/email";
2async function emailRandomJoke() {
3 function fetchRandomJoke() {
4 const SAMPLE_JOKE = {
5 setup: "What do you call a group of disorganized cats?",
9 }
10
11 const randomJoke = fetchRandomJoke();
12 const setup = randomJoke.setup;
13 const punchline = randomJoke.punchline;
21async function checkForKombuchaSale(): Promise<{isOnSale: boolean, price?: string, saleDetails?: string}> {
22 try {
23 // Fetch the Whole Foods search page for GT Synergy Kombucha
24 const response = await fetch(PRODUCT_URL, {
25 headers: {
26 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
29
30 if (!response.ok) {
31 throw new Error(`Failed to fetch Whole Foods page: ${response.status}`);
32 }
33
47
48 // Send the data to the server
49 const response = await fetch('/api/agents', {
50 method: 'POST',
51 body: data,
34For more advanced use cases, you can modify the code to:
35
36- Fetch dynamic content from an API
37- Send different emails based on the day of the week
38- Include personalized content
42
43// This is the entry point for HTTP vals
44export default app.fetch;
98 });
99 } catch (error) {
100 console.error("Error fetching resumes:", error);
101 return c.json<ApiResponse<null>>({
102 success: false,
103 error: "Failed to fetch resumes"
104 }, 500);
105 }
123 });
124 } catch (error) {
125 console.error("Error fetching resume:", error);
126 return c.json<ApiResponse<null>>({
127 success: false,
128 error: "Failed to fetch resume"
129 }, 500);
130 }
174 });
175 } catch (error) {
176 console.error("Error fetching job requirements:", error);
177 return c.json<ApiResponse<null>>({
178 success: false,
179 error: "Failed to fetch job requirements"
180 }, 500);
181 }
199 });
200 } catch (error) {
201 console.error("Error fetching job requirement:", error);
202 return c.json<ApiResponse<null>>({
203 success: false,
204 error: "Failed to fetch job requirement"
205 }, 500);
206 }
304 });
305 } catch (error) {
306 console.error("Error fetching screening results:", error);
307 return c.json<ApiResponse<null>>({
308 success: false,
309 error: "Failed to fetch screening results"
310 }, 500);
311 }
313
314// Export the app for HTTP val
315export default app.fetch;
53
54// Export the Hono app for HTTP val
55export default app.fetch;
21 });
22 } catch (error) {
23 console.error("Error fetching chat history:", error);
24 return new Response(JSON.stringify({
25 error: "Failed to fetch chat history",
26 details: error instanceof Error ? error.message : String(error)
27 }), {