Multichannel Bot Telegram WhatsApp Viber — Unified Logic
Integrating a bot in one messenger is not hard. The complexity starts when you need to cover Telegram, WhatsApp, and Viber simultaneously — without turning the codebase into three independent piles of logic. We solve this through a unified business logic layer, isolating each platform's specifics behind an adapter interface. Developing three separate bots costs 40–60% more, and time-to-market is two to three times longer. For a typical project, our multichannel solution starts at $5,000 and saves up to 60% of the budget compared to three independent bots.
Why three bots are not three times more work, but three times more bugs? — multichannel bot telegram
Each platform has its own rules. Telegram Bot API sends webhooks synchronously and expects a 200 OK response within 5 seconds — if the backend delays, the platform will resend the request, and the bot will get duplicates. WhatsApp Business API (Meta Cloud API) works differently: webhook verification comes as a GET request with hub.challenge, and if you don't respond with the correct value, the webhook simply won't register — a silent error easily missed.
Viber has a different rich media format: the rich_media type with buttons only works when sent via send_message, not through the reply API. Developers migrating logic from Telegram (where inline keyboards can be attached to any message) run into this on the first day. Viber rich media is about 3x more complex to implement than Telegram inline keyboards.
Attachments are another story. Telegram accepts multipart/form-data when sending a file directly. WhatsApp requires uploading media via POST /v1/media to get a media_id, then sending it in a message — adding an extra API call that increases latency by 200–500 ms. Viber limits file size to 200 MB and supports strictly defined MIME types. If all this logic is scattered across a service without a clear abstraction, maintaining it after six months is impossible.
How the adapter pattern eliminates duplication?
The right approach is to introduce a BotAdapter interface with methods sendMessage, sendFile, parseIncoming. Each platform gets its own implementation.
// Android (Kotlin) — adapter layer example
interface BotAdapter {
suspend fun sendMessage(chatId: String, text: String, buttons: List<BotButton>? = null)
suspend fun sendFile(chatId: String, fileUrl: String, mimeType: String)
fun parseIncoming(payload: String): BotMessage
}
class TelegramAdapter(private val token: String) : BotAdapter {
private val client = OkHttpClient()
override suspend fun sendMessage(chatId: String, text: String, buttons: List<BotButton>?) {
val body = buildTelegramPayload(chatId, text, buttons)
client.newCall(Request.Builder()
.url("https://api.telegram.org/bot$token/sendMessage")
.post(body).build()).execute()
}
// ...
}
On iOS, the pattern is the same — a BotAdapter protocol and three struct implementations via URLSession. In Flutter, it's convenient to use an abstract class with dio under the hood. Business logic (command recognition, FSM dialogue, database work) lives above — it doesn't know where the message came from. This cuts code by 40–60% compared to three independent implementations.
Dialogue State Management (FSM)
Any non-trivial bot needs a finite state machine. Storing userState in memory is an antipattern: a service restart resets all dialogues. In practice, we use Redis with TTL (e.g., 30 minutes of inactivity reset the session) or a PostgreSQL table with updated_at. Redis offers speed (sub-millisecond reads) and automatic expiration, while PostgreSQL provides reliability and ACID compliance. For most projects, Redis is preferred due to its performance and built-in TTL, though PostgreSQL adds about 10–20 ms overhead per state lookup.
The state key is {platform}:{chatId}, allowing one user to have independent dialogues in different messengers, which is sometimes required by business logic.
AI-Powered Steps for Implementation
Our process leverages AI-driven analysis to streamline development:
- Audit scenarios — AI identifies command patterns and edge cases from your requirements.
- Design FSM — generate state transitions using predefined templates, reducing design time by 30%.
- Implement adapters — use AI code generation to produce boilerplate for each messenger.
- Integrate logic — AI tests compatibility across platforms automatically.
- Load test — simulate up to 1000 webhooks/min with AI-generated payloads.
- Monitor — AI sets up anomaly detection for webhook failures and latency spikes.
Mobile app specifics
If the bot is embedded not in a server service but directly in a mobile app, you need WebSocket subscription or polling. For Telegram in a mobile context, this means getUpdates with long polling through BackgroundFetch (iOS) or WorkManager (Android). Keeping a persistent WebSocket for a bot in the background on iOS is impossible — the system will kill the process. The correct pattern: a push notification from the server wakes the app, it makes one getUpdates call, processes the queue, and goes back to sleep. This reduces battery drain by 90% compared to continuous polling.
WhatsApp Cloud API in a mobile app requires a server proxy — you cannot call the Meta API directly from a mobile client (a verified business account is needed on the server side). This often surprises teams looking for an "easy" integration.
Messenger API Comparison
Telegram uses a straightforward webhook: POST with 5-second timeout and multipart file uploads. WhatsApp Cloud API requires a two-step verification (GET then POST), a media upload step before sending files, and a 20-second webhook timeout. Viber supports rich media only via send_message, not reply, has a 30-second timeout, and enforces a 200 MB file size limit with strict MIME types. These differences mean that a naive port from Telegram to Viber can take 3x longer due to rich media rework.
Process
First, a scenario audit: which commands, are buttons/carousels needed, is file exchange required, is payment needed (Telegram Payments vs WhatsApp Pay). This determines the complexity of the adapters.
Next: FSM design, adapter implementation one by one (Telegram first — the most mature API), integration with core logic, webhook load testing (up to 1000 requests/min). A separate stage is monitoring: logging incoming payloads with personal data masking, alerts for delivery_failed in Viber and failed webhook verifications.
Common integration mistakes (and how to avoid them)
- Missing WhatsApp webhook verification → webhook doesn't register. Use a dedicated endpoint that echos the challenge.
- Using reply API for Viber rich media → buttons don't show. Always use
send_messagefor rich media. - Storing state in memory → dialogue loss on restart. Use Redis or PostgreSQL.
- No timeouts on Telegram → duplicate webhooks. Set a 5-second timeout in your server.
- Direct call to Meta API from a mobile app → blocking. Implement a server proxy.
What's included (deliverables)
- Scenario and requirements audit using AI tools
- FSM and adapter layer design
- Adapter implementation for Telegram, WhatsApp, Viber
- Integration with server-side and mobile app
- Load testing (up to 1000 webhooks/min) with AI-generated test cases
- Monitoring and alerts (logs, PII masking, anomaly detection)
- Documentation and team training
- Post-release support (3 months)
Timeline and cost estimates
A bot in one messenger with basic commands — 3–5 days. Multichannel implementation with FSM, files, buttons, and server-side — 2–4 weeks. If CRM or payment integration is needed — separate assessment after requirements analysis. Starting price for a multichannel bot is $5,000, with typical savings of 40–60% compared to building three separate bots. We have completed over 50 messenger integrations with a 95% client satisfaction rate.
App Store Review Guidelines Section 4.2 mandates minimal functionality, so the bot must work without subscriptions. We consider this during design. We have 5+ years of experience in mobile and server solutions and have implemented over 50 messenger integrations. Our clients save up to 60% of the budget on development and get a solution in 2–4 weeks. Get a consultation — we'll evaluate your project and offer the best solution.







