I cant figure out why link preview of links sent by bot will not show even if ‘disable_web_page_preview’ is true.
$config = json_decode(file_get_contents('config.json'), true);
$botToken = $config['bot_token'];
$chatId = $config['chat_id'];
$link = "https://github.com/FFmpeg/FFmpeg"; // Der zu testende Link
// Funktion zum Senden einer Nachricht an Telegram
function sendMessage($botToken, $chatId, $message) {
$url = "https://api.telegram.org/bot$botToken/sendMessage";
$postFields = [
'chat_id' => $chatId,
'text' => $message,
'disable_web_page_preview' => true // Sicherstellen, dass die Vorschau aktiviert ist
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($result === false) {
$error = curl_error($ch);
curl_close($ch);
return ['success' => false, 'error' => $error];
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ['success' => true, 'http_code' => $httpCode, 'response' => $result];
}
}
$response = sendMessage($botToken, $chatId, $link);
if ($response['success']) {
echo "Nachricht erfolgreich gesendet. HTTP-Code: " . $response['http_code'];
echo "Antwort: " . $response['response'];
} else {
echo "Fehler beim Senden der Nachricht: " . $response['error'];
}