Telegram Bot to Human Handoff Automation with n8n

This n8n workflow automates seamless Telegram bot-to-human handoffs by managing conversation states with Redis and AI agents. It reduces wait times and errors by ensuring structured customer onboarding and clear human transfer.
telegramTrigger
redis
switch
+11
Learn how to Build this Workflow with AI:
Workflow Identifier: 1149
NODES in Use: telegramTrigger, redis, switch, lmChatOpenAi, memoryRedisChat, informationExtractor, agent, toolWorkflow, telegram, code, if, executeWorkflow, executeWorkflowTrigger, memoryManager

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

Visit through Desktop for Best experience

1. The Challenge Sarah Faces Managing Customer Support on Telegram

Imagine Sarah, who runs a busy online retail store and receives dozens of customer inquiries every day via Telegram. Many customers first interact with an AI chatbot that tries to assist with common questions. However, when complex issues arise, Sarah needs to manually step in. The problem? Switching conversations smoothly between the AI chatbot and human agents has been chaotic and slow. Without a smart system, Sarah spends hours daily sorting who needs human help and which conversations the bot can handle, resulting in frustrated customers, wasted time, and lost revenue.

Manual handoffs create confusion because conversations can overlap or get dropped. Important customer details are inconsistently gathered, leading to repeated questions and errors. Sarah wishes for a solution that seamlessly manages the transition between AI and humans, keeping the context intact and automating task delegation.

2. What This Automation Does

This powerful n8n workflow handles Telegram conversations by using AI and Redis-backed session states to orchestrate seamless handoffs between a chatbot and human agents. When a message arrives, the workflow checks if the user is in a “bot,” “human,” or onboarding state and routes messages accordingly.

  • Structured Onboarding: An AI agent collects critical customer details (name, address, reason for contact) from conversation history using LangChain’s Information Extractor node.
  • Stateful Interaction Control: Conversation states are saved in Redis to track if the interaction is currently with the bot or a human agent.
  • Human-in-the-Loop Handoff: When switching to a human, the workflow sends a session summary and awaits a manual response from the human agent before returning control to the bot.
  • After-Sales Assistance: Once a human hands off back to the bot, the bot continues with enriched memory of the prior human interaction to provide better support.
  • Clear User Notifications: Customers are informed whenever they are transferred to or from a human agent to improve transparency.
  • Concurrent Subworkflows: Uses n8n’s executeWorkflowTrigger and toolWorkflow nodes to manage parallel conversation flows without blocking user messages.

Overall, this automation saves Sarah hours daily by eliminating manual tracking and enabling smooth, state-aware bot-human interactions, improving customer satisfaction and reducing errors.

3. Prerequisites ⚙️

  • n8n Account (Cloud or Self-hosted) 🔑
  • Telegram Bot API Token (via Telegram node) 📧
  • Redis Server for session and chat memory storage 📁
  • OpenAI API Key for LangChain AI agents 🔐
  • Basic familiarity with n8n workflows and Telegram bots

4. Step-by-Step Guide to Building This Workflow

Step 1: Set Up the Telegram Trigger

Navigate to Nodes → Telegram Trigger. Create a new Telegram Bot in BotFather if you haven’t. Enter your Bot API credentials. Configure it to listen to message updates.

You will see incoming Telegram messages trigger your workflow. This is the entry point for all user interactions.

Common mistake: Forgetting to set the webhook URL in Telegram to point to your n8n instance.

Step 2: Retrieve Conversation State from Redis

Add a Redis Get node connected to the Telegram Trigger. Configure the key as handoff_{{ $json.message.chat.id }}_state to check if the user is currently interacting with the bot or human.

The node fetches the session state to direct message flow.

Common mistake: Using inconsistent keys causing failed lookups.

Step 3: Switch Conversation Based on State

Use the Switch node to evaluate Redis data. Add rules to route for values human, bot, or default to onboarding.

This node controls flow: whether the message continues with the AI, is blocked awaiting human response, or triggers onboarding.

Step 4: Onboarding Agent Collects Customer Data

In the onboarding path, include an Agent node configured with a system message specifying the data needed (first name, last name, address, reason for call).

Link a Redis Memory node to maintain chat context.

Note: This dedicated agent focuses solely on onboarding to limit stray responses.

Step 5: Extract Structured Data with Information Extractor

Add the Information Extractor LangChain node to analyze recent messages stored in Redis chat history to pull required customer attributes.

Follow with a Code node to ensure all fields are captured by setting default empty values when missing.

Step 6: Check If All Required Details Are Present

Insert an If node to evaluate whether all customer information fields are present. This logic enables moving forward only when onboarding is complete.

