Telegram API:电报上的弹出窗口“打开此链接?”如何避免?

发布于 2025-02-09 02:08:32 字数 2571 浏览 2 评论 0原文

这是我的第一篇文章。希望我在这里得到帮助。感谢您的阅读。

简短版本: 当我发送到机器人的链接时,电报显示弹出窗口“打开此链接....?”打开链接之前。 我想避免。有什么想法吗? 另请参阅问题

长版本: 我有一个电报机器人,我正在向Raspberry Pi发送消息 通过PHP。背景是我聪明的家中的一些状态通知。 请参阅下面的代码。

我正在发送带有内联键盘的链接的电报消息,以便我可以为我的智能家园提供一定的响应。 在其他问题中,我看到这连接到“ parse_mode” html。我尝试了不同的模式,但是结果总是相同的。 还检查了Telegram API文档以寻求帮助。

https://core.telegram.telegram.org/bots/api#sendmessage 仅适合我自己,只在本地运行,我不在乎化妆品或安全性。

感谢任何帮助或新想法。

这是我的代码供参考

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>";
  }
}

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>";
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像极了他 2025-02-16 02:08:32

我或多或少地找到了我自己问题的答案:
我还没有找到inline_keyboard的解决方案。
如果您评论键盘功能,并且仅使用“文本” paramater中的链接 - &gt;然后电报是不是要求提供额外的确认以打开链接。
请参阅下面的升级代码。
因此解决了问题。至少对我来说。

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

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'
  ];
甚是思念 2025-02-16 02:08:32

我参加聚会有点晚。但这可能会帮助某人。
显示了我的弹出窗口,因为我的Web应用程序正在重定向到其他URL,然后在页面加载上为Web_App URL配置。
使用重定向URL直接解决了我的问题。
为了。例如
https://example.com =&gt; https://example.com/login

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文