Whatsapp service updates
This commit is contained in:
parent
e22a8e8d98
commit
3da103c010
16 changed files with 151 additions and 36 deletions
|
|
@ -1,3 +1,35 @@
|
|||
import { Service } from "./service";
|
||||
import { NextResponse } from "next/server";
|
||||
import { db } from "bridge-common";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { Service, ServiceParams } from "./service";
|
||||
|
||||
export class Whatsapp extends Service {}
|
||||
export class Whatsapp extends Service {
|
||||
async getBot({ params: { token } }: ServiceParams) {
|
||||
const row = await db
|
||||
.selectFrom("WhatsappBot")
|
||||
.selectAll()
|
||||
.where("token", "=", token as string)
|
||||
.executeTakeFirstOrThrow();
|
||||
const id = row.id;
|
||||
const url = `${process.env.BRIDGE_WHATSAPP_URL}/api/bots/${id}`;
|
||||
const result = await fetch(url, { cache: "no-store" });
|
||||
console.log({ result1: result });
|
||||
const json = await result.json();
|
||||
|
||||
await db
|
||||
.updateTable("WhatsappBot")
|
||||
.set({ verified: json.verified })
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
|
||||
revalidatePath(`/whatsapp/${id}`);
|
||||
|
||||
if (!json.verified) {
|
||||
const url = `${process.env.BRIDGE_WHATSAPP_URL}/api/bots/${id}/register`;
|
||||
const result = await fetch(url, { method: "POST", cache: "no-store" });
|
||||
console.log({ result2: result });
|
||||
}
|
||||
|
||||
return NextResponse.json(json);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue