Inspiration

AI is often seen as a leverage, equalling the playing ground between the not-so tech savvy and tech bros ( and girls). That is not always the case, though AI communicates with Natural Language manipulating it to get a desired (tech) product requires being grounded in programming and other adjacent tech jargons at best and being an “ Andrej Karpathy” at worse. That's is what inspired the creation of SquadlyHelperBot, to help soloprenuers stop the scrolls from one YouTube video to the other learning about agents, MCPs etc. By giving them a ‘platform’ to create a custom personal / virtual AI assistant with (absolutely) no technical knowledge required. To go on a rhetoric: we were inspired to smoothen the rough (read tech knowledge required) edges of AI and LLMs.

What it does

SquadlyHelperBot gives you a platform to create a custom bot/agent to help manage and run your Telegram community. It answers questions about the business, moderate groups, manage payments, onboard new members etc. It's a community manager, virtual assistant, financial assistant and moderator in one.

How we built it

Tech Stack Backend & Core Infrastructure: Django 5.2.8 with Django REST Framework for robust API and admin panel PostgreSQL with SSL/TLS encryption for secure data persistence Redis 7.1.0 for real-time conversation state management and message queuing

Telegram Integration: python-telegram-bot 22.5 supporting hybrid webhook + long-polling architecture for reliability across different deployment environments Custom middleware for business context injection and webhook secret verification

AI & NLP: Google Gemini 2.5 Flash Lite API for intelligent response generation Sentence Transformers for semantic FAQ matching and similarity scoring scikit-learn for intent classification and query analysis

DevOps: Gunicorn application server with WhiteNoise for static asset serving Full async/await pipeline for concurrent request handling

Architecture Highlights Our system uses a multi-tenant bot manager that: Routes incoming messages from any business bot to the correct Django instance Manages separate Telegram bot tokens per business while maintaining a single backend Implements a custom Redis-backed state machine with 24-hour TTL for conversation persistence Processes 10K+ messages/minute through a scalable worker queue system

The workflow is: Telegram Webhook/Polling → Redis Queue → Async Workers → LLM Processing → Response Relay

Challenges we ran into

1.The Multi-Bot Problem Initial Problem: We tried creating separate Django Application instances per business bot This led to massive memory overhead, state synchronization nightmares, and webhook routing conflicts Each bot needed its own event loop, handlers, and database connection pool Our Solution: Single Process, Multiple Bot Tokens Instead of multiple applications, we:

Single Worker Process: One long-polling worker that manages ALL bot instances in parallel Token-Based Routing: Store all verified bot tokens in a list and poll from each one simultaneously Business Context Injection: Middleware extracts the bot token, looks up which business it belongs to via bot_manager.get_business_id_from_token(), and injects that into the context Shared State via Redis:All bots share the same Redis instance for conversation state, session data, and message queues Worker Process (Single) ├── Bot 1 Token (Business A) → business_id=1 ├── Bot 2 Token (Business B) → business_id=2 ├── Bot 3 Token (Business C) → business_id=3 └── Bot N Token (Business N) → business_id=N ↓ All route through same handlers & middleware → correct data isolation via business_id

