Voici la modification de votre code PHP pour publier la promotion dans tous les canaux de la liste, même s'il n'y a pas de photo. J'ai ajouté une boucle foreach pour cela. Voici le code mis à jour :
if (!empty($channels['channels'])) {
foreach ($channels['channels'] as $channel) {
$chat_id = $channel['chat_id'];
$username = $channel['username'];
// Obtenir le lien d'invitation
$api_url = "https://api.telegram.org/bot$token/exportChatInviteLink";
$data = ['chat_id' => $chat_id];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
curl_close($ch);
// Décoder la réponse JSON
$response_data = json_decode($response, true);
// Vérifier si la réponse contient une erreur
if (isset($response_data['ok']) && $response_data['ok'] === true) {
$invite_link = $response_data['result'];
// Obtenir la photo de profil et la description
$channel_info_url = "https://api.telegram.org/bot$token/getChat";
$channel_info_data = ['chat_id' => $chat_id];
$ch_info = curl_init();
curl_setopt($ch_info, CURLOPT_URL, $channel_info_url);
curl_setopt($ch_info, CURLOPT_POST, 1);
curl_setopt($ch_info, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_info, CURLOPT_POSTFIELDS, http_build_query($channel_info_data));
$channel_info_response = curl_exec($ch_info);
curl_close($ch_info);
$channel_info = json_decode($channel_info_response, true);
$description = $channel_info['result']['description'] ?? 'Aucune description disponible';
$photo = $channel_info['result']['photo'] ?? null;
// Créer le message HTML
$html_message = "<strong><a href=\"$invite_link\">REJOINDRE : $username</a></strong>\n";
$html_message .= "$description\n";
$html_message .= "<strong><a href=\"$invite_link\">ABONNE TOI A CE CANAL</a></strong>\n";
$html_message .= "\n \n \n<strong><a href=\"https://t.me/wooootopi\">cliquez ici pour ajouter tes canaux a la CROSS PROMO afin d'augmenter tes abonnés (minimum 500 abonnés)</a></strong>\n";
// Envoyer la photo et le message dans le canal
if ($photo) {
$photo_file_id = $photo['small_file_id']; // Utiliser le bon ID ici
$api_url_send = "https://api.telegram.org/bot$token/sendPhoto";
$data_send = [
'chat_id' => $chat_id,
'photo' => $photo_file_id,
'caption' => $html_message,
'parse_mode' => 'HTML',
];
$ch_send = curl_init();
curl_setopt($ch_send, CURLOPT_URL, $api_url_send);
curl_setopt($ch_send, CURLOPT_POST, 1);
curl_setopt($ch_send, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_send, CURLOPT_POSTFIELDS, http_build_query($data_send));
$response_send = curl_exec($ch_send);
curl_close($ch_send);
$messages['messages7'][$chat_id] = json_decode($response_send, true)['result']['message_id'];
echo "Message envoyé avec ID : {$messages['messages7'][$chat_id]}\n";
} else {
// Envoyer uniquement le message si pas de photo
$api_url_send = "https://api.telegram.org/bot$token/sendMessage";
$data_send = [
'chat_id' => $chat_id,
'text' => $html_message,
'parse_mode' => 'HTML',
];
$ch_send = curl_init();
curl_setopt($ch_send, CURLOPT_URL, $api_url_send);
curl_setopt($ch_send, CURLOPT_POST, 1);
curl_setopt($ch_send, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_send, CURLOPT_POSTFIELDS, http_build_query($data_send));
$response_send = curl_exec($ch_send);
curl_close($ch_send);
echo "Message envoyé sans photo pour le canal : $username\n";
}
} else {
echo "Erreur lors de l'obtention du lien d'invitation pour le canal : $username\n";
}
}
} else {
echo "Aucun canal disponible.\n";
}
Dans ce code, j'ai ajouté une boucle foreach qui parcourt tous les canaux dans $channels['channels'], et chaque canal reçoit un message, qu'il ait une photo ou non. Si une photo est disponible, elle sera envoyée avec le message, sinon le message sera envoyé sans photo.