Skip to main content

Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets

Workflow preview

Workflow preview
100%
Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets preview
Open on n8n.io

Important notice

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

1. Workflow Overview

How It Works This workflow creates an AI powered Telegram chatbot with session management , allowing users to: Start new conversations ( ). Check current sessions ( ). Resume past sessions ( ). Get...

Best for

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

Tools used

@n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.memorybufferwindow, n8n-nodes-base.telegramtrigger, n8n-nodes-base.switch, n8n-nodes-base.googlesheets, n8n-nodes-base.telegram, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.chainsummarization

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets
Workflow name
Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets

How It Works

This workflow creates an AI-powered Telegram chatbot with session management, allowing users to:

  • Start new conversations (/new).
  • Check current sessions (/current).
  • Resume past sessions (/resume).
  • Get summaries (/summary).
  • Ask questions (/question).

Key Components:

  • Session Management:
    • Uses Google Sheets to track active/expired sessions (storing SESSION IDs and STATE).
    • /new creates a session; /resume reactivates past ones.
  • AI Processing:
    • OpenAI GPT-4 generates responses with contextual memory (via Simple Memory node).
    • Summarization: Condenses past conversations when requested.
  • Data Logging:
    • All interactions (prompts/responses) are saved to Google Sheets for audit and retrieval.
  • User Interaction:
    • Telegram commands trigger specific actions (e.g., /question [query] fetches answers from session history).

Main Advantages

1. Multi-session Handling
Each user can create, manage, and switch between multiple sessions independently, perfect for organizing different conversations without confusion.

2. Persistent Memory
Conversations are stored in Google Sheets, ensuring that chat history and session states are preserved even if the server or n8n instance restarts.

3. Commands for Full Control
With intuitive commands like /new, /current, /resume, /summary, and /question, users can manage sessions easily without needing a web interface.

4. Smart Summarization and Q&A
Thanks to OpenAI models, the workflow can summarize entire conversations or answer specific questions about past discussions, saving time and improving the chatbot’s usability.

5. Easy Setup and Scalability
By using Google Sheets instead of a database, the workflow is easy to clone, modify, and deploy — ideal for quick prototyping or lightweight production uses.

6. Modular and Extensible
Each logical block (new session, get current session, resume, summarize, ask question) is modular, making it easy to extend the workflow with additional features like analytics, personalized greetings, or integrations with CRM systems.


Setup Steps

Prerequisites:
  • Telegram Bot Token: Create via BotFather.
  • Google Sheets:
    • Duplicate this template.
    • Two sheets: Session (active/inactive sessions) and Database (chat logs).
  • OpenAI API Key: For GPT-4 responses.
Configuration:
  1. Telegram Integration:

    • Add your bot token to the Telegram Trigger and Telegram Send nodes.
  2. Google Sheets Setup:

    • Authenticate the Google Sheets nodes with OAuth.
    • Ensure sheet names (Session, Database) and column mappings match the template.
  3. OpenAI & Memory:

    • Add your API key to the OpenAI Chat Model nodes.
    • Adjust contextWindowLength in the Simple Memory node for conversation history length.
  4. Testing:

    • Use Telegram commands to test:
      • /new: Starts a session.
      • /question [query]: Tests AI responses.
      • /summary: Checks summarization.
  5. Deployment:

    • Activate the workflow; the bot will respond to Telegram messages in real-time.

Need help customizing?

Contact me for consulting and support or add me on Linkedin.

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 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 2 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 3 - Get message

Type / Role
n8n-nodes-base.telegramTrigger - telegramTrigger
Config choices
Version 1.2

Block 4 - Command or text?

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 5 - Get session

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

Block 6 - Disable previous session

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

Block 7 - Set new session

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

Block 8 - Session activated

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 9 - Send response

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 10 - Update database

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

Block 11 - Sticky Note

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

Block 12 - Summarization Chain

Type / Role
@n8n/n8n-nodes-langchain.chainSummarization - chainSummarization
Config choices
Version 2

Block 13 - OpenAI Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 14 - OpenAI Chat Model2

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 15 - Basic LLM Chain

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.6

Block 16 - Get message1

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

Block 17 - Set to expire

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

Block 18 - Exist?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 19 - OK

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 20 - KO

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 21 - Trim resume

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

Block 22 - Get session1

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

Block 23 - Prompt + Resume

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

Block 24 - Send summary

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Showing the first 24 of 38 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets
Complexity advanced
Nodes 38
Categories Support Chatbot, AI Chatbot
Author Davide
Published 30 Apr 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3798/3798.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 Create a session-based Telegram chatbot with GPT-4o-mini and Google Sheets do?

How It Works This workflow creates an AI powered Telegram chatbot with session management , allowing users to: Start new conversations ( ). Check current sessions ( ). Resume past sessions ( ). Get...

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.