What this workflow does
This workflow helps a Thai language Line chatbot remember past conversations using Google Sheets. It solves the problem of the chatbot forgetting earlier chats and giving repeated replies. The chatbot fetches, updates, and stores chat history to create better, polite replies with AI assistance.
The result is a smoother, more personal chat experience that saves hours of manual work for chat managers.
Who should use this workflow
This is for chat managers and small businesses who use Line Official Accounts to talk with customers in Thai. It works well for shops with many daily inquiries needing quick and polite replies.
Users who want to keep dialogue history simple in Google Sheets without complex databases will benefit most.
Tools and services used
- Line Official API: Receives and sends chat messages.
- Google Sheets: Stores and retrieves chat history per user.
- Google Gemini AI (Google Palm API): Generates chatbot replies based on conversation context.
- n8n Automation Platform: Runs the workflow connecting Line, Sheets, and AI.
How this workflow works (Inputs → Process → Output)
Inputs
- Incoming Line chat messages including user ID, user message text, and reply token.
Processing Steps
- Webhook node catches messages from Line.
- Edit Fields node extracts user ID, reply token, and message text for clean use.
- Get History Google Sheets node fetches past chat history for that user ID.
- Prepare Prompt node builds a new text prompt; it joins previous chat history with the new message and instructs the AI to answer politely as a chatbot named “ลลิตา” in Thai language.
- AI Agent node sends this prompt to Google Gemini AI and gets the AI reply.
- Split History node uses JavaScript to add latest user and bot messages to history and splits old chat logs into archive parts if too large.
- Save History Google Sheets node updates the sheet with the new chat history per user.
- HTTP Request node replies to the Line user through the Line Messaging API with the AI-generated answer.
Outputs
- Personalized, polite AI replies sent back to the user on Line.
- Updated chat history stored safely in Google Sheets for next conversations.
Beginner step-by-step: How to use this workflow in n8n
Step 1: Import the workflow
- Click the Download button on this page to get the workflow file.
- Open the n8n editor where you want to use it.
- Choose Import from File option and upload the downloaded file.
Step 2: Configure credentials and variables
- Set up your Line channel access token and set it in the HTTP Request node headers.
- Connect your Google account with OAuth credentials in the Google Sheets nodes.
- Add your Google Palm API key to the AI Agent node credentials.
- Check and update your Google Sheets columns names (UserID, History, History_Archive_1-4) match the sheet you use.
- Adjust the webhook
pathin the Webhook node to match your public endpoint URL.
Step 3: Test the workflow
- Send a test message from your Line Official Account to the chatbot.
- Watch the Webhook node trigger in n8n.
- Confirm the AI replies appear properly in Line chat.
Step 4: Activate the workflow
- Turn the workflow ON inside n8n to run continuously.
- Make sure your n8n webhook URL is public and reachable by Line servers.
- If using self-host n8n, confirm server uptime for steady operation.
Customization ideas
- Edit the system message inside the AI Agent node to change chatbot style or tone.
- Add more archive columns in Google Sheets and extend the Split History node JavaScript to store longer chats.
- Change webhook
pathfor using the workflow with other Line accounts. - Replace Google Gemini AI model with another AI if needed, by changing the AI Agent node settings.
- Adapt prompt to support multi-language chats based on user data.
Handling errors and common problems
- Webhook not triggered: Check webhook URL matches Line developer settings and is public.
- Empty AI reply or API errors: Confirm Google Palm API keys and prompt format are correct.
- Google Sheets update fails: Verify UserID values match and appendOrUpdate operation is correct.
- 401 error from Line API: Renew and use correct Line channel access token in HTTP headers.
Summary of benefits and outcomes
✓ Saves hours by automating chat memory management.
✓ Gives polite, context-aware AI replies in Thai.
✓ Stores conversation history cleanly in Google Sheets.
✓ Works directly with Line Official Accounts and Google AI.
✓ Easy to configure and extend inside n8n.
