Add Metamigo webhooks

This commit is contained in:
Darren Clarke 2024-04-21 08:11:24 +02:00
parent 87c2c2f8b7
commit 242f3cf6b8
15 changed files with 81 additions and 76 deletions

View file

@ -67,6 +67,27 @@ const deleteBot = async (req: NextRequest) => {
return NextResponse.json({ response: "ok" });
};
const handleWebhook = async (req: NextRequest) => {
console.log({ req });
const { searchParams } = req.nextUrl;
const token = searchParams.get("hub.verify_token");
if (token !== process.env.FB_VERIFY_TOKEN) {
// return NextResponse.error("Invalid token", { status: 403 });
}
if (searchParams.get("hub.mode") === "subscribe") {
const challenge = searchParams.get("hub.challenge");
console.log(token);
console.log(challenge);
return new Response(challenge, { status: 200 }) as NextResponse;
}
return NextResponse.json({ response: "ok" });
};
export const Facebook: Service = {
getAllBots,
getOneBot,
@ -79,4 +100,5 @@ export const Facebook: Service = {
refreshBot,
createBot,
deleteBot,
handleWebhook,
};