Telegram Messenger Integration with Website (Notifications, Bots)
Telegram Bot API is one of the most convenient tools for notifications and automation. Free, fast, doesn't require sender name registration. Covers most tasks: admin notifications, service messages to users, interactive bots for processing requests.
Telegram Chat Notifications (Simplest Scenario)
Quick way to receive notifications about orders or events on your site — send to Telegram chat via Bot API:
class TelegramNotifier
{
public function send(string $message, string $parseMode = 'HTML'): void
{
Http::post("https://api.telegram.org/bot{$this->token}/sendMessage", [
'chat_id' => config('services.telegram.chat_id'),
'text' => $message,
'parse_mode' => $parseMode
]);
}
}
// Usage
$telegram->send(
"🛒 <b>New order #{$order->id}</b>\n"
. "Amount: {$order->total} ₽\n"
. "Customer: {$order->customer_name}"
);
For group notifications: the bot must be added to the group and have permission to send messages. chat_id for a group is a negative number.
Webhook for Incoming Messages
To make the bot respond to user messages, a webhook is needed:
// Register webhook
Http::post("https://api.telegram.org/bot{$token}/setWebhook", [
'url' => 'https://yoursite.com/webhooks/telegram',
'allowed_updates' => ['message', 'callback_query']
]);
// Handler
Route::post('/webhooks/telegram', function (Request $request) {
$update = $request->json()->all();
if (isset($update['message'])) {
$chatId = $update['message']['chat']['id'];
$text = $update['message']['text'];
dispatch(new ProcessTelegramMessageJob($chatId, $text));
}
if (isset($update['callback_query'])) {
// Inline button clicked
$callbackData = $update['callback_query']['data'];
dispatch(new ProcessTelegramCallbackJob($update['callback_query']));
}
return response('OK');
});
Inline Keyboards for Interactivity
Http::post("https://api.telegram.org/bot{$token}/sendMessage", [
'chat_id' => $chatId,
'text' => "Request #{$applicationId} received. What to do?",
'reply_markup' => json_encode([
'inline_keyboard' => [[
['text' => '✅ Accept', 'callback_data' => "accept_{$applicationId}"],
['text' => '❌ Reject', 'callback_data' => "reject_{$applicationId}"]
]]
])
]);
Manager clicks button in Telegram → bot receives callback_query → updates request status on site → sends confirmation.
Telegram Login Widget
Website authentication via Telegram:
<script async src="https://telegram.org/js/telegram-widget.js?22"
data-telegram-login="YourBotName"
data-size="large"
data-auth-url="https://yoursite.com/auth/telegram/callback"
data-request-access="write">
</script>
// Verify signature
public function callback(Request $request): void
{
$checkHash = $request->hash;
$authData = $request->except('hash');
ksort($authData);
$dataCheckString = implode("\n", array_map(
fn($k, $v) => "{$k}={$v}",
array_keys($authData), $authData
));
$secretKey = hash('sha256', config('services.telegram.bot_token'), true);
$hash = hash_hmac('sha256', $dataCheckString, $secretKey);
if (!hash_equals($hash, $checkHash)) {
abort(403, 'Invalid Telegram signature');
}
// User authorization
}
Service Notifications to Users
To send notifications to specific users, save their chat_id — it's passed on first bot interaction. User starts dialog with bot, bot saves chat_id linked to site account.
Integration timeframe: 2–3 days for a bot with notifications, inline buttons, and Telegram Login.







