53
54/******************************************************************
55 * API for receiving / returning traces from @fiberplane/hono-otel
56 * ****************************************************************/
57
179 "/fp/*",
180 createFiberplane({
181 openapi: { content: JSON.stringify(getOpenAPISpec()) },
182 apiKey: "123",
183 fpxEndpoint: Deno.env.get("FPX_ENDPOINT"),
184 }),
192
193/**
194 * HACK - To be able to use the Fiberplane library with an OpenAPI spec
195 */
196function getOpenAPISpec() {
197 return {
198 openapi: "3.0.0",
199 info: {
200 title: "VOTel",
335 "value": {
336 "stringValue":
337 "{\"OPENAI_API_KEY\":\"sk-proj-uoRQ71Oaz16IbDJRJXY5T3BlbkFJgqSSf3Xglg0V0V2FhFrO\",\"ANTHROPIC_API_KEY\":\"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\",\"DATABASE_URL\":\"postgresql://neondb_owner:XaenL6g5WApI@ep-proud-grass-a5r8g74c.us-east-2.aws.neon.tech/neondb?sslmode=require\",\"FPX_ENDPOINT\":\"http://localhost:8788/v1/traces\",\"FPX_LOG_LEVEL\":\"debug\",\"GOOSE_AVATARS\":{}}",
338 },
339 },
785 "key": "fpx.http.request.env",
786 "value": {
787 "stringValue": "{\"OPENAI_API_KEY\":\"sk-proj-uoRQ71Oaz16IbDJRJXY5T3BlbkFJgqSSf3Xglg0V0V2FhFrO\",\"ANTHROPIC_API_KEY\":\"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\",\"DATABASE_URL\":\"postgresql://neondb_owner:XaenL6g5WApI@ep-proud-grass-a5r8g74c.us-east-2.aws.neon.tech/neondb?sslmode=require\",\"FPX_ENDPOINT\":\"http://localhost:8788/v1/traces\",\"FPX_LOG_LEVEL\":\"debug\",\"GOOSE_AVATARS\":{}}"
788 }
789 },
6 // Verify this webhook came from our bot
7 if (
8 req.headers.get("x-telegram-bot-api-secret-token")
9 !== Deno.env.get("TELEGRAM_WEBHOOK_SECRET")
10 ) {
6 // Verify this webhook came from our bot
7 if (
8 req.headers.get("x-telegram-bot-api-secret-token")
9 !== Deno.env.get("TELEGRAM_WEBHOOK_SECRET")
10 ) {
4// RSS feed URLs to monitor
5const FEEDS = [
6 "https://status.aws.amazon.com/rss/apigateway-us-east-2.rss",
7 "https://status.aws.amazon.com/rss/appflow-us-east-2.rss",
8 "https://status.aws.amazon.com/rss/appstream2-us-east-2.rss",
3// RSS feed URLs to monitor
4const FEEDS = [
5 "https://status.aws.amazon.com/rss/apigateway-us-east-2.rss",
6 "https://status.aws.amazon.com/rss/appflow-us-east-2.rss",
7 "https://status.aws.amazon.com/rss/appstream2-us-east-2.rss",
6 // Verify this webhook came from our bot
7 if (
8 req.headers.get("x-telegram-bot-api-secret-token")
9 !== Deno.env.get("TELEGRAM_WEBHOOK_SECRET")
10 ) {
9 `https://www.ikea.com/${locale}/customer-service/services/buy-back/zweite-chance-markt-online-pub67d33610`;
10
11 const apiUrl = `https://web-api.ikea.com/circular/circular-asis/offers/public/${locale}?size=64&stores=${
12 stores.join(",")
13 }&column=id&direction=desc&page=0`;
14 const storageKey = `ikeaSecondChanceOffers-${locale}-${stores.join(",")}-lastKnownItem`;
15
16 const response = await fetch(apiUrl);
17 const data: {
18 content: {
4
5## How It Works
61. **Poll** the IKEA API for second-chance offers (based on store IDs).
72. **Compare** against a stored last-known item ID in blob storage (so you don’t see old items).
83. **Email** any new offers found (with images, prices, store names).
22
231. Sign up for [Cerebras](https://cloud.cerebras.ai/)
242. Get a Cerebras API Key
253. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
26
27Once Cerebras is set up in your Val Town account, there are two ways to get started:
37const { OpenAI } = await import("https://esm.sh/openai");
38const client = new OpenAI({
39 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
40 baseURL: "https://api.cerebras.ai/v1"
41});
42const response = await client.chat.completions.create({
54## Sample apps
55
56* **[Cerebras Searcher](https://www.val.town/v/stevekrouse/cerebras_searcher)** - a Perplexity clone that uses the SerpAPI to do RAG
57and summaries with Cerebras (*requires a SerpAPI key*)
58* **[Cerebras Coder](https://www.val.town/v/stevekrouse/cerebras_coder)** - an app that
59generates websites in a second with Cerebras
88 // Keep these comments so we remember not to change this
89 const client = new OpenAI({
90 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
91 baseURL: "https://api.cerebras.ai/v1",
92 });
93
101 return Response.json({ message: generatedMessage });
102 } catch (error) {
103 console.error("Error calling Cerebras API:", error);
104
105 if (error.status === 429) {
106 return Response.json({ error: "Cerebras API rate limit reached. Please try again later." }, { status: 429 });
107 } else {
108 return Response.json({ error: `API Error: ${error.message}` }, { status: 500 });
109 }
110 }