58);
59
60const airtableApiKey = Deno.env.get("AIRTABLE_API_KEY");
61const defaultBaseId = "app1wLB4irV14mxMU";
62const defaultTableName = "ExampleItems";
66
67async function fetchAirtableData(baseId, tableName, nameColumn, contentColumn, embeddingColumn) {
68 const base = new Airtable({ apiKey: airtableApiKey }).base(baseId);
69 const records = await base(tableName).select().all();
70 const documents = records.map(record => ({
12}));
13
14const airtableApiKey = Deno.env.get("AIRTABLE_API_KEY");
15const defaultBaseId = "app1wLB4irV14mxMU";
16const defaultTableName = "ExampleItems";
19
20async function fetchAirtableData(baseId, tableName, contentColumn, embeddingColumn) {
21 const base = new Airtable({ apiKey: airtableApiKey }).base(baseId);
22 const records = await base(tableName).select().all();
23
9[](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
12
13# TODO
50## How it works
51
52Telegram has a lovely API.
53
541. I created a @ValTownBot via [Bot Father](https://t.me/botfather).
552. I created a [webhook](https://www.val.town/v/stevekrouse.telegramValTownBotWebhook) and [registered it with telegram](https://www.val.town/v/stevekrouse.telegramValTownBotWebhookSetup)
563. Whenever someone new messages @ValTownBot, I generate a secret and save it along with their Chat Id in @stevekrouse/telegramValTownBotSecrets (a private val), and message it back to them
574. Now whenever you call this val, it calls [`telegramValTownAPI`](https://www.val.town/v/stevekrouse.telegramValTownAPI), which looks up your Chat Id via your secret and sends you a message
58
59## Telegram Resources
71
72- [ ] Store user data in Val Town SQLite
73- [ ] Parse user data on the API side using Zod
25
26async function telegramRequest(path, body, authorization?: string) {
27 const response = await fetch("https://stevekrouse-telegramValTownAPI.web.val.run/" + path, {
28 method: "POST",
29 body: JSON.stringify(body),
7}) => {
8 const { results } = await fetchJSON(
9 "https://api.openaq.org/v2/locations?"
10 + new URLSearchParams({
11 coordinates: lat.toPrecision(8) + "," + lon.toPrecision(8),
2 // try/catch prevents crashes if the script doesn't have env access
3 try {
4 return Deno.env.get("VALTOWN_API_URL");
5 } catch {}
6}
7
8export function getApiUrl(): string {
9 return envOrUndefined("VALTOWN_API_URL") ?? "https://api.val.town";
10}
11
12export const API_URL = getApiUrl();
1# Val Town API URL
2
3When Val Town code is run on Val Town servers we use a local URL so we can save time by skipping a roundtrip to the public internet. However, if you want to run your vals that use our API, ie std library vals, locally, you'll want to use our public API's URL, `https://api.val.town`. We recommend importing and using `std/API_URL` whenever you use our API so that you are always using the most efficient route.
4
5## Example Usage
6
7```ts
8import { API_URL } from "https://esm.town/v/std/API_URL";
9
10const response = await fetch(`${API_URL}/v1/me`, {
11 headers: {
12 Authorization: `Bearer ${Deno.env.get("valtown")}`,
2import { setEnv } from "https://esm.town/v/pomdtr/setEnv";
3
4setEnv("valtown", Deno.env.get("SQLITE_API_TOKEN"));
5export default handler;
15 <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
16 <style>
17 @import url("https://fonts.googleapis.com/css2?family=Inter:wght@500;700&display=swap");
18 @import url("https://esm.sh/tldraw/tldraw.css");
19