n8n Workflows

Learn how to integrate Demeterics into your workflows with step-by-step guides and API examples.

n8n Workflows

Extend your AI chat widget with powerful automation using n8n workflows. Connect chat conversations to your CRM, ticketing system, email marketing, and more.


What is n8n?

n8n is an open-source workflow automation tool that connects your apps and services. Think Zapier or Make, but self-hosted and infinitely customizable.

With Demeterics + n8n, you can:

  • Capture leads from chat and send to HubSpot, Salesforce, or Google Sheets
  • Create tickets in Zendesk, Freshdesk, or Jira from support conversations
  • Send notifications via Slack, Teams, or email when keywords appear
  • Enrich conversations with data from your CRM before responding
  • Trigger follow-ups based on conversation outcomes

Setting Up the Webhook Connection

Step 1: Create a Webhook in n8n

  1. Open your n8n instance
  2. Create a new workflow
  3. Add a Webhook node as the trigger
  4. Set method to POST
  5. Copy the Webhook URL (looks like https://your-n8n.example.com/webhook/abc123)

Step 2: Configure Your Agent

  1. Go to AI Chat > Your Agent > Edit
  2. Under Provider Mode, select Webhook (BYOW)
  3. Paste your n8n webhook URL
  4. (Optional) Add an auth token for security
  5. Click Save

Step 3: Handle Incoming Requests

Your n8n workflow will receive POST requests with this payload:

{
  "messages": [
    {"role": "user", "content": "Hello, I need help with my order"},
    {"role": "assistant", "content": "I'd be happy to help! Could you provide your order number?"},
    {"role": "user", "content": "Order #12345"}
  ],
  "agentKey": "DEM-XXXXXXXXXXXX",
  "promptName": "default",
  "metadata": {
    "domain": "example.com",
    "path": "/support",
    "referrer": "https://google.com",
    "userAgent": "Mozilla/5.0..."
  }
}

Step 4: Return a Response

Your workflow must return a JSON response:

{
  "response": "I found your order #12345. It shipped yesterday and should arrive by Friday. Is there anything else I can help with?"
}

Example Workflows

Lead Capture to Google Sheets

Use case: Collect contact info from sales conversations and log to a spreadsheet.

Workflow:

  1. Webhook – Receives chat messages
  2. IF – Check if message contains email or phone
  3. Google Sheets – Append row with contact info, timestamp, and conversation summary
  4. Set – Prepare response acknowledging receipt

n8n nodes:

Webhook → IF (contains email) → Google Sheets (Append) → Set → Respond to Webhook

Response template:

{
  "response": "Thanks! I've noted your contact info. Our team will reach out within 24 hours."
}

Support Ticket Creation (Zendesk)

Use case: Create a Zendesk ticket when visitors report issues.

Workflow:

  1. Webhook – Receives chat messages
  2. IF – Check for support keywords ("issue", "problem", "broken", "help")
  3. Zendesk – Create ticket with conversation transcript
  4. Set – Prepare response with ticket number

n8n nodes:

Webhook → IF (support keywords) → Zendesk (Create Ticket) → Set → Respond to Webhook

Response template:

{
  "response": "I've created support ticket #{{$node.Zendesk.json.id}}. Our team will respond within 2 hours."
}

Slack Notification on Keywords

Use case: Alert your team in Slack when visitors mention competitors or high-intent keywords.

Workflow:

  1. Webhook – Receives chat messages
  2. IF – Check for keywords ("pricing", "competitor", "cancel", "enterprise")
  3. Slack – Send message to #sales-alerts channel
  4. OpenAI – Generate response using ChatGPT
  5. Respond to Webhook – Return AI response

n8n nodes:

Webhook → IF (keywords) → Slack (Post Message) → OpenAI (Chat) → Respond to Webhook

CRM Enrichment (HubSpot)

Use case: Look up visitor in HubSpot and personalize the conversation.

Workflow:

  1. Webhook – Receives chat with email in metadata
  2. HubSpot – Search contacts by email
  3. IF – Check if contact exists
  4. Set – Prepare context with HubSpot data (name, company, deal stage)
  5. OpenAI – Generate personalized response
  6. Respond to Webhook – Return response

n8n nodes:

Webhook → HubSpot (Search) → IF (found) → Set (context) → OpenAI (Chat) → Respond to Webhook

Personalized prompt:

You are chatting with {{$node.HubSpot.json.firstname}} from {{$node.HubSpot.json.company}}.
They are currently in the "{{$node.HubSpot.json.deal_stage}}" stage.
Be helpful and reference their company name naturally.

Multi-Step Appointment Booking

Use case: Book appointments through conversational flow with calendar integration.

Workflow:

  1. Webhook – Receives messages
  2. Function – Parse intent (inquire, select date, confirm)
  3. Google Calendar – Check availability
  4. IF – Branch based on intent
  5. Google Calendar – Create event when confirmed
  6. Respond to Webhook – Return next step or confirmation

Conversation flow:

User: "I'd like to book a consultation"
Bot: "Great! I have availability on Tuesday 2pm, Wednesday 10am, or Friday 3pm. Which works best?"

User: "Tuesday at 2"
Bot: "Perfect! I've booked your consultation for Tuesday at 2pm. You'll receive a calendar invite shortly."

Best Practices

Security

  • Always use auth tokens – Add X-Demeterics-Token header validation in your webhook
  • Validate incoming requests – Check agentKey matches expected value
  • Rate limit your workflow – Prevent abuse by adding delays or limits

Performance

  • Keep workflows fast – Aim for <5 second response time
  • Use async for heavy operations – Log to CRM in parallel, don't block response
  • Cache API responses – Reduce external API calls where possible

Reliability

  • Handle errors gracefully – Return a fallback response if external APIs fail
  • Log everything – Use n8n's execution log for debugging
  • Set up alerts – Get notified when workflows fail

Testing

  • Use n8n's test webhook – Preview payloads before going live
  • Test edge cases – Empty messages, long conversations, special characters
  • Monitor response quality – Review transcripts to catch issues early

Debugging Tips

Workflow Not Triggering

  1. Verify webhook URL is correct in agent settings
  2. Check n8n workflow is active (toggle in workflow editor)
  3. Look at n8n execution log for errors
  4. Test webhook directly with curl:
curl -X POST https://your-n8n/webhook/abc123 \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"test"}]}'

Slow Responses

  1. Check which node is taking longest in execution details
  2. Add caching for repeated API calls
  3. Consider async processing for non-critical steps
  4. Upgrade n8n hosting if needed

Inconsistent Responses

  1. Review OpenAI/Claude node settings (temperature, max tokens)
  2. Check for race conditions in parallel branches
  3. Validate data transformations in Set nodes
  4. Test with identical inputs to reproduce

Resources


What's Next?