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;