Skip to content
// No-AI fallback: a short, stage-aware follow-up draft per deal.
const OPENERS = {
  'appointmentscheduled': 'Looking forward to our call. Is the time we booked still good for you?',
  'qualifiedtobuy': 'I put together a few ideas based on what you shared. Would a 15-minute call this week work to walk through them?',
  'presentationscheduled': 'Following up on our presentation. What questions came up on your side?',
  'decisionmakerboughtin': 'Great to have everyone aligned. Shall I send over the next steps and timeline?',
  'contractsent': 'Just checking you received the contract. Happy to clarify anything before you sign.',
};
return $input.all().map(({ json: d }) => {
  const first = d.contact ? d.contact.split(' ')[0] : 'there';
  const line = OPENERS[d.stage] ?? 'Wanted to follow up on our last conversation. Is this still a priority for you?';
  return {
    json: {
      ...d,
      draft_subject: `Following up: ${d.name}`,
      draft_body: `Hi ${first},\n\n${line}\n\nBest,\n${d.owner.split(' ')[0]}`,
      draft_source: 'template',
    },
  };
});