0

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

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.

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>";
  }
}
0stone0
  • 34,288
  • 4
  • 39
  • 64
Holger
  • 31
  • 4

2 Answers2

0

I more or less found the answer now to my own question: I haven't found a solution for the inline_keyboard. If you comment the keyboard feature out and only use the link in the "text" paramater --> Then telegram is not asking for a extra confirmation to open the link. See upated code below. So issue solved. At least for me.

  $params = [
     'chat_id'=>chatId,
     'text'=> 'open this link: 192.168.1.1/test.php',
     //'reply_markup' => @$encodedKeyboard,
     //'one_time_keyboard' => $setting,
     'parse_mode'=> 'Markdown'
  ];
Holger
  • 31
  • 4
0

I'm a bit late to the party. But it might help someone. The popup for me was shown because my web app was redirecting to a different url then configured for web_app url on page load. Using the redirection url directly solved the problem for me. For. e.g. https://example.com => https://example.com/login

Dev
  • 1