Create a Telegram Bot with Mistral Nemotron AI and Conversation Memory
š¤ Create a Telegram Bot with Mistral AI and Conversation Memory
A sophisticated Telegram bot that provides AI-powered responses with conversation memory. This template demonstrates how to integrate any AI API service with Telegram, making it easy to swap between different AI providers like OpenAI, Anthropic, Google AI, or any other API-based AI model.
š§ How it works
The workflow creates an intelligent Telegram bot that: š¬ Maintains conversation history for each user š§ Provides contextual AI responses using any AI API service š± Handles different message types and commands š Manages chat sessions with clear functionality š Easily adaptable to any AI provider (OpenAI, Anthropic, Google AI, etc.)
āļø Set up steps
š Prerequisites š¤ Telegram Bot Token (from @BotFather) š AI API Key (from any AI service provider) š n8n instance with webhook capability
š ļø Configuration Steps
š¤ Create Telegram Bot Message @BotFather on Telegram Create new bot with /newbot command Save the bot token for credentials setup
š§ Choose Your AI Provider OpenAI: Get API key from OpenAI platform Anthropic: Sign up for Claude API access Google AI: Get Gemini API key NVIDIA: Access LLaMA models Hugging Face: Use inference API Any other AI API service
š Set up Credentials in n8n Add Telegram API credentials with your bot token Add Bearer Auth/API Key credentials for your chosen AI service Test both connections
š Deploy Workflow Import the workflow JSON Customize the AI API call (see customization section) Activate the workflow Set webhook URL in Telegram bot settings
⨠Features
š Core Functionality šØ Smart Message Routing**: Automatically categorizes incoming messages (commands, text, non-text) š§ Conversation Memory**: Maintains chat history for each user (last 10 messages) š¤ AI-Powered Responses**: Integrates with any AI API service for intelligent replies ā” Command Support**: Built-in /start and /clear commands
š± Message Types Handled š¬ Text Messages**: Processed through AI model with context š§ Commands**: Special handling for bot commands ā Non-text Messages**: Polite error message for unsupported content
š¾ Memory Management š¤ User-specific chat history storage š Automatic history trimming (keeps last 10 messages) š Global state management across workflow executions
š¤ Bot Commands
/start šÆ - Welcome message with bot introduction /clear šļø - Clears conversation history for fresh start Regular text š¬ - Processed by AI with conversation context
š§ Technical Details
šļø Workflow Structure š” Telegram Trigger - Receives all incoming messages š Message Filtering - Routes messages based on type/content š¾ History Management - Maintains conversation context š§ AI Processing - Generates intelligent responses š¤ Response Delivery - Sends formatted replies back to user
š¤ AI API Integration (Customizable) Current Example (NVIDIA): Model: mistralai/mistral-nemotron Temperature: 0.6 (balanced creativity) Max tokens: 4096 Response limit: Under 200 words
š Easy to Replace with Any AI Service:
OpenAI Example: { "model": "gpt-4", "messages": [...], "temperature": 0.7, "max_tokens": 1000 }
Anthropic Claude Example: { "model": "claude-3-sonnet-20240229", "messages": [...], "max_tokens": 1000 }
Google Gemini Example: { "contents": [...], "generationConfig": { "temperature": 0.7, "maxOutputTokens": 1000 } }
š”ļø Error Handling ā Non-text message detection and appropriate responses š§ API failure handling ā ļø Invalid command processing
šØ Customization Options
š¤ AI Provider Switching To use a different AI service, modify the "NVIDIA LLaMA Chat Model" node:
š Change the URL in HTTP Request node š§ Update the request body format in "Prepare API Request" node š Update authentication method if needed š Adjust response parsing in "Save AI Response to History" node
š§ AI Behavior š Modify system prompt in "Prepare API Request" node š”ļø Adjust temperature and response parameters š Change response length limits šÆ Customize model-specific parameters
š¾ Memory Settings š Adjust history length (currently 10 messages) š¤ Modify user identification logic šļø Customize data persistence approach
š Bot Personality š Update welcome message content ā ļø Customize error messages and responses ā Add new command handlers
š” Use Cases
š§ Customer Support**: Automated first-line support with context awareness š Educational Assistant**: Homework help and learning support š„ Personal AI Companion**: General conversation and assistance š¼ Business Assistant**: FAQ handling and information retrieval š¬ AI API Testing**: Perfect template for testing different AI services š Prototype Development**: Quick AI chatbot prototyping
š Notes
š Requires active n8n instance for webhook handling š° AI API usage may have rate limits and costs (varies by provider) š¾ Bot memory persists across workflow restarts š„ Supports multiple concurrent users with separate histories š Template is provider-agnostic - easily switch between AI services š ļø Perfect starting point for any AI-powered Telegram bot project
š§ Popular AI Services You Can Use
| Provider | Model Examples | API Endpoint Style | |----------|---------------|-------------------| | š¢ OpenAI | GPT-4, GPT-3.5 | https://api.openai.com/v1/chat/completions | | šµ Anthropic | Claude 3 Opus, Sonnet | https://api.anthropic.com/v1/messages | | š“ Google | Gemini Pro, Gemini Flash | https://generativelanguage.googleapis.com/v1beta/models/ | | š” NVIDIA | LLaMA, Mistral | https://integrate.api.nvidia.com/v1/chat/completions | | š Hugging Face | Various OSS models | https://api-inference.huggingface.co/models/ | | š£ Cohere | Command, Generate | https://api.cohere.ai/v1/generate |
Simply replace the HTTP Request node configuration to switch providers!
Related Templates
Demo Workflow - How to use workflowStaticData()
This workflow demonstrates how to use the workflowStaticData() function to set any type of variable that will persist wi...
Bulk Automated Google Drive Files Sharing and Direct Download Link Generation
This N8N workflow automates the process of sharing files from Google Drive. It includes OAuth2 authentication, batch pro...
USDT And TRC20 Wallet Tracker API Workflow for n8n
Overview This n8n workflow is specifically designed to monitor USDT TRC20 transactions within a specified wallet. It u...
š Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments