6 const url = `https://api.telegram.org/bot${TOKEN}/sendMessage`;
7
8 fetch(url, {
9 method: "POST",
10 headers: { "Content-Type": "application/json" },
55export type AppType = typeof app;
56
57export default app.fetch;
6 const url = `https://api.telegram.org/bot${TOKEN}/sendMessage`;
7
8 fetch(url, {
9 method: "POST",
10 headers: { "Content-Type": "application/json" },
15The `client.tsx` module imports the `AppType` type along with `hc` from `hono/client`
16to create the client instance.
17This module demonstrats fetching all `cats` from the API, adding a new cat, and refetching the results.
18
19This example _DOES NOT_ include validation. See [Hono RPC Zod Starter][] for an example with validation.
16The `client.tsx` module imports the `AppType` type along with `hc` from `hono/client`
17to create the client instance.
18This module demonstrats fetching all `cats` from the API, adding a new cat, and refetching the results.
19
20It then tries to create a cat without a name, which throws a Zod error.
10
11The `http.tsx` file imports Hono's JSX runtime and the Hono library from npm.
12It exports the `app.fetch` handler to server the page.
13
14[View more starters](https://val.town/x/jxnblk/how-to)
5
6async function bootstrap () {
7 console.log("fetching cats");
8 let cats = await client.api.cats.$get();
9 let data = await cats.json();
20 console.log({ newCat });
21
22 console.log("refetching cats");
23 cats = await client.api.cats.$get();
24 data = await cats.json();
19});
20
21export default app.fetch;
1# Team - Notion & Val Town Integration
2
3A simple integration that automatically enriches a Notion database of team members with their Val Town account information. When a new team member is added to your Notion database, this Val automatically fetches their Val Town profile data and populates the relevant fields.
4
5## Features
6
7- **Automatic Profile Enrichment**: Fetches Val Town user data when triggered by Notion webhooks
8- **Flexible Username Detection**: Supports both URL-based and direct username input
9- **RESTful API**: Provides endpoints to manually query Val Town user information
65
661. **Trigger**: When a team member is added/updated in Notion, a webhook is sent to `/tasks`
672. **Data Retrieval**: The system fetches the full page data from Notion to get the username
683. **Username Extraction**: Extracts username from either:
69 - The `URL` field (extracts from `https://val.town/u/username`)
70 - The `Username` field directly
714. **Profile Fetch**: Queries the Val Town API for user profile data
725. **Database Update**: Updates the Notion page with the retrieved information
73
82## Val Town Profile Data
83
84The integration fetches and stores the following data from Val Town:
85
86- **Username**: Val Town handle
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { z } from "npm:zod";
275 try {
276 console.log("Sending to /questionnaire:", payload);
277 const resp = await fetch('/questionnaire', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
278 setLoading(false); clearErr();
279 if (!resp.ok) {
310 console.log("Sending to /execute:", finalPayload);
311 if (!finalPayload || !finalPayload.task || !finalPayload.data) { throw new Error("Invalid data for execution."); }
312 const resp = await fetch('/execute', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(finalPayload) });
313 setLoading(false);
314 const resData = await resp.json();