Automate Telegram AI Chat with DeepSeek and n8n

This unique n8n workflow automates AI-powered conversations on Telegram using DeepSeek models, managing context with long-term memory stored in Google Docs. It solves personalized and context-aware chatbot challenges with Telegram integration.
telegram
agent
googleDocs
+10
Workflow Identifier: 2000
NODES in Use: if, telegram, stickyNote, webhook, set, switch, agent, merge, memoryBufferWindow, chatTrigger, googleDocsTool, googleDocs, lmChatOpenAi

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What This Automation Does

This workflow connects Telegram, DeepSeek AI, and Google Docs to create a chat bot that remembers user details and chats long term.
It solves the problem of answering repeated questions and losing chat memory.
The bot takes messages, understands user context, and replies using past conversation history.
This means less work writing replies and friendlier chats for users.

The workflow uses a Telegram webhook to get messages instantly and checks if the sender is a known user.
It sorts messages by type like text, voice, or images.
Text messages go to an AI node that talks using DeepSeek models and can use past memories stored in Google Docs.
The bot updates long-term memories after each talk and sends the reply back to Telegram.


Tools and Services Used

  • Telegram Bot API: Receives user messages.
  • n8n Webhook node: Catches Telegram messages in real-time.
  • Set node: Holds user info for validation.
  • If node: Checks user identity to allow or block message flow.
  • Switch node: Routes message types (text, voice, image).
  • LangChain AI Agent node (DeepSeek): Processes text with AI, understands context and responds.
  • Google Docs node: Reads stored past chat and user data.
  • Google Docs Tool node: Adds new memories to Google Docs.
  • Telegram node: Sends chat replies back to users.

Linking the self-host n8n option is good to run the webhook server safely with HTTPS.


Who Should Use This Workflow

This is for users running Telegram groups or small businesses who want an AI chat helper that:

  • Remembers past chats and user details.
  • Handles different input types (text, voice, image).
  • Reduces time spent answering similar questions.
  • Allows personalized AI replies without losing context.

The user does not need deep coding knowledge but should have some familiarity with n8n and bot credentials.


Input, Processing, and Output

Inputs

  • Telegram messages from users via webhook.
  • User details: first name, last name, and Telegram ID stored in a Set node.

Processing

  • Validate users to allow only known people.
  • Check message types to send each to the right handler.
  • For text messages, use AI to generate replies with context from long-term memories.
  • Read and write user memory data to Google Docs.

Output

  • Send AI-generated replies to the Telegram chat.
  • Send error messages to unknown users.

Beginner Step-by-Step: How To Use This Workflow in n8n

Step 1: Import the Workflow

  1. Click the Download button on this page to get the workflow file.
  2. Open n8n editor.
  3. Choose “Import from File” and select the downloaded file.

Step 2: Configure Credentials

  1. Add your Telegram Bot API credentials.
  2. Add Google Docs OAuth2 credentials.
  3. Set the DeepSeek API Key in the LangChain AI Agent node.

Step 3: Update User Details and IDs

  1. In the Set node named “Validation,” enter the known user’s first name, last name, and Telegram ID.
  2. Make sure the Google Docs document URL is correct in the Google Docs nodes.
  3. If needed, update Telegram chat IDs or other references.

Step 4: Test the Workflow

  1. Send a test message from the authorized Telegram user.
  2. Check if the bot replies with AI-generated text.
  3. Try sending a message from an unauthorized user and confirm error handling.

Step 5: Activate the Workflow

  1. Turn the workflow’s active toggle on.
  2. Monitor for any errors using the n8n execution panel.

Following these steps gets the bot running in production with context-aware replies.


Customization Ideas

  • Modify user validation to allow more users by changing the Set node and If node logic.
  • Add voice-to-text transcription nodes, connecting voice messages to text handlers.
  • Switch Google Docs memory storage to a database like Airtable or MongoDB for large scale.
  • Change the AI Agent’s system prompt to include company language or personality.
  • Integrate image recognition APIs to analyze pictures sent in chat.

Troubleshooting

Webhook Not Receiving Telegram Messages

This might happen if the webhook URL is not set with HTTPS or if Telegram rejects the URL.
Check the Webhook node URL and Telegram bot settings.

User Validation Keeps Failing

Make sure the user names and Telegram IDs exactly match the stored values.
Check case sensitivity carefully.

Memory Not Loading or Saving

Verify the Google Docs document URL is accessible and OAuth2 credentials have permission.
Check that the tokens are valid and the document is not moved or deleted.


Pre-Production Checklist

  • Confirm Telegram webhook registration returns { “ok”: true, “result”: true }.
  • Test messages from known and unknown users through the validation node.
  • Check message routing sends text properly to AI Agent.
  • Perform read and write tests on Google Docs memory.
  • Test full flow with AI reply and Telegram response.

Deployment Guide

Activate the workflow in n8n.
Watch executions for errors or message drops.

Keep the Telegram webhook URL public and HTTPS.
Set alerts in n8n if you want notifications about failures.

Consider self-host n8n for better control and uptime.


Summary

✓ Saves hours of manual answering in Telegram chats.
✓ Keeps chat context over long time using Google Docs.
✓ Provides personalized AI replies through DeepSeek models.
✓ Validates users to allow trusted conversations only.
✓ Handles multiple message types with flexible routing.

→ The user gets a ready-to-use AI assistant on Telegram that feels like a real helper, remembering past talks and preferences.


Frequently Asked Questions

Yes, other AI models that work with OpenAI APIs can replace DeepSeek by changing credentials and model names in the LangChain AI Agent node.
User data is stored securely using Google Docs with OAuth2 authentication and access control managed by Google.
Add the new users’ details in the Set node for validation and update the If node logic to allow their messages.
Check that the webhook URL uses HTTPS, is correctly registered in Telegram Bot settings, and n8n instance is publicly reachable.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free