Step 7: Handle Onboarding Completion

If all details are captured, trigger a Subworkflow node to prepare a summary of onboarding details.

This summary is forwarded to the human agent to take over support.

Step 8: Notify the User of Human Handoff

The subworkflow sends a message via the Telegram node using the sendAndWait operation that pauses for human input. This demonstrates a “human-in-the-loop” capability.

User receives notification that a human agent will assist them shortly.

Step 9: Set Redis State to “human” and Block Bot Response

Use a Redis Set node to mark the session interaction as “human” so that incoming messages no longer reach the AI agent.

Step 10: Human Agent Concludes and Returns Control to Bot

After the human agent responds, use set Redis to switch session state back to “bot”.

Capture the human’s comments and add them to the AI agent’s memory with Memory Manager nodes, enriching future bot replies.

Step 11: Resume Bot Conversation for After-Sales Assistance

The After Sales Agent node now handles the conversation with context from the human handoff.

User can continue chatting, or at any time request transfer back to a human through the provided tool.

Step 12: Use Human-In-The-Loop Tool for Smooth Delegation

The Tool Workflow node allows the AI agent to delegate back to humans upon user request, feeding data into the handoff subworkflow.

Step 13: Send Canned Responses and Notifications

Configure Telegram nodes to send polite, clear messages to users when their input is blocked during human interaction or after transfer.

5. Customizations ✏️

  • Add More Customer Fields: In the Information Extractor node, expand the attributes to capture mobile number or email by adding schema entries.
  • Switch to Different Messaging Platform: Replace Telegram nodes with WhatsApp or Slack nodes, updating credentials accordingly.
  • Adjust Timeout for Human Handoff: Modify the sendAndWait operation’s response timeout in the Telegram node to control how long the workflow waits for human input.
  • Integrate CRM System: Add HTTP Request nodes or database nodes to log customer data onboarded or handed off.
  • Customize Agent Prompts: Modify system messages in the Agent nodes to suit your business language and desired data collection style.

6. Troubleshooting 🔧

Problem: “Redis get operation returns null or empty”

Cause: Redis key does not exist or the key pattern is incorrect.

Solution: Verify the Redis key naming pattern matches exactly handoff_{{chatId}}_state. Check Redis server is reachable and authenticated correctly.

Problem: “Telegram sendAndWait node times out or no human reply”

Cause: Human agent does not respond or webhook connectivity issues.

Solution: Ensure the Telegram bot webhook is correctly set and the human agent system is notified and responsive. Consider adding alerting or fallback mechanisms.

Problem: “AI Agent keeps asking for same data repeatedly”

Cause: The Information Extractor is not correctly retrieving structured data.

Solution: Check the prompt template in the Information Extractor node to improve extraction accuracy. Test the Redis chat history consistency to ensure clean message records.

7. Pre-Production Checklist ✅

  • Test Telegram Bot connectivity with sample messages.
  • Verify Redis session keys are correctly set and updated during conversation flow.
  • Test AI onboarding agent to ensure it collects all required customer details.
  • Simulate human handoff by sending manual replies to the sendAndWait node.
  • Confirm after-sales agent responds with enriched human input context.
  • Backup your n8n workflows before deployment.

8. Deployment Guide

Activate the workflow by setting it active in n8n. Ensure your n8n instance is publicly accessible with proper SSL for Telegram webhooks.

Monitor executions in the n8n dashboard and enable logging for error tracking. Adjust redis server performance parameters if handling high message volume.

9. FAQs

Q: Can I use another AI model instead of GPT-4o-mini?
A: Yes, replace the model setting in LangChain nodes to your preferred OpenAI or compatible model.

Q: Does using Redis incur extra cost?
A: Running Redis on your own server is free; cloud Redis providers may bill based on usage.

Q: Is this workflow secure?
A: Telegram data is transmitted via secured webhooks, and hashed keys in Redis protect session states. Ensure your n8n instance is secure.

Q: Can I handle multiple simultaneous conversations?
A: Yes, Redis handles parallel session keys, and n8n nodes scale well for concurrent usage.

10. Conclusion

By following this detailed guide, you have built an advanced Telegram bot to human handoff automation with n8n using Redis and LangChain AI agents. The workflow ensures structured onboarding, smooth human-in-the-loop transitions, and enriched post-handoff assistance.

This automation will save you hours daily by reducing manual handoff confusion, improving customer experience and accuracy in support interactions.

Next, consider expanding this system by integrating CRM logging, adding voice/multimedia support, or automating complex routing with more conversation states. Keep iterating to fine-tune your customer service workflow efficiently.

Keep experimenting and happy automating!

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 (Beginner Guide)

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