Skip to main content

Line chatbot with Google Sheets memory and Gemini AI

Workflow preview

Workflow preview
100%
Line chatbot with Google Sheets memory and Gemini AI preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Main Use Case This workflow enables automated, AI assisted replies to users messaging a LINE Official Account, while storing and referencing chat history from Google Sheets to maintain context. Ide...

Best for

  • Support Chatbot automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.webhook, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatgooglegemini, n8n-nodes-base.set, n8n-nodes-base.httprequest, n8n-nodes-base.googlesheets, n8n-nodes-base.stickynote, n8n-nodes-base.code

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Jakkrapat Ampring.

Original n8n.io source

1.1 Workflow description

Title
Line chatbot with Google Sheets memory and Gemini AI
Workflow name
Line chatbot with Google Sheets memory and Gemini AI

Main Use Case

This workflow enables automated, AI-assisted replies to users messaging a LINE Official Account, while storing and referencing chat history from Google Sheets to maintain context. Ideal for businesses or support teams that want to provide smart, personalized customer interactions using AI with memory.

How It Works (Step-by-Step)

  1. Connect to LINE Official Account's API
  • A Webhook listens for incoming messages from users on LINE.
  • When a message is received, it triggers the workflow.
  1. Prepare the Data
  • An Edit Fields module structures incoming data (e.g. extracts user ID, message content).
  • This ensures data is clean and usable downstream.
  1. Retrieve Chat History
  • The user’s previous conversations are fetched from a Google Sheet.
  • This ensures the AI has memory and can continue conversations contextually.
  1. Prepare Prompt
  • The retrieved chat history is combined with the new message to form a complete prompt for the AI.
  • Example format: “User previously said X. Now they said Y. How should we respond?”
  1. AI Agent: Google Gemini
  • The formatted prompt is passed to an AI Agent (Google Gemini Chat Model).
  • The AI generates a response based on the message + history.
  • Tools used: Chat ModeMemory, ToolOutputParser for accurate replies.
  1. Split & Clean History
  • The conversation history is split into smaller chunks for cleaning and storage.
  • This ensures the Google Sheet remains readable and manageable over time.
  1. Save Chat History
  • The cleaned new message and AI reply are saved to Google Sheets.
  • This updates the chat history for future context.
  1. Send Reply to LINE
  • The AI-generated reply is sent back to the user via a POST HTTP Request to the LINE Messaging API.

How to Set Up

Prerequisites:

  • LINE Official Account
  • Google Sheet to store chat history
  • Google Gemini API or AI agent with context memory
  • Automation platform (e.g., n8n, as this seems visually similar)

Step-by-Step:

  1. Create a Webhook on LINE:
  • Set the webhook URL to your automation service.
  • Enable webhook events.
  1. Design Your Google Sheet:
  • Create a sheet with columns: User ID, Timestamp, Message, AI Reply.
  1. Set Up Modules in Automation Platform:
  • Webhook: receives user messages.
  • Edit Fields: extract user ID and message.
  • Google Sheets Read: fetch message history.
  • Prompt Composer: format prompt using past history + new message.
  • AI Agent: connect to Google Gemini for smart replies.
  • Split & Clean: clean and chunk history if needed.
  • Google Sheets Write: save the updated conversation.
  • HTTP Request: send reply to LINE via Messaging API.
  1. Test Your Workflow:
  • Send a message from LINE.
  • Watch the full loop: receive → process → AI → store → reply.
  1. Deploy & Monitor:
  • Ensure error handling is in place (e.g., for blank messages or failed API calls).
  • Regularly check your Google Sheets for storage limits. (If limits reached, you can increase the history row.)

📦 Benefits

  • Maintains context in conversations
  • Personalized, AI-driven responses
  • Easy history tracking via Google Sheets
  • Fully automated and scalable

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2

Block 2 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 3 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 4 - Edit Fields

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 5 - HTTP Request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 6 - Get History

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 7 - Prepare Prompt

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 8 - Save History

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 9 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Split History

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 16 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Line chatbot with Google Sheets memory and Gemini AI
Complexity advanced
Nodes 17
Categories Support Chatbot, AI Chatbot
Author Jakkrapat Ampring
Published 18 Apr 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3600/3600.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Line chatbot with Google Sheets memory and Gemini AI do?

Main Use Case This workflow enables automated, AI assisted replies to users messaging a LINE Official Account, while storing and referencing chat history from Google Sheets to maintain context. Ide...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Support Chatbot, AI Chatbot use case.