Universal Multi-Media Broadcast Engine (copyMessage)
Deliver text, photos, videos, voice notes, stickers, and channel forwards to all users with safe rate-limited pacing.
Universal Multi-Media Broadcast System
Mass announcements and notifications are essential for audience engagement. Botlify Cloud standardizes multi-media broadcasting using Telegram's official copyMessage API method, enabling administrators to broadcast any rich content type without uploading files multiple times.
Why copyMessage Outperforms sendMessage
| Feature | Traditional sendMessage | Botlify copyMessage Engine |
|---|---|---|
| Supported Content | Plain text / HTML only | Text, Photo, Video, Document, Voice, Audio, Sticker, GIF, Channel Forwards |
| Media Upload Overhead | Re-uploads media on every call | Clones message on Telegram's servers (Zero Bandwidth) |
| Formatting Preservation | Requires manual parse_mode tag parsing | Preserves original captions, spoiler tags, and entities automatically |
Production Implementation Pattern
The following engine pattern is recommended for all production bots on Botlify Cloud:
PHP — Universal Multi-Media Broadcast Engine (copyMessage)
<?php
// ── Botlify Cloud .env — auto-injected, never hardcode secrets ──
$BOT_TOKEN = getenv('BOT_TOKEN'); // Telegram bot token from @BotFather
$ADMIN_CHAT_ID = getenv('ADMIN_CHAT_ID'); // Your numeric admin Telegram user ID
$BOT_USERNAME = getenv('BOT_USERNAME'); // Bot username without @
declare(strict_types=1);
// Admin Broadcast Message Handler
if ($state === 'awaiting_broadcast_message' && (string)$chatId === ADMIN_CHAT_ID) {
clearState($chatId);
bot('sendChatAction', ['chat_id' => $chatId, 'action' => 'typing']);
$msgId = (int)($msg['message_id'] ?? 0);
$users = $pdo->query('SELECT chat_id FROM users WHERE is_banned = 0')->fetchAll();
$sent = 0;
$failed = 0;
foreach ($users as $u) {
$targetId = (string)$u['chat_id'];
$r = bot('copyMessage', [
'chat_id' => $targetId,
'from_chat_id' => $chatId,
'message_id' => $msgId
]);
if (!empty($r['ok'])) {
$sent++;
} else {
$failed++;
}
usleep(38000); // 38ms safe rate limiting (~26 messages/sec)
}
bot('sendMessage', [
'chat_id' => $chatId,
'text' => "📢 Universal Broadcast Complete!\n━━━━━━━━━━━━━━━━━━━━━\n• Successfully Delivered: {$sent}\n• Failed / Blocked: {$failed}",
'parse_mode' => 'HTML',
'reply_markup' => getAdminKeyboard()
]);
exit;
}
Safe Anti-Flood Pacing (38ms Sleep)
Telegram enforces an outbound limit of approximately 30 messages per second per bot. Pausing execution for
usleep(38000) (~38 milliseconds) caps delivery at ~26 messages per second, ensuring smooth delivery without triggering HTTP 429 Too Many Requests or account throttling.
Botlify Cloud Runtime
Credentials are auto-injected in
Credentials are auto-injected in
.env — always load them with getenv(): BOT_TOKEN, ADMIN_CHAT_ID, BOT_USERNAME. Main database: database.db (SQLite, WAL mode). Runtime errors: error.log. Quick test: send to $ADMIN_CHAT_ID. Full details: Runtime Reference.