Animated data flow diagram

AI-Powered Telegram Chatbot: Text & Voice Assistant (GPT-4o)

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

Telegram OpenAI Langchain

Overview

Unlock Seamless User Engagement with this AI-Powered Telegram Agent

This n8n workflow deploys a sophisticated AI Agent directly into your Telegram, capable of handling both text and voice conversations. It's designed to understand user queries naturally, thanks to OpenAI's GPT-4o, and even transcribes voice notes on the fly using OpenAI Whisper. The agent leverages Langchain for managing conversational context, ensuring interactions are coherent and personalized. It's a powerful way to automate customer support, lead engagement, or provide information, directly where your users are.

Key Features & Benefits

  • Dual Input Modes: Effortlessly processes standard text messages and voice notes, making interaction easy for users.
  • Advanced AI Conversation: Utilizes OpenAI's GPT-4o for intelligent, human-like dialogue and understanding.
  • Voice-to-Text Transcription: Integrated OpenAI Whisper automatically converts spoken messages into text for the AI.
  • Contextual Awareness with Langchain: Employs Langchain's window buffer memory to recall recent conversation history, leading to more relevant responses.
  • Customizable AI Persona: Fine-tune the AI's behavior, personality, and specific instructions via the system prompt in the Langchain AI Agent node.
  • Richly Formatted Replies: Delivers responses using Telegram-supported HTML for enhanced readability and user experience (e.g., bold, italics, code blocks).
  • Robust Error Handling: Includes a mechanism to clean up and resend messages if the AI's initial HTML formatting causes issues.
  • User Experience Focused: Implements a "typing..." indicator to let users know the agent is processing their request.

Use Cases

  • Automating responses to frequently asked questions (FAQs) on Telegram, 24/7.
  • Providing instant, intelligent replies to sales inquiries or support requests received via Telegram.
  • Building a personal AI assistant for task reminders, information retrieval, or simple Q&A on Telegram.
  • Offering interactive content delivery or basic services through a conversational Telegram interface.
  • Qualifying leads by engaging users in conversation and gathering preliminary information.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key with access to a GPT-4o (or similar powerful chat model) and Whisper (for audio transcription).
  • Telegram Bot API Token, configured as an n8n credential.

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure Telegram Credentials: In the 'Listen for incoming events' (Telegram Trigger) node, create or select your Telegram API credential. Use this same credential for all other Telegram nodes ('Download voice file', 'Send final reply', 'Send error message', 'Correct errors', 'Send Typing action').
  4. Configure OpenAI Credentials: In the 'OpenAI Chat Model' node, create or select your OpenAI API credential. Use this same credential for the 'Convert audio to text' (OpenAI Transcribe) node.
  5. Customize AI Behavior: Navigate to the 'AI Agent' (Langchain Agent) node. Modify the systemMessage in its parameters to define your bot's persona, specific knowledge, HTML formatting rules, and how it should address users. (It's pre-configured to use the user's first name and current date/time).
  6. Model Selection: In the 'OpenAI Chat Model' node, ensure gpt-4o or your preferred model is selected. Adjust temperature or other options as needed.
  7. Memory Configuration: The 'Window Buffer Memory' (Langchain Memory) node is set to remember the last 10 exchanges. Adjust contextWindowLength if you need more or less history for context.
  8. Test Thoroughly: Send various text and voice messages to your Telegram bot to ensure all paths function correctly and the AI responds as expected.
  9. Activate the workflow to go live.

Tags:

AI AgentChatbotTelegramOpenAIGPT-4oLangchainVoice AssistantNLPAutomationCustomer Support

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation