import "server-only"; import { sql } from "drizzle-orm"; import { db } from "./db"; export type BotCommand = | { type: "account.start_pairing"; accountId: string } | { type: "account.unpair"; accountId: string } // Like account.unpair, but the bot also calls socket.logout() so // WhatsApp drops this device from the operator's linked-devices // list before the row is deleted. | { type: "account.delete"; accountId: string } | { type: "account.sync_groups"; accountId: string } | { type: "group.send_test"; groupId: string; text: string } | { type: "reminder.schedule"; reminderId: string; scheduledAtIso: string } | { type: "reminder.resume"; reminderId: string; runId: string }; export async function pgNotifyBot(cmd: BotCommand): Promise { const json = JSON.stringify(cmd); await db.execute(sql`SELECT pg_notify('bot.command', ${json})`); }