+
+ {/* Send Test Message */}
+
+
+ Send Test Message
+
+ Send a one-off message to this group to verify the connection.
+
+
+
+
+
+
+
+ {/* Use in reminder */}
+
+
+
+
+
+
+
+
Use in a Reminder
+
+ Schedule recurring messages to this group
+
+
+
+
+
+
+
+ {/* Last synced */}
+
+
+ Last synced: {lastSynced}
+
+
+ );
+}
diff --git a/apps/web/src/lib/queries.ts b/apps/web/src/lib/queries.ts
index 3269c09..560f701 100644
--- a/apps/web/src/lib/queries.ts
+++ b/apps/web/src/lib/queries.ts
@@ -43,3 +43,44 @@ export async function getAccount(operatorId: string, accountId: string) {
where: (a, { eq, and }) => and(eq(a.id, accountId), eq(a.operatorId, operatorId)),
});
}
+
+export async function listGroupsForAccount(operatorId: string, accountId: string, q?: string) {
+ const account = await getAccount(operatorId, accountId);
+ if (!account) return null;
+ const trimmed = (q ?? "").trim();
+ const rows = trimmed
+ ? await db.execute(sql`
+ SELECT id, account_id, wa_group_jid, name, participant_count, is_archived, last_synced_at
+ FROM whatsapp_groups
+ WHERE account_id = ${accountId} AND name % ${trimmed}
+ ORDER BY similarity(name, ${trimmed}) DESC
+ LIMIT 50
+ `)
+ : await db.execute(sql`
+ SELECT id, account_id, wa_group_jid, name, participant_count, is_archived, last_synced_at
+ FROM whatsapp_groups
+ WHERE account_id = ${accountId}
+ ORDER BY name ASC
+ LIMIT 200
+ `);
+ const groups = (rows.rows as Array>).map((r) => ({
+ id: r.id as string,
+ accountId: r.account_id as string,
+ waGroupJid: r.wa_group_jid as string,
+ name: r.name as string,
+ participantCount: Number(r.participant_count),
+ isArchived: r.is_archived as boolean,
+ lastSyncedAt: r.last_synced_at as Date,
+ }));
+ return { account, groups };
+}
+
+export async function getGroup(operatorId: string, groupId: string) {
+ const group = await db.query.whatsappGroups.findFirst({
+ where: (g, { eq }) => eq(g.id, groupId),
+ });
+ if (!group) return null;
+ const account = await getAccount(operatorId, group.accountId);
+ if (!account) return null;
+ return { group, account };
+}