Code Webhook Automate Webhook – Business Process Automation | Complete n8n Webhook Guide (Intermediate)
This article provides a complete, practical walkthrough of the Code Webhook Automate Webhook n8n agent. It connects HTTP Request, Webhook across approximately 1 node(s). Expect a Intermediate setup in 15-45 minutes. One‑time purchase: €29.
What This Agent Does
This agent orchestrates a reliable automation between HTTP Request, Webhook, handling triggers, data enrichment, and delivery with guardrails for errors and rate limits.
It streamlines multi‑step processes that would otherwise require manual exports, spreadsheet cleanup, and repeated API requests. By centralizing logic in n8n, it reduces context switching, lowers error rates, and ensures consistent results across teams.
Typical outcomes include faster lead handoffs, automated notifications, accurate data synchronization, and better visibility via execution logs and optional Slack/Email alerts.
How It Works
The workflow uses standard n8n building blocks like Webhook or Schedule triggers, HTTP Request for API calls, and control nodes (IF, Merge, Set) to validate inputs, branch on conditions, and format outputs. Retries and timeouts improve resilience, while credentials keep secrets safe.
Third‑Party Integrations
- HTTP Request
- Webhook
Import and Use in n8n
- Open n8n and create a new workflow or collection.
- Choose Import from File or Paste JSON.
- Paste the JSON below, then click Import.
-
Show n8n JSON
**Title:** Building a Conversational Thai Line Chatbot with Memory Using n8n, Google Sheets, and Gemini AI **Meta Description:** Discover how to create an intelligent Thai-speaking chatbot named “ลลิตา” using Line’s Messaging API, Google Gemini, and Google Sheets as a memory store — all orchestrated within n8n’s visual automation platform. **Keywords:** n8n workflow, Line chatbot, Thai chatbot, AI chatbot memory, Google Gemini API, Google Sheets chatbot, conversational AI, LangChain, Google Palm, Thai AI assistant, chatbot history, LINE Messaging API, chatbot persistence, Google Sheets API, chatbot context memory --- # Creating a Personalized Thai Line Chatbot with Memory Using n8n In the evolving world of chatbots, users expect personalized, contextual conversations — as though they’re chatting with a close friend or dedicated assistant. To meet those expectations, developers need tools that enable not only intelligent interactions but also memory. Enter “ลลิตา”, a Thai-speaking AI assistant developed using n8n, Google Gemini, and Google Sheets. This intelligent chatbot, fully operable via Line’s Messaging API, is designed to remember past interactions and respond with cultural fluency and emotional context. In this article, we’ll explore how the components work together and why this setup is a smart choice for localized, persistent chatbot experiences in Thai. --- ## Overview of the Workflow The n8n workflow is aptly named: **(G) LineChatBot + Google Sheets (as a memory)** It seamlessly connects user input from a Line Official Account to an AI agent powered by Google Gemini. The responses are enriched with memory from past chats stored in Google Sheets, enabling deeper, contextual interaction over time — all within the Thai locale and language. Let’s walk through the architecture: ### 1. User Message Collection: Webhook Integration A webhook node listens for user input from the Line Messaging platform. Each incoming message sends a POST request to a designated webhook path (`/guitarpa`), delivering the sender’s message, reply token, and user ID. ### 2. Parsing and Preparation Next, the data is parsed via the “Edit Fields” node, where key values like the user ID, message content, and reply token are extracted. This parsed data gets passed to the rest of the workflow. ### 3. Chat History Retrieval: Google Sheets API Before generating a reply, the chatbot retrieves past interactions from Google Sheets. History is segmented across fields — `History`, `History_Archive_1` through `_4` — allowing for expandable memory without hitting Google Sheets’ cell limits. This creates a pseudo-database that tracks each user contextually using their unique user ID. ### 4. Prompt Construction with History The chatbot, embodied by “ลลิตา”, is designed to be polite, friendly, and Thai-language fluent. A new prompt is constructed dynamically by amalgamating recent chat history and the current user input. The output prompt might look something like this: ``` คุณคือลลิตา แชทบอทภาษาไทยที่สุภาพและเป็นมิตร ตอบตามบริบทของการสนทนา: [...Previous Chat History...] ผู้ใช้: สวัสดี ลลิตา วันนี้อากาศเป็นยังไงบ้าง? ลลิตา: ``` This approach helps the AI respond in a manner that feels consistent and context-aware — a key feature for emotionally intelligent chatbots. ### 5. AI Response Generation: Google Gemini via LangChain The constructed prompt is then sent to the Google Gemini language model (Gemini Flash v2.0). This communication is facilitated through LangChain’s integration into n8n. The system message sets parameters like chatbot name, tone, and timezone (Asia/Bangkok), ensuring regional consistency. ### 6. History Management: Memory that Grows After generating a response, the workflow logs the new user-bot exchange. To handle Google Sheets’ 50,000-character cell limit, a “Split History” custom JavaScript node distributes older portions of history into four archive buckets. The script ensures that the active `History` field remains short enough to prompt the AI efficiently, while older exchanges are preserved for context continuity. ### 7. Reply Delivery Back to Line Finally, the chatbot’s response is sent back to the user via a POST request to the Line Messaging API’s `reply` endpoint. The response string is sanitized and formatted to comply with JSON and Line’s rich response formatting rules. --- ## Why This Workflow is Powerful ✅ Context-Aware Interaction By maintaining historical user input, “ลลิตา” can provide answers that account for previous conversations — a huge leap in chatbot sophistication. ✅ Thai-Language Native Localizing both experience and tone for a Thai-speaking audience fosters trust, usability, and cultural alignment. ✅ Scalable Memory The dynamic archiving and prompt prep ensure interactions remain within character limits while still retaining up to 170,000 characters of historical memory across five fields. ✅ Low-Code Automation Thanks to n8n’s visual editor, this workflow is easy to maintain and extend without writing full back-end infrastructure. --- ## Third-Party APIs Used 1. **Line Messaging API** - For receiving and replying to user messages. - Endpoint: `https://api.line.me/v2/bot/message/reply` 2. **Google Sheets API (via OAuth2)** - For saving and retrieving personalized chat histories. - Enables persistence of state between chats. 3. **Google Gemini / Palm API (via LangChain)** - For generating AI-driven responses in natural Thai language. - Model used: `models/gemini-2.0-flash-001` 4. **LangChain for n8n** - Handles AI agent orchestration, prompt transformation, and language model communication. --- ## Final Thoughts If you’re building a personalized chatbot that needs historical memory, localization, and AI power — this n8n workflow is a gold standard. It pairs low-code automation logic with high-quality AI responses from Google and a robust messaging infrastructure via Line. "ลลิตา" isn’t just a chatbot; she’s a conversational partner with memory, manners, and a mission to help, one Thai SMS at a time. Whether you want to build a customer service bot, personal assistant, or educational tutor in Thai or any other language, this architecture gives you the tools to make it conversational and contextual.
- Set credentials for each API node (keys, OAuth) in Credentials.
- Run a test via Execute Workflow. Inspect Run Data, then adjust parameters.
- Enable the workflow to run on schedule, webhook, or triggers as configured.
Tips: keep secrets in credentials, add retries and timeouts on HTTP nodes, implement error notifications, and paginate large API fetches.
Validation: use IF/Code nodes to sanitize inputs and guard against empty payloads.
Why Automate This with AI Agents
AI‑assisted automations offload repetitive, error‑prone tasks to a predictable workflow. Instead of manual copy‑paste and ad‑hoc scripts, your team gets a governed pipeline with versioned state, auditability, and observable runs.
n8n’s node graph makes data flow transparent while AI‑powered enrichment (classification, extraction, summarization) boosts throughput and consistency. Teams reclaim time, reduce operational costs, and standardize best practices without sacrificing flexibility.
Compared to one‑off integrations, an AI agent is easier to extend: swap APIs, add filters, or bolt on notifications without rewriting everything. You get reliability, control, and a faster path from idea to production.
Best Practices
- Credentials: restrict scopes and rotate tokens regularly.
- Resilience: configure retries, timeouts, and backoff for API nodes.
- Data Quality: validate inputs; normalize fields early to reduce downstream branching.
- Performance: batch records and paginate for large datasets.
- Observability: add failure alerts (Email/Slack) and persistent logs for auditing.
- Security: avoid sensitive data in logs; use environment variables and n8n credentials.
FAQs
Can I swap integrations later? Yes. Replace or add nodes and re‑map fields without rebuilding the whole flow.
How do I monitor failures? Use Execution logs and add notifications on the Error Trigger path.
Does it scale? Use queues, batching, and sub‑workflows to split responsibilities and control load.
Is my data safe? Keep secrets in Credentials, restrict token scopes, and review access logs.