I’m trying to send a video note to multiple Telegram users using the Telegram Bot API, but I’m encountering an issue where the first request succeeds and all subsequent requests return a 404 “Not Found” error. Here’s the PHP code I’m using to send these video notes:
$apiURLBase = "https://api.telegram.org/bot<YourBotToken>/";
$selectedUsers = ['111111111', '2222222222']; // Example chat IDs
$originalVideoPath = 'path_to_your_video.mp4';
foreach ($selectedUsers as $chatId) {
$uniqueFilePath = 'video_notes/' . uniqid() . '.mp4';
copy($originalVideoPath, $uniqueFilePath); // Ensure a unique file for each request
$apiURL = $apiURLBase . "sendVideoNote";
$video_note = new CURLFile($uniqueFilePath);
$data = [
'chat_id' => $chatId,
'video_note' => $video_note
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
unlink($uniqueFilePath); // Clean up the temporary file
echo "Response for chat_id $chatId: " . $output . "<br>";
}
Expected behavior:
I expect the video note to be sent to all users in the $selectedUsers
array without any issues.
Actual behavior:
The first user in the array receives the video note successfully, but for the second user, I receive the following response from the Telegram API:
{“ok”:false,”error_code”:404,”description”:”Not Found”}
Additional details:
The video files are ensured to be unique for each request by copying them to a new file with a unique name.
The problem persists even after adding a delay between requests using sleep(1);
.
All other parameters and settings (such as API URLs, bot token, etc.) have been double-checked for accuracy.
Could anyone help identify why subsequent requests are failing and how to fix this issue?
1