Result: Moved from "one app per bot" to "one worker for all bots" 90% reduction in memory overhead No state sync issues (everything's in Redis) Horizontally scalable (add more Worker processes if needed)

2. The Async-to-Sync Bridge Custom business bots weren't receiving any updates. The issue? We were calling Django ORM methods from async contexts without proper @sync_to_async decorators. Python didn't throw an error—it silently failed. Solution: Systematic audit of all database calls and wrapping them appropriately. Also implemented strict logging to catch these issues earlier. 2. Conversation State Leaks Users would get stuck in outdated conversation states because Redis state wasn't expiring properly. One user reported being asked "What's your business name?" after they'd already completed onboarding. Solution: Implemented automatic TTL-based cleanup (24 hours) and explicit state clearing when conversations end. 3. Telegram's Rate Limits & Webhook Timeouts Telegram enforces strict rate limits and webhook response timeouts. During testing, sending too many messages too quickly would cause silent failures. Solution: Implemented message batching and intelligent queuing—not a perfect fix, but it works under most circumstances.

Accomplishments that we're proud of

The Complete No-Code Solution A solopreneur can literally create a fully functional AI-powered Telegram bot without touching a single line of code. They input their FAQs, set custom instructions, and their bot goes live. This democratization of AI was our core mission, and we nailed it.

The Intelligent 3-Tier Response System We're not just generating random responses. Our system intelligently:

i. First checks custom instructions (time-based, priority rules that override everything) ii. Then searches semantically through FAQs using embeddings Finally falls back to Gemini LLM only when needed

This means most customer questions are answered instantly from business knowledge, not through expensive LLM calls.

** Seamless Human Handoff** When a customer issue is too complex, our escalation system instantly connects them to a human without losing conversation history. The owner sees everything the customer has said, can edit responses before sending, and can close the ticket when done. It's not just a bridge—it's a fully-featured support ticket system. Production-Ready Architecture We didn't just hack something together. Our system has:

Full SSL/TLS encryption Connection pooling with health checks Async workers handling 10K+ messages/minute Complete conversation audit trails Multi-database routing for tenant isolation Comprehensive error handling and logging

The "Owner Main Menu" We implemented a smart UX where returning business owners see a dashboard menu (/start → main menu) instead of being forced back through onboarding. Small detail, but it shows we were thinking about the actual user experience, not just the technical spec.

What we learned

AI Isn't Magic—Context Is Everything We thought we could throw raw customer questions at Gemini and get decent answers. We were wrong. Turns out, providing business context (FAQs, instructions, operating hours) is worth 10x more than the LLM's raw capabilities. The "AI" is only as good as the knowledge you feed it. State Management at Scale Is Hard Redux, Vuex, Redux-Saga—all these frontend state managers exist for a reason. Building our own Redis-backed conversation state manager made us appreciate how many edge cases there are (expired states, concurrent writes, TTL races, etc). Telegram's Constraints Are Actually Features We initially hated Telegram's strict rate limits and webhook timeouts. But they forced us to design for reliability implementing queues, retries, and graceful degradation. The constraints made us better engineers. Solopreneurs Want Simplicity, Not Features During testing, we learned that business owners don't want 50 configuration options. They want to input their info, create FAQs, and move on. Every extra setting we added, they wanted removed. UX simplicity > feature richness for this audience. Async Python Is Worth the Learning Curve Initially, we tried to do everything synchronously. It was slow and unstable. Once we committed to full async/await, our throughput increased 5x and reliability improved dramatically. The initial learning curve was worth it.

What's next for SquadlyHelperBot

Expansion Beyond Telegram

WhatsApp & Instagram DMs integration for multi-platform coverage Web chat widget for businesses wanting on-site customer support Support for other messaging platforms (Discord, Slack communities)

Advanced Analytics & Intelligence

Conversation analytics dashboard: Track customer sentiment, common issues, resolution rates Automated FAQ suggestions: Use conversation logs to recommend new FAQs Performance metrics: Show owners ROI (e.g., "Your bot handled 85% of support requests without human intervention")

Payment & Commerce Integration

Stripe/Paystack integration for businesses to collect payments through the bot Product catalog integration for e-commerce businesses Order management directly within Telegram conversations

Agent Collaboration & Teams

Multi-agent support: Allow teams of humans to collaborate on complex escalations Role-based permissions: Admins, support agents, view-only roles Handoff workflows: Route escalations intelligently based on agent availability

Self-Learning Bots

Active learning: Bot learns from human responses and improves over time Feedback loops: Owners can thumbs-up/down bot responses to train it Custom model fine-tuning: Option to fine-tune Gemini on business-specific data

Share this project:

Updates