Instantly Autoreply
Purpose
Automatically generate and send intelligent replies to incoming emails from Instantly campaigns, using campaign-specific knowledge bases and web research.
Inputs
The webhook receives this payload from Instantly (reply event):
timestamp: ISO timestamp when the event occurredevent_type: Type of event (e.g., "reply")campaign_id: UUID of the campaigncampaign_name: Name of the campaign (format: "CAMPAIGN_ID | Campaign Name")lead_email: The prospect's email addressemail_account: The sending account (eaccount)email_id: UUID of the email to reply to (use as reply_to_uuid)reply_subject: Subject line of the incoming replyreply_text: Full plain text content of the incoming replyreply_html: Full HTML content of the incoming replyreply_text_snippet: Short preview of the reply content- Additional lead data fields may be present
Process
Step 1: Parse Incoming Reply
The incoming email content is already in the payload:
reply_textorreply_html: The full content of their replyreply_subject: Their subject line Use this directly - no need to fetch.
Step 2: Get Full Conversation History (Optional)
If more context is needed, call instantly_get_emails with the lead_email to retrieve prior emails (limit 10).
Step 3: Extract Campaign ID
Parse the campaign_name to get the ID (everything before the "|"). Or use campaign_id directly if available.
Step 4: Lookup Knowledge Base
Call read_sheet on spreadsheet 1QS7MYDm6RUTzzTWoMfX-0G9NzT5EoE2KiCE7iR1DBLM to find the row where column "ID" matches the campaign ID. Extract:
Knowledge Base: Campaign-specific context and talking pointsReply Examples: Example replies to match tone
Step 5: Skip if No Knowledge Base
If no knowledge base found for this campaign, skip processing and return empty.
Step 6: Generate Reply
Using extended thinking, generate a reply following these rules:
Role & Tone:
- Write as the email_account (first person: 'I', 'we')
- Concise, confident, friendly, non-corporate, outcome-focused
- No em dashes (—), no over-explaining, no hype, no filler
- If followup: be light but persistent, illustrate value props
Research (use web_search tool):
- Research the sender and their company/clinic thoroughly
- Look up any products, tools, locations, acronyms you don't recognize
- Use research to tailor the reply (don't mention you searched)
When to Return Empty (no reply):
- If additional email would be needless (they confirmed call, logistics done)
- If explicitly negative: "DO NOT EMAIL", "UNSUBSCRIBE", "remove me from list"
- If no knowledge base found
Output Format:
- 3-8 sentences unless thread requires more
- HTML with
<br>for line breaks,<br><br>between paragraphs - No
<html>,<body>,<p>tags - Sign off with first name from email_account
Step 7: Filter Empty Replies
If the generated reply is empty or just whitespace, do NOT send. Return success with skipped: true.
Step 8: Send Reply
Call instantly_send_reply with:
eaccount: The email_account from inputreply_to_uuid: The email_id from inputsubject: The reply_subject from inputhtml_body: The generated reply
Output
Return:
status: "success" or "error"skipped: true if reply was intentionally emptyreply_sent: true if reply was actually sentmessage_id: ID from Instantly if sent
Error Handling
- If Instantly API fails: Log error, return error status
- If knowledge base lookup fails: Skip this email (no KB = no reply)
- If AI generation fails: Log error, do not send partial reply
Knowledge Base Sheet Structure
Spreadsheet ID: 1QS7MYDm6RUTzzTWoMfX-0G9NzT5EoE2KiCE7iR1DBLM
| ID | Campaign Name | Knowledge Base | Reply Examples |
|---|---|---|---|
| abc123 | Dental Outreach | [context...] | [examples...] |