Whatsapp unlink WIP #1

This commit is contained in:
Darren Clarke 2025-11-09 11:12:04 +01:00
parent 12b72a727c
commit 48165db6a2
9 changed files with 120 additions and 3 deletions

View file

@ -31,4 +31,30 @@ export class Whatsapp extends Service {
return NextResponse.json(json);
}
async relink({ params }: ServiceParams) {
const { token } = await params;
const row = await db
.selectFrom("WhatsappBot")
.selectAll()
.where("token", "=", token as string)
.executeTakeFirstOrThrow();
const id = row.id;
// Step 1: Call unverify to remove the bot directory and disconnect
const unverifyUrl = `${process.env.BRIDGE_WHATSAPP_URL}/api/bots/${id}/unverify`;
await fetch(unverifyUrl, { method: "POST" });
// Step 2: Reset verified flag in database
await db
.updateTable("WhatsappBot")
.set({ verified: false })
.where("id", "=", id)
.execute();
// Step 3: Revalidate the path to refresh the UI
revalidatePath(`/whatsapp/${id}`);
return NextResponse.json({ success: true, message: "WhatsApp connection reset. Please scan the new QR code." });
}
}