Telegram Channel
The eight endpoints that connect a Telegram bot, switch the channel and manage the chats notifications reach.
Overview
Telegram is a notification channel beside e-mail and SMS. A bot token connects the channel, and the channel switch turns the copies on or off.
Messages go to chats. Shared chats are groups and channels that receive template notifications, and one of them is the default. Personal chats belong to staff members.
A chat is linked in the panel, with a one-time link opened in Telegram. These endpoints read, adjust and remove linked chats; they cannot link a new one.
Reference
Reading the Channel Settings
Returns the channel state, the bot behind the token and how many chats are linked. The token is write-only and comes back masked.
<bot id>:••••••. Null when no token is saved. The secret part never leaves the server.curl 'https://panel.example.com/api/v1/admin/notifications/telegram' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/notifications/telegram', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data } = await res.json();
const canSend = data.available;$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// "enabled" alone does not mean copies go out: "available" also needs an active chat.
$tg = Api::Notifications()->GetTelegramSettings()['data'];
$canSend = $tg['available'];Writing the Channel Settings
Saves a bot token and switches the channel on or off. Both fields are optional; one invalid field means nothing is written.
curl -X PUT 'https://panel.example.com/api/v1/admin/notifications/telegram' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"token":"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11","enabled":true}'const res = await fetch('https://panel.example.com/api/v1/admin/notifications/telegram', {
method: 'PUT',
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled: false }),
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['token' => $botToken]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// A token of a DIFFERENT bot breaks every linked chat: compare bot.id before and after.
$before = Api::Notifications()->GetTelegramSettings()['data']['bot']['id'] ?? null;
$after = Api::Notifications()->UpdateTelegramSettings(['token' => $botToken])['data'];Testing the Bot
Checks the saved token with Telegram and refreshes the bot details. No message goes to any chat.
curl -X POST 'https://panel.example.com/api/v1/admin/notifications/telegram/test' \
-H "Authorization: Bearer $API_KEY"const res = await fetch('https://panel.example.com/api/v1/admin/notifications/telegram/test', {
method: 'POST',
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data } = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/test');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// A token revoked in BotFather shows up here as telegram_error.
$check = Api::Notifications()->TestTelegramBot();Listing the Chats
Lists every linked chat: shared chats first with the default at the top, then personal chats. Telegram's own chat id is not returned; every call uses the row id.
shared or personal. Leave it out for both kinds.shared or personal.active or broken. Broken means the bot lost the chat: removed, blocked, or the chat is gone.curl -G 'https://panel.example.com/api/v1/admin/notifications/telegram/chats' \
-H "Authorization: Bearer $API_KEY" \
--data-urlencode 'kind=shared'const res = await fetch('https://panel.example.com/api/v1/admin/notifications/telegram/chats?kind=shared', {
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data } = await res.json();
const broken = data.filter((c) => c.status === 'broken');$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/chats?kind=shared');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// kind travels in the query string, the second argument.
$shared = Api::Notifications()->GetTelegramChats([], ['kind' => 'shared'])['data'];Reading a Chat
Returns one linked chat.
curl 'https://panel.example.com/api/v1/admin/notifications/telegram/chats/5' \
-H "Authorization: Bearer $API_KEY"const res = await fetch(`https://panel.example.com/api/v1/admin/notifications/telegram/chats/${chatId}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
const { data } = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/chats/' . $chatId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// last_error holds Telegram's own reason when the chat is broken.
$chat = Api::Notifications()->GetTelegramChat(['id' => 5])['data'];Updating a Chat
Changes a chat's default flag and quiet hours. Every field is checked before anything is written.
curl -X PATCH 'https://panel.example.com/api/v1/admin/notifications/telegram/chats/5' \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '{"quiet_enabled":true,"quiet_start":"22:00","quiet_end":"08:00"}'const res = await fetch(`https://panel.example.com/api/v1/admin/notifications/telegram/chats/${chatId}`, {
method: 'PATCH',
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ is_default: true }),
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/chats/' . $chatId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['quiet_enabled' => false]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// Quiet hours silence the sound, not the message: everything still arrives.
Api::Notifications()->UpdateTelegramChat([
'id' => 5, 'quiet_enabled' => true, 'quiet_start' => '22:00', 'quiet_end' => '08:00',
]);Removing a Chat
Removes a linked chat. For a shared chat the bot also leaves the group or channel.
curl -X DELETE 'https://panel.example.com/api/v1/admin/notifications/telegram/chats/6' \
-H "Authorization: Bearer $API_KEY"const res = await fetch(`https://panel.example.com/api/v1/admin/notifications/telegram/chats/${chatId}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/chats/' . $chatId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// Removing the default chat moves the flag; read the list again afterwards.
Api::Notifications()->DeleteTelegramChat(['id' => 6]);Sending a Test Message
Sends the panel's test message to the chat. A delivered message marks the chat active again; a refusal marks it broken.
curl -X POST 'https://panel.example.com/api/v1/admin/notifications/telegram/chats/5/test' \
-H "Authorization: Bearer $API_KEY"const res = await fetch(`https://panel.example.com/api/v1/admin/notifications/telegram/chats/${chatId}/test`, {
method: 'POST',
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await res.json();$ch = curl_init('https://panel.example.com/api/v1/admin/notifications/telegram/chats/' . $chatId . '/test');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);// A broken chat that takes the message comes back as active.
$sent = Api::Notifications()->SendTelegramTestMessage(['id' => 5]);Pitfalls
Saving the token of a different bot marks every linked chat as broken, because the new bot is not a member of them. Notifications stop until the chats are linked again in the panel. Compare the bot id before and after a token change.
Linking needs a one-time link that a person opens in Telegram. These endpoints only read, adjust and remove chats that are already linked. A removed chat comes back only through the panel.
When the removed chat was the default, the flag moves to the oldest remaining active shared chat. With none left, no chat is the default until one is chosen.
The chat test sends a real Telegram message that everyone in the chat sees. The bot test checks the token alone and sends nothing.
Related Articles
Merci pour votre retour !
L'équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas dans la base de connaissances.