Telegram Bot API Integration in Mobile Application
Telegram Bot API — simplest to integrate channel. HTTP API without SDK, documentation straightforward, sandbox not needed. But nuances: user must start dialog with bot, webhook needs HTTPS with valid cert, Telegram Web App enables mini-app within Telegram.
Sending Notifications via Bot
Minimal flow: user taps "Connect Telegram" in app, goes to bot, taps /start — bot gets chat_id, backend saves and uses for sending.
Message send:
POST https://api.telegram.org/bot{TOKEN}/sendMessage
Content-Type: application/json
{
"chat_id": 123456789,
"text": "Your order #98765 sent for delivery 🚚",
"parse_mode": "HTML",
"reply_markup": {
"inline_keyboard": [[
{ "text": "Track", "url": "https://yourbrand.com/track/98765" },
{ "text": "Support", "callback_data": "contact_support_98765" }
]]
}
}
parse_mode: "HTML" or "MarkdownV2" — formatting. HTML easier: <b>, <i>, <code>, <a href="...">.
Getting chat_id — via webhook. Backend registers webhook:
POST https://api.telegram.org/bot{TOKEN}/setWebhook
{ "url": "https://api.yourbrand.com/telegram/webhook" }
On /start from user, Telegram sends:
{
"message": {
"from": { "id": 123456789, "username": "user_alex" },
"chat": { "id": 123456789 },
"text": "/start auth_token_from_deeplink"
}
}
/start can pass parameter via deep link https://t.me/YourBot?start=user_uuid_12345. Auto-bind chat_id to system user without extra confirmation.
Inline Keyboard and Callback Queries
Buttons in message — inline keyboard. Tap triggers callback_query to webhook:
{
"callback_query": {
"from": { "id": 123456789 },
"message": { "message_id": 456, "chat": { "id": 123456789 } },
"data": "contact_support_98765"
}
}
After handling, must answer callback_query or button spins indefinitely:
POST https://api.telegram.org/bot{TOKEN}/answerCallbackQuery
{ "callback_query_id": "...", "text": "Connecting support..." }
Telegram Web App (TWA)
For full interface within Telegram — Telegram Web App. web_app button in keyboard opens mini-browser with your web app. Mobile app here acts as PWA or React app:
// Web App has Telegram WebApp SDK
const tg = window.Telegram.WebApp;
tg.ready();
// User data
const user = tg.initDataUnsafe.user;
// Send data to bot and close TWA
tg.sendData(JSON.stringify({ action: "order_confirmed", orderId: "98765" }));
Mobile App: Deep Link for Bot Connection
Mobile side needs "Connect Telegram" button opening Telegram with deep link. iOS and Android:
// Android
val telegramDeepLink = "https://t.me/YourBotName?start=${currentUser.id}"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(telegramDeepLink))
startActivity(intent)
// iOS
let deepLink = "https://t.me/YourBotName?start=\(currentUser.id)"
if let url = URL(string: deepLink) {
UIApplication.shared.open(url)
}
Telegram not installed — opens in browser, offers install or Web Telegram.
After binding backend marks user "Telegram connected" — mobile app next launch syncs status and changes button UI.
Timeline
Telegram Bot API integration, webhook handler with commands and callback queries, deep link user binding, mobile UI for bot connection — 3–5 workdays.







