πŸ’¬ Create a Telegram bot with Mistral Nemotron AI and conversation memory

⚑ 1,102 views Β· πŸ’¬ Support Chatbots

Description

πŸ€– 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:

βš™οΈ Set up steps

πŸ“‹ Prerequisites

πŸ› οΈ Configuration Steps

  1. πŸ€– Create Telegram Bot

    • Message @BotFather on Telegram
    • Create new bot with /newbot command
    • Save the bot token for credentials setup
  2. 🧠 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
  3. πŸ” 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
  4. πŸš€ 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

πŸ“± Message Types Handled

πŸ’Ύ Memory Management

πŸ€– Bot Commands

πŸ”§ Technical Details

πŸ—οΈ Workflow Structure

  1. πŸ“‘ Telegram Trigger - Receives all incoming messages
  2. πŸ”€ Message Filtering - Routes messages based on type/content
  3. πŸ’Ύ History Management - Maintains conversation context
  4. 🧠 AI Processing - Generates intelligent responses
  5. πŸ“€ Response Delivery - Sends formatted replies back to user

πŸ€– AI API Integration (Customizable)

Current Example (NVIDIA):

πŸ”„ 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

🎨 Customization Options

πŸ€– AI Provider Switching

To use a different AI service, modify the β€œNVIDIA LLaMA Chat Model” node:

  1. πŸ“ Change the URL in HTTP Request node
  2. πŸ”§ Update the request body format in β€œPrepare API Request” node
  3. πŸ” Update authentication method if needed
  4. πŸ“Š Adjust response parsing in β€œSave AI Response to History” node

🧠 AI Behavior

πŸ’Ύ Memory Settings

🎭 Bot Personality

πŸ’‘ Use Cases

πŸ“ Notes

ProviderModel ExamplesAPI Endpoint Style
🟒 OpenAIGPT-4, GPT-3.5https://api.openai.com/v1/chat/completions
πŸ”΅ AnthropicClaude 3 Opus, Sonnethttps://api.anthropic.com/v1/messages
πŸ”΄ GoogleGemini Pro, Gemini Flashhttps://generativelanguage.googleapis.com/v1beta/models/
🟑 NVIDIALLaMA, Mistralhttps://integrate.api.nvidia.com/v1/chat/completions
🟠 Hugging FaceVarious OSS modelshttps://api-inference.huggingface.co/models/
🟣 CohereCommand, Generatehttps://api.cohere.ai/v1/generate

Simply replace the HTTP Request node configuration to switch providers!

πŸ”— Nodes Used

HTTP Request, Telegram, Telegram Trigger

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup