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

Opening Problem Statement

Meet Sarah, a Telegram group admin and small business owner who wants to provide personalized AI assistance to her community. Every day, she spends hours answering repetitive questions, remembering preferences, and trying to keep context alive in chat. Worse, she struggles to manage different types of inputs like voice notes and images through Telegram, and she worries about losing past chat insights because her bot just resets memory after each session.

This wastes Sarah about 3 hours daily that could be better spent on her business, leads to frustrated users because the bot feels impersonal, and risks loss of valuable user-specific data over time.

If only there was a way to automate meaningful AI conversations on Telegram that remembered past interactions, understood user context, and handled multiple input types seamlessly.

What This Automation Does

This n8n workflow combines Telegram, DeepSeek AI models, and Google Docs to create a powerful personalized chatbot with long-term memory capabilities.

  • Automatically receives Telegram messages through a webhook for real-time updates.
  • Validates the sender’s Telegram user by matching first name, last name, and ID.
  • Routes messages based on content type (text, voice, image) to appropriate processing.
  • Uses the DeepSeek AI Agent node to process text messages conversationally, with personalized interaction based on user context.
  • Retrieves and saves long-term memories in Google Docs, allowing the bot to remember past conversations and preferences over time.
  • Sends AI-generated responses back to the Telegram chat, maintaining a natural and engaging user experience.

This saves hours of manual responding, reduces repetitive answers, and ensures a context-aware, personalized AI assistant on Telegram.

Prerequisites ⚙️

  • n8n account with workflow activation permissions.
  • Telegram Bot API access and credentials for your bot.
  • Google Docs account and OAuth2 credentials set up in n8n.
  • DeepSeek API key credentials integrated in n8n for AI processing.
  • HTTPS-accessible endpoint or self-hosted n8n instance for webhook reception.
    (Self-hosting option recommended for reliability, see self-hosting with Hostinger).

Step-by-Step Guide

1. Set Up the Telegram Webhook Listener

Navigate to n8n and create a new workflow. Add the Webhook node and configure it:

  • Click Add Node → Search and select Webhook (n8n-nodes-base.webhook).
  • Set HTTP Method to POST and Path to wbot (or your preferred webhook path).
  • Note the webhook URL generated by n8n; you will register this URL with Telegram bot’s setWebhook method.

Verify your webhook with Telegram by visiting:
https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook?url=YOUR_WEBHOOK_URL

You should see a JSON confirming success:

{
  "ok": true,
  "result": true
}

Common Mistake: Forgetting to use HTTPS URL or incorrect bot token will cause webhook registration to fail.

2. Validate Telegram User Data

Add the Set node (n8n-nodes-base.set) named “Validation” and enter your expected user’s first name, last name, and ID exactly as known.

Then add an If node (n8n-nodes-base.if) called “Check User & Chat ID” that compares incoming Telegram message sender’s first name, last name, and ID with your stored values.

This ensures only authorized or known users proceed, sending unauthorized users an error message.

Common Mistake: Ensure case sensitivity matches actual Telegram usernames; mismatches block valid users.

3. Route Messages by Type

Use a Switch node (n8n-nodes-base.switch) named “Message Router” to filter messages by type: text, voice notes, images, or extras.

Each output path handles a different type. For this example, the workflow mainly processes text messages with an AI agent, while other types can be extended with custom nodes.

Common Mistake: Not accounting for all possible message types may cause some inputs to be ignored.

4. Process Text Messages with DeepSeek AI Agent

Add the LangChain AI Agent node (@n8n/n8n-nodes-langchain.agent) and connect it to the text output of the Message Router.

Configure it with:

  • Prompt including system messages directing the agent to provide friendly, context-aware responses.
  • Dynamic input text from the Telegram message body.
  • Tool usage enabled for saving long-term memories.

This node uses DeepSeek models (deepseek-chat and deepseek-reasoner) for advanced reasoning and personalized responses.

5. Retrieve Long-Term Memories from Google Docs

Use a Google Docs node (n8n-nodes-base.googleDocs) configured to read a specific document URL where long-term user memories are stored.

