From 06b84bf2d71891de6caf3fd565775ebd2bfefdde Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Fri, 17 Apr 2026 11:08:47 -0400 Subject: [PATCH] fix(rsocials): list-and-match fallback to recover postizPostId after create Postiz's POST /public/v1/posts response shape doesn't reliably include the new post's id (varies by version). When parsing fails, query listPosts in a narrow window right after create and match by integration+content to recover the real id. Without this, reconcile can't find queued posts back in Postiz. Co-Authored-By: Claude Opus 4.7 (1M context) --- modules/rsocials/mod.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/rsocials/mod.ts b/modules/rsocials/mod.ts index 94d7b4cb..84d7093a 100644 --- a/modules/rsocials/mod.ts +++ b/modules/rsocials/mod.ts @@ -885,12 +885,28 @@ async function sendCampaignNodeToPostiz( try { const result = await createPost(config, payload); - // Postiz returns either { id } or an array — be defensive. - const postizPostId = (result as any)?.id + // Postiz returns either { id } or an array — be defensive on parse. + let postizPostId: string = (result as any)?.id || (Array.isArray(result) && (result[0] as any)?.id) || (result as any)?.posts?.[0]?.id || ''; + // Fallback: Postiz's create response shape varies by version and often + // doesn't include the new post id. Query listPosts in a narrow window, + // then find by integration + content to recover the real id. + if (!postizPostId) { + try { + const windowStart = new Date(Date.now() - 60_000); + const windowEnd = new Date(Date.now() + 365 * 86400_000); + const listed = await listPosts(config, windowStart, windowEnd); + const match = listed.find(p => + p.integration?.id === integrations[0].id && + (p.content || '').trim() === payload.content.trim() + ); + if (match) postizPostId = match.id; + } catch { /* leave id empty, reconcile will treat as lost */ } + } + _syncServer!.changeDoc(docId, `postiz send ${nodeId}`, (d) => { const f = d.campaignFlows?.[flowId]; if (!f) return;