This is what all it required by polar to see the webhook data. Managing with webhook data is not an issue, but how do I pair this all with appwrite functions structure so I will be able to verify the signature and get the webhook data in the first place?
import { Hono } from "hono";
import { Webhooks } from "@polar-sh/hono";
const app = new Hono();
app.post(
"/polar/webhooks",
Webhooks({
webhookSecret: process.env.POLAR_WEBHOOK_SECRET!,
onPayload: async (payload) => {
console.log("Received webhook payload:", payload);
},
})
);
Do you have something like this
https://github.com/dishwasher-detergent/kurioh/blob/main/functions/api/src/main.ts#L44-L45 https://github.com/dishwasher-detergent/kurioh/blob/main/functions/api/src/lib/utils.ts#L6
that converts the appwrite context into a context for hono?
var Webhooks = ({
webhookSecret,
onPayload,
entitlements,
...eventHandlers
}) => {
return async (c) => {
const requestBody = await c.req.text();
const webhookHeaders = {
"webhook-id": c.req.header("webhook-id") ?? "",
"webhook-timestamp": c.req.header("webhook-timestamp") ?? "",
"webhook-signature": c.req.header("webhook-signature") ?? ""
};
let webhookPayload;
try {
webhookPayload = validateEvent(
requestBody,
webhookHeaders,
webhookSecret
);
} catch (error) {
if (error instanceof WebhookVerificationError) {
return c.json({ received: false }, { status: 403 });
}
throw error;
}
await handleWebhookPayload(webhookPayload, {
webhookSecret,
entitlements,
onPayload,
...eventHandlers
});
return c.json({ received: true });
};
};
const validateEvent = (body, headers, secret) => {
const base64Secret = Buffer.from(secret, "utf-8").toString("base64");
const webhook = new Webhook(base64Secret);
try {
const parsed = webhook.verify(body, headers);
return parseEvent(parsed);
}
catch (error) {
if (error instanceof _WebhookVerificationError) {
throw new WebhookVerificationError(error.message);
}
throw error;
}
};
what does your main entry point to the function look like
What do you mean?
How is this being served by appwrites function?
Recommended threads
- Feedback and Deployment Challenges with ...
Hello world!, I've been developing a project using FastAPI in Python, and I was considering deploying it through Appwrite Functions. However, I encountered a f...
- Bulk feature status
Hi there, I am using version 1.7.4 self hosted and wanted to use the bulk operations in a dart function. I saw that in the dart_appwrite sdk version 16.1.0 it ...
- CORS preflight returns 500 on Dart funct...
Hey everyone 👋 I’m running a Dart cloud function, Every time I respond to a preflight (OPTIONS) request, I get a 500 internal error, and the logs show: ```NoSu...