Merge retrieved memories back into the flow so the AI Agent can refer to past conversations and context.

Common Mistake: Using an incorrect or inaccessible document URL will block memory retrieval causing context loss.

6. Save New Long-Term Memories

Connect the AI Agent node output to a Google Docs Tool node (n8n-nodes-base.googleDocsTool) configured to append summarized user information or context updates to the same Google Docs document.

This enables the chatbot to gradually learn and remember important details over time, preserving continuity.

7. Send AI Response Back to Telegram

Finally, use the Telegram node (n8n-nodes-base.telegram) to send the AI-generated response back to the user in the original chat ID.

Enable HTML formatting for rich messages, disable appended attribution, and test with real Telegram conversations.

8. Handle Unauthorized and Error Messages

Add additional Telegram nodes configured for error responses if unknown users send messages or in case the AI agent fails.

These nodes send friendly error messages without exposing internal details.

Customizations ✏️

  • Customize User Validation: In the “Validation” set node, modify the stored user details to handle multiple users by expanding the logic in the “Check User & Chat ID” node.
  • Add Voice Note Processing: Extend the “Message Router” node to connect voice messages to a speech-to-text node for transcription, then send text to the AI Agent.
  • Change Memory Storage: Swap Google Docs nodes with a database node like Airtable or MongoDB for scalable long-term memory management.
  • Personalized AI Prompt: Adjust the system message in the AI Agent node to include more personalized instructions or company-specific jargon.
  • Enable Image Processing: Add an image recognition API node to handle photo messages routed by the “Message Router” node.

Troubleshooting 🔧

Problem: “Webhook not receiving Telegram messages”

Cause: Webhook URL not properly registered or HTTPS issues.

Solution: Double-check the HTTPS webhook URL in Telegram Bot setup; ensure your n8n instance is publicly accessible over HTTPS.

Problem: “User validation failing consistently”

Cause: Case mismatches or incorrect user data in validation node.

Solution: Verify exact Telegram sender.first_name, last_name, and ID, and ensure case sensitivity matches in the “Check User & Chat ID” node conditions.

Problem: “Memory not retrieved or saved correctly”

Cause: Incorrect Google Docs document URL or insufficient permissions.

Solution: Confirm document URL is correct and the OAuth2 credentials have write/read access to the document.

Pre-Production Checklist ✅

  • Verify Telegram bot webhook registration successfully returns JSON status OK.
  • Test message flow with valid and invalid user inputs through the “Check User & Chat ID” node.
  • Confirm the “Message Router” routes text messages correctly to the AI Agent.
  • Perform read and write tests on the Google Docs used for memories.
  • Simulate AI Agent handling and Telegram responses end-to-end before publishing.

Deployment Guide

Activate your workflow in n8n by toggling the active status. Monitor the execution via n8n’s built-in execution tracking for errors or drop-offs.

Ensure your Telegram bot’s webhook URL remains valid and reachable to avoid missed messages.

Consider setting automated alerts in n8n for failures or add additional logging nodes for production monitoring.

FAQs

  • Can I use other AI models instead of DeepSeek?
    Yes, the workflow structure supports other OpenAI-compatible models by adjusting credentials and model names.
  • Does this consume API credits rapidly?
    The usage depends on message volume and AI response length; monitor your DeepSeek API quota accordingly.
  • Is my data safe in Google Docs?
    Google Docs is secured with OAuth2 authentication and encrypted storage; protect access with strong credentials.
  • Can this handle large Telegram groups?
    Yes, but ensure your n8n and API quotas scale accordingly.

Conclusion

You’ve just built a personalized AI Telegram bot using DeepSeek with long-term memory via Google Docs, powered by n8n automation. You saved hours of repetitive chat management and improved user engagement with contextual AI responses.

Next, explore adding voice-to-text transcription, richer multimedia handling, or integrating more complex workflows with CRM systems for complete automation.

Keep experimenting and making AI work smarter for you!

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 in n8n

A complete beginner guide to building an AI-powered 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