
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
- The function became slower after being e...
I used the Python SDK and set `xasync=True` in `create_execution`, expecting it to execute quickly on another worker. However, the execution ended up taking sev...
- CORS errors on prod
Hi, I have an appwrite function all of a sudden it starts to give CORS errors on production environment, although it works fine but 3/5 times it gives CORS erro...
- How to reduce cold start times for cloud...
Is there anything I can do to prevent slow responses? How long does it take for a function to enter a "cold state"?
