6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
1112<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
telegramWebhookEchoMessagemain.tsx2 matches
34const BOT_TOKEN = Deno.env.get("TELEGRAM_TOKEN");
5const TELEGRAM_API_URL = `https://api.telegram.org/bot${BOT_TOKEN}`;
67useHTTP(async (req, res) => {
26async function sendMessage(chatId, text) {
27try {
28const url = `${TELEGRAM_API_URL}/sendMessage`;
29const payload = {
30chat_id: chatId,
iconExplorermain.tsx7 matches
1/**
2* This val creates an enhanced NPM package explorer using the npm registry API.
3* It displays a grid of npm packages with basic information, categories, and navigation.
4* The approach uses React for the frontend and fetch for API calls.
5* It includes a details view for each package, a link to the npm page, and category navigation.
6*/
104const category = url.searchParams.get("category") || "";
105106let apiUrl = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(searchTerm)}&size=${size}&from=${from}`;
107
108if (category === "popular") {
109apiUrl += "&popularity=1.0";
110} else if (category === "new") {
111apiUrl += "&maintenance=0&quality=0&popularity=0";
112} else if (category !== "all" && category) {
113apiUrl += `&keywords=${encodeURIComponent(category)}`;
114}
115116const response = await fetch(apiUrl);
117const data = await response.json();
118return new Response(JSON.stringify(data), {
whatsappWebhookExamplemain.tsx2 matches
2* Simple, free webhook to start using WhatsApp Platform.
3* Handles GET request for verification, and POST request for notifications.
4* Meta example: https://glitch.com/edit/#!/whatsapp-cloud-api-echo-bot
5*
6* Setup:
9* 2. Set your env variable `WHATSAPP_WEBHOOK_VERIFY_TOKEN`
10* Set env variables in val: https://docs.val.town/reference/environment-variables/
11* hub.verify_token value: https://developers.facebook.com/docs/graph-api/webhooks/getting-started
12*
13* Note:
todaystatsmain.tsx12 matches
1/**
2* This tool fetches real-time data from various free APIs to create a JSON object
3* representing the current state of the world from different perspectives.
4* Data is cached for 30 minutes using Val Town's SQLite database to reduce API calls and improve performance.
5*/
643async function fetchWolframData(query: string) {
44const appId = 'K8UTGR-8Y5G3A3VTP';
45const url = `http://api.wolframalpha.com/v1/result?appid=${appId}&i=${encodeURIComponent(query)}`;
46try {
47const response = await fetch(url);
58// Utility function for fetching Alpha Vantage stock data
59async function fetchStockData(symbol: string) {
60const apiKey = 'TD7I78XY3N2AGKWP';
61const url = `https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=${symbol}&interval=5min&apikey=${apiKey}`;
62try {
63const data = await fetchJSON(url);
9192// If no valid cache, fetch new data
93const issData = await fetchJSON('http://api.open-notify.org/iss-now.json');
94const weatherData = await fetchJSON('https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.01¤t_weather=true&temperature_unit=celsius&daily=temperature_2m_max,temperature_2m_min,sunrise,sunset&timezone=America%2FNew_York');
95const airQualityData = await fetchJSON('https://api.waqi.info/feed/geo:40.71;-74.01/?token=demo');
96const cryptoData = await fetchJSON('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,dogecoin,ripple,cardano,polkadot,litecoin&vs_currencies=usd');
97const peopleInSpaceData = await fetchJSON('http://api.open-notify.org/astros.json');
98const timeData = await fetchJSON('https://worldtimeapi.org/api/timezone/America/New_York,Europe/London,Asia/Tokyo');
99const exchangeRateData = await fetchJSON('https://api.exchangerate-api.com/v4/latest/USD');
100const usaCovidData = await fetchJSON('https://disease.sh/v3/covid-19/countries/USA');
101const solarData = await fetchJSON('https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json');
1/**
2* This program creates an HTTP server that fetches various data from NASA APIs
3* and returns a JSON response with a collection of interesting information about today.
4* It uses multiple NASA APIs to gather diverse space-related data, including real-time imagery
5* and additional interesting data points.
6*/
8import { DOMParser } from "https://esm.sh/linkedom";
910const NASA_API_KEY = 'vYg1cCNLVbcgNemMWuLEjoJsGOGbBXZjZjmwVwuV';
1112async function fetchNASAData() {
1415// Fetch Astronomy Picture of the Day
16const apodResponse = await fetch(`https://api.nasa.gov/planetary/apod?api_key=${NASA_API_KEY}`);
17const apodData = await apodResponse.json();
1819// Fetch latest EPIC image metadata
20const epicResponse = await fetch(`https://api.nasa.gov/EPIC/api/natural?api_key=${NASA_API_KEY}`);
21const epicData = await epicResponse.json();
22const latestEpicImage = epicData[0];
2324// Fetch Near Earth Objects for today
25const neowsResponse = await fetch(`https://api.nasa.gov/neo/rest/v1/feed?start_date=${today}&end_date=${today}&api_key=${NASA_API_KEY}`);
26const neowsData = await neowsResponse.json();
2728// Fetch Mars Weather data (note: this data is not always up-to-date)
29const marsWeatherResponse = await fetch(`https://api.nasa.gov/insight_weather/?api_key=${NASA_API_KEY}&feedtype=json&ver=1.0`);
30const marsWeatherData = await marsWeatherResponse.json();
3132// Fetch Earth Observatory Natural Event Tracker (EONET) data
33const eonetResponse = await fetch(`https://eonet.gsfc.nasa.gov/api/v3/events`);
34const eonetData = await eonetResponse.json();
3536// Fetch ISS Current Location
37const issResponse = await fetch('http://api.open-notify.org/iss-now.json');
38const issData = await issResponse.json();
3940// Fetch NASA Image and Video Library data
41const nasaLibraryResponse = await fetch(`https://images-api.nasa.gov/search?q=space&media_type=image`);
42const nasaLibraryData = await nasaLibraryResponse.json();
43
451. Click `Fork`
62. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
73. Click `Run`
8
sqliteExplorerAppREADME.md1 match
13## Authentication
1415Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
1617## Todos / Plans
sqliteExplorerAppmain.tsx2 matches
27<head>
28<title>SQLite Explorer</title>
29<link rel="preconnect" href="https://fonts.googleapis.com" />
3031<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32<link
33href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34rel="stylesheet"
35/>