P9 - Build Local AI Telegram Bot Fast (Ollama Guide)
🚀 AI Tutorial – P9: Create a Local AI Telegram Bot with Ollama in Minutes
Building a Local AI Telegram Bot is one of the fastest ways to bring AI into real-world usage. By combining Ollama with a simple Python script, you can create a powerful chatbot that runs entirely on your local machine.
In this guide, you’ll learn how to deploy a Telegram bot, connect it to a local AI model, and run it as a background service for continuous operation.
🎯 Why Use a Local AI Telegram Bot?
Running a local AI bot offers several advantages:
- 🔒 Full privacy (no external API calls)
- ⚡ Instant response from local models
- 💰 Zero API cost
- 🔧 Fully customizable behavior
🔗 Part 1: Connecting the Telegram Bot
🤖 Step 1: Create the Telegram Bot
Create your bot via Telegram (BotFather) and obtain your API token:
📁 Step 2: Create Bot Directory
On your Ubuntu server:
cd telegram-ai-bot
📦 Step 3: Install Python and Libraries
Install pip (if not available):
Install required libraries:
Upgrade if needed:
💻 Step 4: Create the Bot Script
Create the Python file:
Paste the following code:
import requests
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes
TOKEN = ""
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "qwen2.5:7b-instruct"
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_text = update.message.text
data = {
"model": MODEL,
"prompt": user_text,
"stream": False
}
response = requests.post(OLLAMA_URL, json=data)
ai_reply = response.json()["response"]
await update.message.reply_text(ai_reply)
app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
print("Bot is running...")
app.run_polling()▶️ Step 5: Run the Bot
Start the bot:
If successful, you will see:
🧪 Step 6: Test the Bot
- Open Telegram
- Search for your bot
- Send a message
👉 The AI will respond using your local Ollama model.
⚙️ Part 2: Run Bot as a Background Service
📍 Step 1: Determine Bot Path
Example path:
Check current path:
🛠️ Step 2: Create systemd Service
Create service file:
Add the following content:
Description=Telegram AI Bot
After=network.target
[Service]
User=bao
WorkingDirectory=/home/bao/telegram-ai-bot
ExecStart=/usr/bin/python3 /home/bao/telegram-ai-bot/bot.py
Restart=always
[Install]
WantedBy=multi-user.target
Save the file.
🔄 Step 3: Enable and Start Service
Reload systemd:
Enable service:
Start bot:
Check status:
If everything is working:
✅ Final Result
After completing all steps, your Local AI Telegram Bot will be fully operational:
- 🤖 Telegram bot connected to Ollama
- 🧠 Running Qwen AI model locally
- 🔄 Auto-start with systemd
- ⚡ Real-time AI responses
💡 Use Cases
This setup is ideal for:
- Personal AI assistants
- Internal business bots
- Automation workflows
- AI-powered chat systems
🎯 Final Thoughts
Creating a Local AI Telegram Bot with Ollama is one of the simplest and most powerful ways to deploy AI in real-world scenarios.
With just a few steps, you can:
- Run AI locally without cloud dependency
- Integrate AI into messaging platforms
- Build scalable and automated systems
🚀 Follow this series to explore more advanced AI integrations like multi-account routing, OpenClaw integration, and automation pipelines.
See also related articles
10 Powerful AI Business Applications to Boost Growth in 2025
Discover 10 powerful AI business applications that can transform your operations, boost efficiency, and drive growth. Learn how to implement AI today.
Read MoreP10 – Uninstall OpenClaw Windows Fast
P10 – Uninstall OpenClaw Windows Fast https://youtu.be/1ljEMzohiSY 🚀 AI Tutorial – P10: Uninstall OpenClaw on Windows (Clean Removal & Fix Issues) If you’re facing issues with OpenClaw or simply want to remove it completely, performing a proper Uninstall OpenClaw Windows process is essential. A partial uninstall may leave behind background...
Read MoreP9 – Build Local AI Telegram Bot Fast (Ollama Guide)
P9 – Build Local AI Telegram Bot Fast (Ollama Guide) https://youtu.be/YuiLJDLIVr0 🚀 AI Tutorial – P9: Create a Local AI Telegram Bot with Ollama in Minutes Building a Local AI Telegram Bot is one of the fastest ways to bring AI into real-world usage. By combining Ollama with a simple...
Read More

