Creación de planes y asignaturas en segundo plano y con webhook de openai #40
@@ -5,6 +5,7 @@
|
||||
"jsr:@david/dax@~0.44.2": "0.44.2",
|
||||
"jsr:@david/path@0.2": "0.2.0",
|
||||
"jsr:@david/which@~0.4.1": "0.4.1",
|
||||
"jsr:@helpr/express@*": "0.1.1",
|
||||
"jsr:@openai/openai@*": "6.16.0",
|
||||
"jsr:@openai/openai@^6.16.0": "6.16.0",
|
||||
"jsr:@std/bytes@^1.0.6": "1.0.6",
|
||||
@@ -54,6 +55,9 @@
|
||||
"@david/which@0.4.1": {
|
||||
"integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e"
|
||||
},
|
||||
"@helpr/express@0.1.1": {
|
||||
"integrity": "15391b350b92ab5102919c555179c954ff3d5974d7f170b99880836e249756d2"
|
||||
},
|
||||
"@openai/openai@6.16.0": {
|
||||
"integrity": "ccee548f61c382d715091fff0c2c3390a4487823644430b8235df543d6d6a78b",
|
||||
"dependencies": [
|
||||
|
||||
@@ -1 +1 @@
|
||||
v2.185.0
|
||||
v2.187.0
|
||||
@@ -1 +1 @@
|
||||
buckets-objects-grants-postgres
|
||||
fix-optimized-search-function
|
||||
@@ -1 +1 @@
|
||||
v1.33.0
|
||||
v1.37.7
|
||||
@@ -48,3 +48,14 @@ entrypoint = "./functions/generate-subject-suggestions/index.ts"
|
||||
# Specifies static files to be bundled with the function. Supports glob patterns.
|
||||
# For example, if you want to serve static HTML pages in your function:
|
||||
# static_files = [ "./functions/generate-subject-suggestions/*.html" ]
|
||||
|
||||
[functions.openai-webhook-responses]
|
||||
enabled = true
|
||||
verify_jwt = true
|
||||
import_map = "./functions/openai-webhook-responses/deno.json"
|
||||
# Uncomment to specify a custom file path to the entrypoint.
|
||||
# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx
|
||||
entrypoint = "./functions/openai-webhook-responses/index.ts"
|
||||
# Specifies static files to be bundled with the function. Supports glob patterns.
|
||||
# For example, if you want to serve static HTML pages in your function:
|
||||
# static_files = [ "./functions/openai-webhook-responses/*.html" ]
|
||||
|
||||
+2481
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
# Configuration for private npm package dependencies
|
||||
# For more information on using private registries with Edge Functions, see:
|
||||
# https://supabase.com/docs/guides/functions/import-maps#importing-from-private-registries
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"imports": {
|
||||
"@supabase/functions-js/edge-runtime.d.ts": "jsr:@supabase/functions-js@^2/edge-runtime.d.ts",
|
||||
"express": "npm:express@5.2.1",
|
||||
"openai": "npm:openai@6.16.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Follow this setup guide to integrate the Deno language server with your editor:
|
||||
// https://deno.land/manual/getting_started/setup_your_environment
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
// Setup type definitions for built-in Supabase Runtime APIs
|
||||
import "@supabase/functions-js/edge-runtime.d.ts";
|
||||
import express from "express";
|
||||
import OpenAI from "openai";
|
||||
|
||||
const app = express();
|
||||
const client = new OpenAI({
|
||||
webhookSecret: Deno.env.get("OPENAI_WEBHOOK_SECRET"),
|
||||
});
|
||||
|
||||
app.use(express.text({ type: "application/json" }));
|
||||
|
||||
app.post("/webhook", async (req: express.Request, res: express.Response) => {
|
||||
try {
|
||||
const event = await client.webhooks.unwrap(req.body, req.headers);
|
||||
|
||||
if (event.type === "response.completed") {
|
||||
const response_id = event.data.id;
|
||||
const response = await client.responses.retrieve(response_id);
|
||||
const output_text = response.output
|
||||
.filter((item) => item.type === "message")
|
||||
.flatMap((item) => item.content)
|
||||
.filter((contentItem) => contentItem.type === "output_text")
|
||||
.map((contentItem) => contentItem.text)
|
||||
.join("");
|
||||
|
||||
console.log("Response output:", output_text);
|
||||
}
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
if (error instanceof OpenAI.InvalidWebhookSignatureError) {
|
||||
console.error("Invalid signature", error);
|
||||
res.status(400).send("Invalid signature");
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
console.log("Inicio de openai-webhook-responses");
|
||||
|
||||
return await app.handle(req);
|
||||
});
|
||||
+1888
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user