Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(automation): filter reply activity by several statuses at once
spacesdrive3e4d79556702
diff --git a/backend/repositories/automationCommentRepository.ts b/backend/repositories/automationCommentRepository.tsindex cd73e54..56dd23a 100644--- a/backend/repositories/automationCommentRepository.ts+++ b/backend/repositories/automationCommentRepository.ts@@ -89,7 +89,7 @@ export interface Reservation {export interface ActivityFilter {accountId?: string;ruleId?: string;- status?: AutomationCommentStatus;+ statuses?: AutomationCommentStatus[];from?: string;to?: string;// created_at of the last item on the previous page@@ -253,12 +253,12 @@ export function createAutomationCommentRepository(db: SupabaseClient): Automatio},// newest first; a full page may have more after it, and the next page asks for rows before the last one's time- async listForUser(userId, { accountId, ruleId, status, from, to, before, limit }) {+ async listForUser(userId, { accountId, ruleId, statuses, from, to, before, limit }) {const found = await rows<AutomationCommentRow>('automationComments.listForUser', () => {let query = db.from('automation_comments').select(COLUMNS).eq('user_id', userId);if (accountId) query = query.eq('account_id', accountId);if (ruleId) query = query.eq('rule_id', ruleId);- if (status) query = query.eq('status', status);+ if (statuses?.length) query = query.in('status', statuses);if (from) query = query.gte('created_at', from);if (to) query = query.lt('created_at', to);if (before) query = query.lt('created_at', before);diff --git a/backend/tests/repositories/automationCommentRepository.test.ts b/backend/tests/repositories/automationCommentRepository.test.tsindex a4b9a48..3b97b6a 100644--- a/backend/tests/repositories/automationCommentRepository.test.ts+++ b/backend/tests/repositories/automationCommentRepository.test.ts@@ -92,8 +92,10 @@ describe('automation comment repository', () => {test('activity filters by user first, then by every filter given', async () => {const supabase = fakeSupabase([]);- await createAutomationCommentRepository(supabase).listForUser('user-1', { accountId: 'ig1', status: 'failed', before: 'B', from: 'F', limit: 20 });- assert.deepEqual(supabase.calls[0].filters, [['user_id', 'user-1'], ['account_id', 'ig1'], ['status', 'failed'], ['created_at', 'F', 'gte'], ['created_at', 'B', 'lt']]);+ await createAutomationCommentRepository(supabase).listForUser('user-1', { accountId: 'ig1', statuses: ['failed', 'needs_review'], before: 'B', from: 'F', limit: 20 });+ assert.deepEqual(supabase.calls[0].filters, [+ ['user_id', 'user-1'], ['account_id', 'ig1'], ['status', ['failed', 'needs_review'], 'in'], ['created_at', 'F', 'gte'], ['created_at', 'B', 'lt'],+ ]);});test('stats come from the database function, with empty groups when nothing happened', async () => {diff --git a/backend/tests/routes/automationRoutes.test.ts b/backend/tests/routes/automationRoutes.test.tsindex 0e6e3c3..af148b6 100644--- a/backend/tests/routes/automationRoutes.test.ts+++ b/backend/tests/routes/automationRoutes.test.ts@@ -151,7 +151,7 @@ describe('automation routes', () => {});test('activity lists only the user\'s comments, newest page first', async () => {- const { body } = await call(server(), 'GET', '/automations/activity?status=failed&limit=1');+ const { body } = await call(server(), 'GET', '/automations/activity?status=failed,needs_review&limit=1');assert.deepEqual(body.items.map((item: { id: string }) => item.id), ['failed-mine']);assert.equal(body.nextBefore, '2026-10-15T00:00:00Z');});diff --git a/backend/tests/validators/automationValidators.test.ts b/backend/tests/validators/automationValidators.test.tsindex ddc43ea..8bd5706 100644--- a/backend/tests/validators/automationValidators.test.ts+++ b/backend/tests/validators/automationValidators.test.ts@@ -69,13 +69,13 @@ test('a test needs a sample comment besides the rule draft', () => {});test('activity filters are checked and dates normalised; the page size defaults to 50 and stops at 100', () => {- assert.deepEqual(parseActivityQuery({ status: 'failed', from: '2026-10-01', before: '2026-10-10T00:00:00Z' }), {- accountId: undefined, ruleId: undefined, status: 'failed', from: '2026-10-01T00:00:00.000Z', to: undefined,+ assert.deepEqual(parseActivityQuery({ status: 'failed, needs_review,failed', from: '2026-10-01', before: '2026-10-10T00:00:00Z' }), {+ accountId: undefined, ruleId: undefined, statuses: ['failed', 'needs_review'], from: '2026-10-01T00:00:00.000Z', to: undefined,before: '2026-10-10T00:00:00.000Z', limit: 50,});assert.equal(parseActivityQuery({ limit: '100' }).limit, 100);assert.throws(() => parseActivityQuery({ limit: '101' }), /from 1 to 100/);- assert.throws(() => parseActivityQuery({ status: 'lost' }), /status must be one of/);+ assert.throws(() => parseActivityQuery({ status: 'failed,lost' }), /status must be one of/);assert.throws(() => parseStatsQuery({ from: 'yesterday' }), /from must be a date/);});diff --git a/backend/validators/automationValidators.ts b/backend/validators/automationValidators.tsindex f1fd64a..e130452 100644--- a/backend/validators/automationValidators.ts+++ b/backend/validators/automationValidators.ts@@ -23,7 +23,8 @@ const MAX_PAGE = 100;export interface ActivityQuery {accountId?: string;ruleId?: string;- status?: AutomationCommentStatus;+ // one status or several, sent as a comma-separated list+ statuses?: AutomationCommentStatus[];from?: string;to?: string;before?: string;@@ -123,11 +124,12 @@ function isoDate(query: Fields, field: string): string | undefined {return new Date(time).toISOString();}-function status(query: Fields): AutomationCommentStatus | undefined {+function statuses(query: Fields): AutomationCommentStatus[] | undefined {const value = optionalString(query, 'status');if (!value) return undefined;- if (!STATUSES.includes(value as AutomationCommentStatus)) throw new ValidationError(`status must be one of ${STATUSES.join(', ')}`);- return value as AutomationCommentStatus;+ const list = [...new Set(value.split(',').map(item => item.trim()).filter(Boolean))];+ if (list.some(item => !STATUSES.includes(item as AutomationCommentStatus))) throw new ValidationError(`status must be one of ${STATUSES.join(', ')}`);+ return list as AutomationCommentStatus[];}export function parseAutomationRule(body: Fields): AutomationRuleRequest {@@ -186,7 +188,7 @@ export function parseActivityQuery(query: Fields): ActivityQuery {return {accountId: optionalString(query, 'accountId') || undefined,ruleId: optionalString(query, 'ruleId') || undefined,- status: status(query),+ statuses: statuses(query),from: isoDate(query, 'from'),to: isoDate(query, 'to'),before: isoDate(query, 'before'),