227 }
228
229 // Handle API requests
230 if (url.pathname.startsWith("/api/")) {
231 if (url.pathname === "/api/summarize" && req.method === "POST") {
232 try {
233 const { url: articleUrl, ageRange } = await req.json();
246 });
247 } catch (error) {
248 console.error("Error in /api/summarize:", error);
249 return Response.json({ error: error.message }, { status: 400 });
250 }
251 }
252 else if (url.pathname === "/api/generate-blog" && req.method === "POST") {
253 try {
254 const { summary, originalUrl, ageRange, images = [] } = await req.json();
267 });
268 } catch (error) {
269 console.error("Error in /api/generate-blog:", error);
270 return Response.json({ error: error.message }, { status: 400 });
271 }
272 }
273 else if (url.pathname === "/api/blogs" && req.method === "GET") {
274 try {
275 // Import the database queries
287 return Response.json(blogsWithUrls);
288 } catch (error) {
289 console.error("Error in /api/blogs:", error);
290 return Response.json({ error: error.message }, { status: 400 });
291 }
874async function generateIntegerSequences(length: number, totalCards: number) {
875 if (!RANDOMORG_KEY) {
876 // Fallback to crypto.getRandomValues if Random.org API key is not available
877 const cardNumbers = new Array(length);
878 const reversedNumbers = new Array(length);
902 "method": "generateIntegerSequences",
903 "params": {
904 "apiKey": RANDOMORG_KEY,
905 "n": 2,
906 "length": length,
913
914 try {
915 const response = await fetch("https://api.random.org/json-rpc/4/invoke", {
916 method: "POST",
917 headers: {
923 return await response.json();
924 } catch (error) {
925 console.error("Random.org API error:", error);
926 // Fallback to crypto if Random.org fails
927 return generateIntegerSequences(length, totalCards);
956 method: "POST",
957 headers: {
958 "apikey": SUPABASE_KEY,
959 "Authorization": `Bearer ${SUPABASE_KEY}`,
960 "Content-Type": "application/json",
989 const response = await fetch(`${SUPABASE_URL}/rest/v1/pulls?id=eq.${pullId}&select=*`, {
990 headers: {
991 "apikey": SUPABASE_KEY,
992 "Authorization": `Bearer ${SUPABASE_KEY}`,
993 },
28});
29
30// API endpoint for getting supported formats (for future use)
31app.get("/api/formats", c => {
32 return c.json({
33 supported: [
416. Watch the animated progress bar and download your PDF
42
43## API Endpoints
44
45- `GET /` - Web interface with dark theme and 3D effects
9 <script src="https://esm.sh/jspdf@2.5.1"></script>
10 <style>
11 @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
12
13 body {
39});
40
41// API routes
42app.get("/api/words", async c => {
43 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
44
87});
88
89app.get("/api/birds", async c => {
90 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
91
140
141 const innerRadius = gameType === "birds" ? INNER_RADIUS_BIRDS : INNER_RADIUS;
142 const apiEndpoint = gameType === "birds" ? "/api/birds" : "/api/words";
143
144 useEffect(() => {
198 const fetchWords = async () => {
199 try {
200 const response = await fetch(apiEndpoint);
201 const data = await response.json();
202 setWordlist(data);
1# Twitter/𝕏 - New user tweet alert [TEMPLATE]
2
3SocialData Monitoring API provides an easy way to get nearly real-time notifications when any Twitter user posts a new tweet.
4Use this Val template to deliver notifications to Discord or Telegram.
5
21
22- `DISCORD_WEBHOOK_URL` - required when using Discord for notifications
23- `TELEGRAM_API_TOKEN` - required when using Telegram for notifications
24- `TELEGRAM_USER_ID` - required when using Telegram for notifications
25
441. Follow [this guide](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) to create a Discord webhook URL.
45
46### Where do I get Telegram bot API token and User ID?
47
481. Follow [this guide](https://core.telegram.org/bots/features#creating-a-new-bot) to create your own Telegram bot and obtain it's API token.
492. Add [@userinfobot](https://t.me/userinfobot) and the bot will reply with your ID whenever you add it (Click Start or type `/start`)
50
58- [New followed account notifications](https://www.val.town/v/socialdata/twitterNewFollowingAlert)
59
60Migrated from folder: MonitoringAPI/twitterNewTweetAlert
2
3const discordWebhookUrl = Deno.env.get("DISCORD_WEBHOOK_URL");
4const telegramBotApiToken = Deno.env.get("TELEGRAM_API_TOKEN");
5const telegramUserId = Deno.env.get("TELEGRAM_USER_ID");
6
7if (!(discordWebhookUrl || (telegramBotApiToken && telegramUserId))) {
8 throw new Error("Either Discord webhook URL or Telegram bot API token and user ID must be provided.");
9}
10
94
95 try {
96 if (telegramBotApiToken && telegramUserId) {
97 await sendEventToTelegram(event);
98 }
175
176 if (!response.ok) {
177 throw new Error(`Discord API responded with status: ${response.status}`);
178 }
179}
214 message += `🌐 Language: ${tweet.lang.toUpperCase()}`;
215
216 const telegramApiUrl = `https://api.telegram.org/bot${telegramBotApiToken}/sendMessage`;
217
218 const payload = {
223 };
224
225 const response = await fetch(telegramApiUrl, {
226 method: "POST",
227 headers: {
233 if (!response.ok) {
234 const errorData = await response.json();
235 throw new Error(`Telegram API responded with status: ${response.status}, message: ${errorData.description}`);
236 }
237
249
250async function sendPhotoToTelegram(photoUrl: string): Promise<void> {
251 const telegramApiUrl = `https://api.telegram.org/bot${telegramBotApiToken}/sendPhoto`;
252
253 const payload = {
256 };
257
258 const response = await fetch(telegramApiUrl, {
259 method: "POST",
260 headers: {
266 if (!response.ok) {
267 const errorData = await response.json();
268 throw new Error(`Telegram API responded with status: ${response.status}, message: ${errorData.description}`);
269 }
270}
15await runMigrations();
16
17// API routes
18app.route("/api/sessions", sessions);
19app.route("/api/stats", stats);
20
21// Serve static files