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
- Open your n8n instance
- Create a new workflow
- Add a Webhook node as the trigger
- Set method to POST
- Copy the Webhook URL (looks like
https://your-n8n.example.com/webhook/abc123)
Step 2: Configure Your Agent
- Go to AI Chat > Your Agent > Edit
- Under Provider Mode, select Webhook (BYOW)
- Paste your n8n webhook URL
- (Optional) Add an auth token for security
- 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:
- Webhook – Receives chat messages
- IF – Check if message contains email or phone
- Google Sheets – Append row with contact info, timestamp, and conversation summary
- 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:
- Webhook – Receives chat messages
- IF – Check for support keywords ("issue", "problem", "broken", "help")
- Zendesk – Create ticket with conversation transcript
- 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:
- Webhook – Receives chat messages
- IF – Check for keywords ("pricing", "competitor", "cancel", "enterprise")
- Slack – Send message to #sales-alerts channel
- OpenAI – Generate response using ChatGPT
- 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:
- Webhook – Receives chat with email in metadata
- HubSpot – Search contacts by email
- IF – Check if contact exists
- Set – Prepare context with HubSpot data (name, company, deal stage)
- OpenAI – Generate personalized response
- 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:
- Webhook – Receives messages
- Function – Parse intent (inquire, select date, confirm)
- Google Calendar – Check availability
- IF – Branch based on intent
- Google Calendar – Create event when confirmed
- 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-Tokenheader validation in your webhook - Validate incoming requests – Check
agentKeymatches 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
- Verify webhook URL is correct in agent settings
- Check n8n workflow is active (toggle in workflow editor)
- Look at n8n execution log for errors
- 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
- Check which node is taking longest in execution details
- Add caching for repeated API calls
- Consider async processing for non-critical steps
- Upgrade n8n hosting if needed
Inconsistent Responses
- Review OpenAI/Claude node settings (temperature, max tokens)
- Check for race conditions in parallel branches
- Validate data transformations in Set nodes
- Test with identical inputs to reproduce
Resources
- n8n Documentation: docs.n8n.io
- n8n Templates: n8n.io/workflows (search "chatbot" or "webhook")
- Community Workflows: Share your workflows in our Discord
- Support: support@demeterics.com for Demeterics-specific questions
What's Next?
- Agent Templates – Pre-built prompts for common use cases
- AI Chat Widget – Complete widget setup guide
- API Reference – Direct API integration for custom apps