Clawdbot: AI Assistant on Telegram
Table of Contents
🤖 Why Telegram?
Telegram is arguably the best platform for bots. Its API is robust, fast, and free. By connecting your self-hosted LLM (Clawdbot) to Telegram, you get:
- Access Everywhere: Chat with your AI from any device.
- Voice Messages: Send audio, get text back (Speech-to-Text).
- Media: Send images for analysis (Multi-modal models).
🏗️ Architecture
- Telegram Bot API: Webhook or Long Polling.
- Middleware (Node.js): Receives message -> Sends to LLM -> Formats response -> Sends back to Telegram.
- LLM Backend: Ollama / LocalAI running Llama 3.
🛠️ Step-by-Step Guide
1. Create a Bot
Talk to @BotFather on Telegram.
/newbot-> Name:MyPrivateAI-> Username:MyPrivateAI_bot.- Copy the API Token.
2. Set Up Node.js Project
mkdir clawdbot-telegram
cd clawdbot-telegram
npm init -y
npm install telegraf axios dotenv
3. Write the Bot Logic (index.js)
require('dotenv').config();
const { Telegraf } = require('telegraf');
const axios = require('axios');
const bot = new Telegraf(process.env.TELEGRAM_TOKEN);
bot.start((ctx) => ctx.reply('Hello! I am your private AI.'));
bot.on('text', async (ctx) => {
const userMessage = ctx.message.text;
ctx.sendChatAction('typing'); // Show "typing..." status
try {
// Call local LLM (Ollama)
const response = await axios.post('http://localhost:11434/api/generate', {
model: 'llama3',
prompt: userMessage,
stream: false
});
ctx.reply(response.data.response);
} catch (error) {
console.error(error);
ctx.reply('Error talking to the brain 🧠');
}
});
bot.launch();
console.log('Bot is running...');
4. Run It
node index.js
🧠 Advanced Features
Maintaining Context
The simple example above has no memory. To fix this:
- Store
chat_idand message history in a simple array or Redis. - Send the last N messages as context to Ollama.
Voice Notes (Whisper)
Telegram sends audio as .ogg.
- Download file.
- Convert to
.wav(ffmpeg). - Send to OpenAI Whisper (or local Faster-Whisper).
- Feed text to LLM.
🚀 Deployment
Run this Node.js script on a Raspberry Pi, a spare laptop, or a cheap VPS (if you expose your Ollama port via tunnel like Ngrok).
🏁 Conclusion
Building a Telegram bot for your AI is a weekend project with massive utility. It democratizes access to your personal intelligence stack.
You might also be interested in
Clawdbot: Hosting Your Own AI Assistant
How to deploy Clawdbot on Android. A self-hosted, open-source AI assistant that respects your privacy. Architecture and setup guide.
ChatGPT 5.3 Codex: The New Standard for Mobile Development?
A deep dive into ChatGPT 5.3 Codex, its new dedicated app, and what it means for Android developers. Includes comparison with Gemini 3.0 Pro.
Clean Architecture + AI: The Dynamic Duo of Modern Development
Discover how Artificial Intelligence and Clean Architecture empower each other to create maintainable, scalable, and precisely auto-generated Android code.