TranscendCode

Embed Persona-Based Chatbots on Any Website Using n8n + DeepSeek API

Bryce Mc Williams
#n8n#chatbot#deepseek#ai#embed#security#workflow#automation

Why Persona-Based Chatbots?

Traditional chatbots feel generic. Persona-based chatbots have distinct characters—helpful support agents, quirky marketing bots, knowledgeable technical experts—that engage users better and create memorable interactions.

I built a system using n8n + DeepSeek API that lets you create these personality-driven chatbots and embed them on any website. The best part? Built-in security guards against hackers, spam, and prompt injection using word filters, phrase detection, and bulletproof system prompts.

This workflow gives you production-ready chatbots for €0.02 per 1,000 conversations.

What You’ll Build

A complete chatbot system with:

  1. Persona system: Different characters with unique voices and knowledge
  2. Embeddable widget: Copy-paste HTML for any website
  3. DeepSeek API integration: Cost-effective, high-quality responses
  4. Security layers: Word filters, jailbreak detection, prompt guards
  5. n8n workflow: Handles conversations, memory, and routing
  6. Rate limiting: Prevents abuse and manages API costs

Prerequisites

Step 1: Set Up DeepSeek API

DeepSeek offers excellent performance at low cost (~$0.14 per 1M input tokens).

  1. Sign up at platform.deepseek.com
  2. Generate API key
  3. Test with curl to verify it works

Step 2: Create Personas

Define your chatbot characters in a JSON config. Each persona has:

{
  "name": "Tech Support Andy",
  "description": "Friendly technical support agent",
  "system_prompt": "You are Tech Support Andy, a friendly technical support agent. Explain complex concepts simply. Be helpful and patient.",
  "knowledge": ["AWS services", "Docker", "Godot game development"],
  "allowed_domains": ["buildcodex.com"],
  "max_tokens": 1500
}

Create multiple personas:

Step 3: n8n Workflow Architecture

The workflow processes these steps:

[Webhook Trigger] → [Security Filter] → [Persona Router] → [DeepSeek API] → [Response Formatter] → [Webhook Response]

Node 1: Webhook Trigger

Receives POST requests from embedded widget:

Node 2: Security Filter (Critical!)

This multi-layered filter protects against abuse:

1. Word/Phrase Blacklist

IF message contains ["free money", "viagra", "casino", "pills"]:
  RETURN "Sorry, I can't help with that."

2. Jailbreak Detection

IF message contains ["ignore previous instructions", "you are now"]:
  RETURN "Nice try! I'm here to help with legitimate questions only."

3. Rate Limiting

IF requests > 10 per minute per IP:
  RETURN "You're sending requests too quickly."

4. Domain Whitelist

IF referrer NOT IN allowed_domains:
  RETURN "This chatbot is only available on authorized websites."

5. Length Limits

IF message.length > 2000 characters:
  RETURN "Message too long."

Node 3: Persona Router

Loads the correct persona configuration and retrieves conversation history.

Node 4: DeepSeek API Call

Sends to DeepSeek with strong system prompt:

messages = [
  {"role": "system", "content": system_prompt},
  ...conversation_history,
  {"role": "user", "content": message}
]

Strong system prompt template:

You are {persona.name}: {persona.description}

IMPORTANT SECURITY RULES (NEVER BREAK):
1. Stay in character. Never reveal you're an AI or break role.
2. Only discuss topics in {persona.knowledge}
3. Never provide harmful, illegal, or unethical advice
4. If asked about disallowed topics, politely redirect
5. Always be {persona.tone}

Node 5: Response Formatter

Processes DeepSeek response before returning:

  1. Trim length to fit UI constraints
  2. Sanitize output
  3. Add persona signature
  4. Store conversation for context
  5. Rate limit tracking update

Node 6: Webhook Response

Returns JSON to the widget.

Step 4: Embeddable Widget

Create an HTML widget users copy-paste into their websites:

<div id="chatbot-container"></div>

<script>
  ChatWidget.init({
    container: '#chatbot-container',
    webhookUrl: 'https://your-n8n-instance.onrender.com/webhook/chat',
    persona: 'Tech Support Andy',
    title: 'Ask Tech Support Andy',
    welcomeMessage: 'Hi! What can I help you with?',
    theme: 'dark'
  });
</script>

Widget features:

Step 5: Security Implementation

Your focus on security makes this production-ready.

Word/Phrase Filters

Blacklist examples:

const BLACKLIST = [
  'free money', 'viagra', 'casino', 'pills', 
  'click here', 'win lottery',
  'ignore previous', 'system prompt', 'jailbreak'
];

Case-insensitive matching with fuzzy matching for variants.

Jailbreak Protection

Layer 1: Pattern matching (fast):

if (message.match(/ignore.*instructions|you are now/i)) {
  return 'Nice try!';
}

Layer 2: LLM safety check (backup): Send suspicious messages to DeepSeek’s safety model.

Rate Limiting

Per chat_id: 10 messages/minute Per IP: 50 messages/hour Global: 1000 messages/hour per n8n instance

Domain Restrictions

ALLOWED_DOMAINS = ['buildcodex.com', 'your-site.com'];

if (!message.referrer.includes(ALLOWED_DOMAINS)) {
  return 'Chatbot only available on authorized websites.';
}

Step 6: Deploy the Workflow

  1. Import to your n8n instance
  2. Set environment variables
  3. Test each node individually
  4. Deploy widget script to your public folder
  5. Embed on websites using the HTML snippet

Cost Breakdown

DeepSeek API:

n8n hosting: €0 (your Render setup) Total: €0.02 per 1,000 conversations

Persona Examples

Tech Support Andy:

system_prompt: "You are Tech Support Andy... explain complex concepts simply..."
knowledge: ["AWS", "Docker", "Godot"]
max_tokens: 1200

Marketing Mia:

system_prompt: "You are Marketing Mia... enthusiastic product promoter..."
knowledge: ["SaaS features", "pricing"]
max_tokens: 800

Real-World Usage Examples

Customer support: Tech Support Andy on your SaaS documentation site Lead qualification: Marketing Mia on landing pages Knowledge base: FAQ Fiona on help centers

Limitations and Improvements

Current limitations:

Easy improvements:

Security Checklist

Before deploying publicly:

Deploy Your Chatbot

  1. Copy the workflow JSON to your n8n instance
  2. Set your DeepSeek API key
  3. Customize personas and security rules
  4. Deploy the widget script
  5. Embed on websites with 5 lines of HTML

That’s it—you now have persona-based AI chatbots that are secure, cost-effective, and embeddable anywhere.

Now go embed intelligent, personality-driven chatbots on your websites!

← Back to Blog