12 }
13 // 🔗 Generate response from OpenAI
14 const aiResponse = await (await fetch("https://api.openai.com/v1/chat/completions", {
15 method: "POST",
16 headers: {
36 console.log("🤖 Final reply to send:", reply);
37 // 📤 Send SMS via Twilio
38 const twilioResponse = await fetch(
39 "https://api.twilio.com/2010-04-01/Accounts/" + Deno.env.get("TWILIO_ACCOUNT_SID") + "/Messages.json",
40 {
19/huyhieu?url=<website>&label=<label>&value=<value>&color=<color>&text=<textColor>&size=<size>&radius=<radius>&shape=<shape>
20```
21- `url` (optional): Website to fetch favicon from
22- `label` (optional): Left text (default: 'huy' if both label and value are missing)
23- `value` (optional): Right text (default: 'hieu' if both label and value are missing)
310
311 try {
312 const res = await fetch(\`\${API_URL}?action=chat\`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: conversationHistory.slice(0, -1), tasks, projects }) });
313 const data = await res.json();
314 if (!res.ok || data.error) throw new Error(data.error || 'Server error');
396 toggleLoading(btn, true);
397 try {
398 const res = await fetch(\`\${API_URL}?action=synthesizeProject\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ goal }) });
399 const data = await res.json();
400 if (!res.ok || data.error) throw new Error(data.error || "Server error");
414 toggleLoading(btn, true);
415 try {
416 const res = await fetch(\`\${API_URL}?action=dailyRebalance\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ tasks: todayTasks }) });
417 const data = await res.json();
418 if (!res.ok || data.error) throw new Error(data.error || "Server error");
31 <pre><code>/huyhieu?url=<website>&label=<label>&value=<value>&color=<color>&text=<textColor>&size=<size></code></pre>
32 <ul>
33 <li><b>url</b> (optional): Website to fetch favicon from</li>
34 <li><b>label</b> (optional): Left text (default: 'huy' if both label and value are missing)</li>
35 <li><b>value</b> (optional): Right text (default: 'hieu' if both label and value are missing)</li>
82 const urlObj = new URL(siteUrl)
83 const faviconUrl = `${urlObj.origin}/favicon.ico`
84 const res = await fetch(faviconUrl)
85 if (res.ok) {
86 const buffer = new Uint8Array(await res.arrayBuffer())
89 }
90 } catch {
91 console.error('HuyHieu: Failed to fetch favicon:', siteUrl)
92 }
93 }
145})
146
147export default app.fetch
148// Serve the app in local to test
149Deno.serve(app.fetch)
150
166 const { content: url } = await c.req.json() as ParseRequest;
167
168 // Fetch the webpage content
169 const response = await fetch(url);
170 if (!response.ok) {
171 return c.json({ success: false, error: "Failed to fetch URL" } as ParseResponse);
172 }
173
221
222 // Inject data to avoid extra round-trips
223 const initialData = await fetchInitialData();
224 const dataScript = `<script>
225 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
268
2695. **API Design:**
270 - `fetch` handler is the entry point for HTTP vals
271 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
272
2736. **Hono Peculiarities:**
101 const path = join(__dirname, "../frontend", c.req.path);
102 try {
103 return await c.env.ASSETS.fetch(new Request(c.req.url));
104 } catch (e) {
105 return next();
109// Start the server
110const server = serve({
111 fetch: app.fetch,
112 port,
113}, (info: { port: number }) => {
124});
125
126export default app.fetch;
230
231 // Inject data to avoid extra round-trips
232 const initialData = await fetchInitialData();
233 const dataScript = `<script>
234 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
277
2785. **API Design:**
279 - `fetch` handler is the entry point for HTTP vals
280 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
281
282## Val Town MCP Tools
155 * The main App component is rendered on the client.
156 * No server-side-specific code should be included in the App.
157 * Use fetch to communicate with the backend server portion.
158 */
159function App() {
178 * Server-only code
179 * Any code that is meant to run on the server should be included in the server function.
180 * This can include endpoints that the client side component can send fetch requests to.
181 */
182export default async function server(request: Request): Promise<Response> {
77```
78
795. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
80```ts
81const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
82```
83
206
207 // Inject data to avoid extra round-trips
208 const initialData = await fetchInitialData();
209 const dataScript = `<script>
210 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
264
2655. **API Design:**
266 - `fetch` handler is the entry point for HTTP vals
267 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
268 - Properly handle CORS if needed for external access
269