4.2 Workflow B: Drafting Documents

This workflow triggers when an agent needs to generate paperwork but doesn't want to log into DocuSign to click tiny checkboxes.

The Goal: The agent dictates the intent via email; Amy does the data entry.


1. The Trigger

  • Source: AgentMail Webhook.

  • Intent Classifier (OpenAI): The Router (Article 3.2) detects a "Drafting Request."

  • Example Input:

    "Amy, draft an Addendum. We are crediting the buyer $5,000 for roof repairs. Also, change the close date to Dec 1st."


2. The Logic: "The Dictionary"

DocuSign doesn't understand "Credit the buyer." It only understands Field IDs (e.g., text_ref_12).

We use n8n to translate Natural Language into API Payloads.

Step A: Identify the Form

  • Input: "Addendum"

  • Lookup: n8n searches our internal Form Dictionary.

  • Match: C.A.R. Form ADM (Addendum No. 1)

Step B: Map the Data

  • Input: "Credit buyer $5,000"

  • Lookup: Field Mapping for Form ADM.

  • Match: { "text_description": "Seller to credit Buyer $5,000 for roof repairs." }


3. The Execution Steps

Action A: Create the Draft (DocuSign API)

Amy creates the envelope but DOES NOT SEND IT.

  • API Call: POST /envelopes

  • Status: created (This means "Draft").

  • Composite Template: We pull the C.A.R. Form ADM template and inject the JSON data into the tab values.

Action B: The "Magic Link" (The Proof)

We need the agent to see what we built.

  • API Call: POST /envelopes/{id}/views/sender

  • Result: DocuSign returns a url. This link opens the envelope in "Editor Mode."

Action C: The Review Request

  • To: The Agent.

  • From: Amy.

  • Body:

    "I've drafted Addendum No. 1 for the roof credit ($5k) and the date change (Dec 1st).

    [Click here to review and edit]

    If it looks good, just reply 'APPROVED' and I will send it to the client for signatures."

Gemini_Generated_Image_3be98d3be98d3be9.png

4. Technical Logic (The n8n Flow)

Code snippet

graph TD
A[Agent Request: 'Draft Addendum'] -->|Webhook| B(n8n Router)
B -->|Intent & Data Extract| C{OpenAI Node}
C -->|Select Form Template| D[Form Dictionary]
D -->|Create Envelope (Draft)| E[DocuSign API]
E -->|Generate Edit Link| F[DocuSign API]
F -->|Send Review Email| G[AgentMail]
Gemini_Generated_Image_so630rso630rso63.png

Developer Implementation Notes 📝

  • The "Iterative" Loop: Agents often change their minds. If the agent replies "Actually, make it $6,000," the workflow must handle the update.

    • Logic: n8n detects the reply is part of an existing Drafting Thread $\rightarrow$ Calls PUT /envelopes/{id}/tabs to update the value $\rightarrow$ Sends a fresh confirmation.

  • Field Mapping: You will need to manually map the Top 5 Forms (RPA, ADM, RRR, SPQ, TDS) in a JSON config file inside n8n or Supabase. Don't try to map all 500 C.A.R. forms on Day 1.


Was this article helpful?
© 2025 DealTrail 3.0