Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(content): say a webhook redirects after a bulk send, and in the webhook test, as a single send does (#1672)
Cihan65698d816a5d
diff --git a/server/src/routes/content-webhooks.test.js b/server/src/routes/content-webhooks.test.jsindex 8225e10d7..23cf81e73 100644--- a/server/src/routes/content-webhooks.test.js+++ b/server/src/routes/content-webhooks.test.js@@ -174,7 +174,13 @@ describe('POST /api/content/webhook-test', () => {it('reads a redirect as an answer, not a success', async () => {postJson.mockResolvedValue({ status: 302, answer: '' });const res = await test({ webhookUrl: 'https://hooks.example/abc' });- expect(await res.json()).toEqual({ success: false, status: 302, statusText: 'Found' });+ // In a send's words, so the dialog says it as a send would (#1590).+ expect(await res.json()).toEqual({+ success: false,+ status: 302,+ statusText: 'Found',+ error: 'The webhook address redirects. Use the address it redirects to.',+ });expect(postJson.mock.calls[0][2]).toEqual({ headers: {}, timeoutMs: 10_000 });});@@ -185,6 +191,7 @@ describe('POST /api/content/webhook-test', () => {success: false,status: 308,statusText: 'Permanent Redirect',+ error: 'The webhook address redirects. Use the address it redirects to.',location: 'https://hooks.example/v2',});});@@ -342,7 +349,7 @@ describe('POST /api/content/bulk/send-webhook', () => {.mockResolvedValueOnce({ status: 200, answer: 'ok' }).mockRejectedValueOnce(new Error('The webhook could not be reached'));const res = await post('/bulk/send-webhook', { ids: ['o1', 'o2'] });- expect(await res.json()).toEqual({ sent: 1, failed: 1 });+ expect(await res.json()).toEqual({ sent: 1, failed: 1, redirected: 0 });expect(postJson.mock.calls.map(([address, body, opts]) => [address,@@ -358,13 +365,13 @@ describe('POST /api/content/bulk/send-webhook', () => {expect(writes[0].values.webhook_response).toEqual({ status: 200, body: 'ok' });});- it('counts a redirect failed and marks only the delivered one sent', async () => {+ it('counts a redirect failed, and redirected, and marks only the delivered one sent', async () => {rows.content_opportunities = [OPPORTUNITY, { ...OPPORTUNITY, id: 'o2', title: 'FAQ page' }];postJson.mockResolvedValueOnce({ status: 302, answer: '' }).mockResolvedValueOnce({ status: 200, answer: 'ok' });const res = await post('/bulk/send-webhook', { ids: ['o1', 'o2'] });- expect(await res.json()).toEqual({ sent: 1, failed: 1 });+ expect(await res.json()).toEqual({ sent: 1, failed: 1, redirected: 1 });const writes = updates.filter((u) => u.table === 'content_opportunities');expect(writes).toHaveLength(1);expect(writes[0].values.webhook_response).toEqual({ status: 200, body: 'ok' });diff --git a/server/src/routes/content.js b/server/src/routes/content.jsindex 984e389a1..cdacc0885 100644--- a/server/src/routes/content.js+++ b/server/src/routes/content.js@@ -38,6 +38,9 @@ import {runningSuggestionJob,} from '../lib/prompt-content-suggestion.js';+/** What a send says of a webhook that redirects, and the test too: nothing reaches where it points. */+const WEBHOOK_REDIRECT_ERROR = 'The webhook address redirects. Use the address it redirects to.';+const router = Router();/** The job a repeated "+ New" or alternative request already started. */@@ -897,6 +900,8 @@ router.post('/bulk/send-webhook', async (req, res) => {let sent = 0;let failed = 0;+ // Failed because the address redirects: every row meets the same one.+ let redirected = 0;// What the workflow receives reads the way the page shows it.const competitors = await competitorNames(brandId);@@ -942,6 +947,7 @@ router.post('/bulk/send-webhook', async (req, res) => {// A redirect isn't followed, so nothing arrived: not sent.if (isRedirect(webhookRes.status)) {failed++;+ redirected++;continue;}const responseBody = webhookRes.answer;@@ -970,7 +976,7 @@ router.post('/bulk/send-webhook', async (req, res) => {}}- return res.json({ sent, failed });+ return res.json({ sent, failed, redirected });} catch (error) {req.log.error({ err: error }, 'bulk send webhook error');return res.status(500).json({@@ -1132,7 +1138,7 @@ router.post('/:id/send-webhook', async (req, res) => {// opportunity keeps its status, as Send to CMS fails a 3xx.if (isRedirect(webhookRes.status)) {return res.status(502).json({- error: 'The webhook address redirects. Use the address it redirects to.',+ error: WEBHOOK_REDIRECT_ERROR,code: 'webhook_redirect',webhookStatus: webhookRes.status,});@@ -1257,8 +1263,9 @@ router.post('/webhook-test', webhookTestLimiter, async (req, res) => {success: webhookRes.status >= 200 && webhookRes.status < 300,status: webhookRes.status,statusText: STATUS_CODES[webhookRes.status] ?? '',- // Where a redirect points (postJson gives it for a 3xx only), so the- // dialog can name the address to use.+ // A redirect in a send's words, and where it points (postJson gives+ // it for a 3xx only), so the dialog can name the address to use.+ ...(isRedirect(webhookRes.status) ? { error: WEBHOOK_REDIRECT_ERROR } : {}),...(webhookRes.location ? { location: webhookRes.location } : {}),});} catch (error) {diff --git a/web/messages/en.json b/web/messages/en.jsonindex be4f418df..64b60e52d 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -6171,7 +6171,8 @@"sentToWorkflow": "Sent to workflow!","sendError": "Failed to send","dismissError": "Failed to dismiss",- "bulkSentToast": "Sent {sent} opportunities to workflow",+ "bulkSentToast": "Sent {sent, plural, one {# opportunity} other {# opportunities}} to workflow",+ "bulkSendRedirect": "Nothing was sent: the webhook address redirects. Use the address it redirects to.","bulkSendPartialError": "{failed} failed to send","bulkSendError": "Failed to send opportunities.","bulkDoneToast": "Marked {updated} opportunities as done",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsxindex e39f7000b..a01898180 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx@@ -84,6 +84,7 @@ import { getOpportunityDrafts } from '@/lib/actions/content-drafts';import { getPlanPriorities, setPlanRowPriority } from '@/lib/actions/content-plan';import { OpportunityRowMenu } from '@/components/content/opportunity-row-menu';import { useUserRole } from '@/hooks/use-user-role';+import { bulkSendNotes } from '@/lib/content/bulk-send';import { contentEditorPath } from '@/lib/content/drafts';import { canWriteOpportunity, opportunityStart } from '@/lib/content/opportunity-start';import { siteTypeOf } from '@/lib/content/page-types';@@ -927,8 +928,10 @@ export default function ContentPage() {toast.error(result.error);return;}- toast.success(t('bulkSentToast', { sent: result.sent }));- if (result.failed > 0) toast.error(t('bulkSendPartialError', { failed: result.failed }));+ const notes = bulkSendNotes(result);+ if (notes.sent !== null) toast.success(t('bulkSentToast', { sent: notes.sent }));+ if (notes.failure === 'redirect') toast.error(t('bulkSendRedirect'));+ else if (notes.failure) toast.error(t('bulkSendPartialError', { failed: result.failed }));setSelectedIds(new Set());await loadData(true);} catch (err) {diff --git a/web/src/lib/actions/content.ts b/web/src/lib/actions/content.tsindex 044587a2e..ab459a75c 100644--- a/web/src/lib/actions/content.ts+++ b/web/src/lib/actions/content.ts@@ -561,6 +561,8 @@ export type BulkSendResult =success: true;sent: number;failed: number;+ /** Of the failed, those whose webhook redirects (0 from an API before #1590's follow-up). */+ redirected: number;}| {success: false;@@ -593,6 +595,7 @@ export async function bulkSendToWebhook(ids: string[]): Promise<BulkSendResult>success: true,sent: data.sent,failed: data.failed,+ redirected: data.redirected ?? 0,};}diff --git a/web/src/lib/content/bulk-send.test.ts b/web/src/lib/content/bulk-send.test.tsnew file mode 100644index 000000000..aa687bb96--- /dev/null+++ b/web/src/lib/content/bulk-send.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest';+import { bulkSendNotes } from './bulk-send';++/** Opportunities' notes after a bulk send to the workflow (#1590). */++describe('bulkSendNotes', () => {+ it('says how many were sent only when any were', () => {+ expect(bulkSendNotes({ sent: 3, failed: 0, redirected: 0 })).toEqual({+ sent: 3,+ failure: null,+ });+ expect(bulkSendNotes({ sent: 0, failed: 2, redirected: 0 }).sent).toBeNull();+ });++ it('says the address redirects when every failure was a redirect', () => {+ expect(bulkSendNotes({ sent: 0, failed: 3, redirected: 3 })).toEqual({+ sent: null,+ failure: 'redirect',+ });+ });++ it('counts the failures, not "Nothing was sent", when some were sent', () => {+ expect(bulkSendNotes({ sent: 1, failed: 1, redirected: 1 })).toEqual({+ sent: 1,+ failure: 'failed',+ });+ });++ it('counts the failures when some had another cause, or an older API says none', () => {+ expect(bulkSendNotes({ sent: 1, failed: 2, redirected: 1 }).failure).toBe('failed');+ expect(bulkSendNotes({ sent: 1, failed: 2 }).failure).toBe('failed');+ });+});diff --git a/web/src/lib/content/bulk-send.ts b/web/src/lib/content/bulk-send.tsnew file mode 100644index 000000000..99e5fcf69--- /dev/null+++ b/web/src/lib/content/bulk-send.ts@@ -0,0 +1,22 @@+/**+ * What Opportunities says after a bulk send to the workflow (#1590): how+ * many were sent, only when any were, and why the others weren't. A+ * webhook that redirects does so for every row, so when nothing was sent+ * and every failure was a redirect, it says so, as a single send does; else+ * how many failed (some got through, so "Nothing was sent" would be wrong).+ */+export function bulkSendNotes(result: { sent: number; failed: number; redirected?: number }): {+ sent: number | null;+ failure: 'redirect' | 'failed' | null;+} {+ const redirected = result.redirected ?? 0;+ return {+ sent: result.sent > 0 ? result.sent : null,+ failure:+ result.failed === 0+ ? null+ : result.sent === 0 && redirected > 0 && redirected === result.failed+ ? 'redirect'+ : 'failed',+ };+}