Loading
Loading
n8n (pronounced "n-eight-n") is an open-source automation platform you can self-host. The name is short for "nodemation" โ automation built on Nodes.
# Run n8n with Docker
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
# Run in background
docker run -d \
--name n8n \
--restart unless-stopped \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
# Install n8n globally
npm install n8n -g
# Start n8n
n8n start
# Start with tunneling (for Webhook testing)
n8n start --tunnel
npx n8n
After starting, open: http://localhost:5678
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ n8n Interface โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Workflows โ Canvas (Work area) โ
โ โโโโโโโโโโโ โ โโโโโโโโ โ โโโโโโโโโโ โ
โ My Workflow โ โTriggerโ โ Action โ โ
โ Email Bot โ โโโโโโโโ โโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Credentials โ Node Panel โ
โ Executions โ Parameters & Settings โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Section | Function | |---------|----------| | Workflows | List all your workflows | | Canvas | Visual workflow building area | | Credentials | Encrypted API keys | | Executions | Log of all runs | | Node Panel | Library of available Nodes |
Now any Workflow can securely use this key!
# ู
ุญุงูุงุฉ n8n Webhook Server โ Python Simulation
import json
import time
import threading
import urllib.request
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse
from dataclasses import dataclass, field
from datetime import datetime
# โโโ Webhook Event โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
@dataclass
class WebhookEvent:
path: str
source: str
payload: dict
received_at: str = field(
default_factory=lambda: datetime.now().strftime("%H:%M:%S")
)
received_events: list[WebhookEvent] = []
# โโโ Webhook Server (ู
ุซู n8n Webhook Trigger Node) โโโโโโโ
class WebhookHandler(BaseHTTPRequestHandler):
"""ูุณุชูุจู ุงูุจูุงูุงุช ุงููุงุฑุฏุฉ ู
ุซู n8n Webhook Trigger"""
def do_POST(self):
content_len = int(self.headers.get("Content-Length", 0))
body = self.rfile.read(content_len)
try:
payload = json.loads(body)
except Exception:
payload = {"raw": body.decode()}
event = WebhookEvent(
path=urlparse(self.path).path,
source=self.headers.get("X-Source", "unknown"),
payload=payload,
)
received_events.append(event)
print(f"\n๐จ [{event.received_at}] Webhook: {event.path}")
print(f" ุงูู
ุตุฏุฑ: {event.source}")
print(f" ุงูุจูุงูุงุช: {json.dumps(event.payload, ensure_ascii=False)}")
# ุชูุฌูู ุญุณุจ ุงูู
ุณุงุฑ (ู
ุซู n8n Router)
if "email" in event.path:
subject = event.payload.get("subject", "")
is_urgent = any(w in subject for w in ["ุนุงุฌู", "urgent"])
print(f" ๐ง ุจุฑูุฏ {'๐ด ุนุงุฌู' if is_urgent else '๐ข ุนุงุฏู'}: {subject}")
elif "payment" in event.path:
amount = event.payload.get("amount", 0)
print(f" ๐ณ ุฏูุนุฉ: {amount} ุฑูุงู")
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
resp = {"status": "ok", "event_id": len(received_events)}
self.wfile.write(json.dumps(resp).encode())
def log_message(self, *args):
pass # ุฅุฎูุงุก ุณุฌูุงุช HTTP ุงูุงูุชุฑุงุถูุฉ
# โโโ ุชุดุบูู ุงูุณูุฑูุฑ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
server = HTTPServer(("localhost", 9100), WebhookHandler)
t = threading.Thread(target=server.serve_forever, daemon=True)
t.start()
print("๐ n8n Webhook Simulator: http://localhost:9100")
print(" ุฌุงูุฒ ูุงุณุชูุจุงู ุงูุฃุญุฏุงุซ...\n")
time.sleep(0.3)
# โโโ ู
ุญุงูุงุฉ ุฅุฑุณุงู Webhooks ู
ู ุชุทุจููุงุช ุฎุงุฑุฌูุฉ โโโโโโโโโโโโโ
def fire_webhook(path: str, data: dict, source: str) -> dict:
body = json.dumps(data).encode()
req = urllib.request.Request(
f"http://localhost:9100{path}",
data=body,
headers={"Content-Type": "application/json", "X-Source": source},
method="POST",
)
with urllib.request.urlopen(req) as r:
return json.loads(r.read())
# ุฃุญุฏุงุซ ุชุฌุฑูุจูุฉ
events = [
("/webhook/email", {"from": "client@co.com", "subject": "ู
ุดููุฉ ุนุงุฌูุฉ ูู ุงููุธุงู
"}, "Gmail"),
("/webhook/email", {"from": "news@daily.com", "subject": "ุงููุดุฑุฉ ุงูุฃุณุจูุนูุฉ"}, "Gmail"),
("/webhook/payment", {"amount": 499, "status": "completed", "plan": "Pro"}, "Stripe"),
("/webhook/email", {"from": "boss@co.com", "subject": "ุชูุฑูุฑ urgent ู
ุทููุจ ุงูุขู"}, "Outlook"),
]
for path, data, source in events:
result = fire_webhook(path, data, source)
print(f" โ
ุฑุฏ: {result}")
time.sleep(0.3)
server.shutdown()
print(f"\n๐ ุฅุฌู
ุงูู ุงูุฃุญุฏุงุซ ุงูู
ุณุชูู
ุฉ: {len(received_events)}")