Proposal Generator
Module 24 · business · intermediate
sent.js
// Mark the proposal sent only if Gmail returned a message id.
const x = $('Assemble Proposal').first().json;
const res = $input.first().json;
const sent = Boolean(res.id) && !res.ok; // Gmail's response has id/threadId; without a credential the input item passes through
const p = $getWorkflowStaticData('global').proposals[x.id];
if (sent) { p.status = 'sent'; p.sent_at = new Date().toISOString(); }
else p.send_error = String(res.error?.message ?? res.error ?? 'no message id returned (check the Gmail credential)').slice(0, 300);
const { html, ...rest } = x;
return [{ json: { ...rest, status: p.status, sent, send_error: sent ? null : p.send_error } }];