This is my first post. Hope I get help here. Thanks for reading.
Short version: When i send a link to my bot, Telegram show a popup "Open this link .... ?" before open the link. I want to avoid that. Any ideas? See also questions
- Force closure of the popup on telegram “Open this link?”
- Is there a way to send links with telegram bot and show no alert on tap/click?
Long Version: I have a telegram bot, which I'm sending a message from a Raspberry pi via PHP. Background is some status notification on my smart home. Please see code below.
I'm send a telegram message with a link attached with an inline keyboard, so that I can provide a certain responds to my smart home. In other questions I saw that this is connected to the "parse_mode" html. I tried different modes, however the result is always the same. Also checked the telegram api documentation for help.
- https://core.telegram.org/bots/api#formatting-options
- https://core.telegram.org/bots/api#sendmessage
As this is just for myself and running only locally, I don't care about cosmetics or security.
I would appreciate any help or new ideas.
Here is my code for reference
function telegram($message,$maschine) {
if (!isset($maschine)) {
echo "no Maschine for telegram";
exit;
}
if (!isset($message)) {
echo "no Message for telegram"; exit;
}
$website = "https://api.telegram.org/bot" . botToken;
$Keyboard = [
'inline_keyboard' =>
[
[
[
'text' => "test",
'url' => '192.168.1.1/test.php,
]
]
]
];
$encodedKeyboard = json_encode($Keyboard);
$params = [
'chat_id'=>chatId,
'text'=> $message,
'reply_markup' => @$encodedKeyboard,
'one_time_keyboard' => true,
'parse_mode'=> 'html'
];
$ch = curl_init($website . '/sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$jsonresult = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($jsonresult['ok']==false) {
echo "Telegram Error Code: " . $jsonresult['error_code'] . " - ". $jsonresult['description'] . "<br>";
} else {
echo "Telegram message send<br>";
}
}