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
- 408 Timeout / Curl Error 7 in Executor w...
Hey everyone, I am losing my mind over a routing loop/timeout issue on a fresh self-hosted setup. I have a single Linux VPS (IP: 45.141.37.105) and one domain (...
- functions returning error 401 in local
I updated to 1.9.0, and the functions that used to work fine in 1.8.1 are now giving me a 401 error. I can't seem to find a solution. If anyone is running versi...
- router_deployment_not_found
I updated my function a few times and now i am getting the error: router_deployment_not_found I even reverted back to my original code but i am still getting th...