Telegram API:电报上的弹出窗口“打开此链接?”如何避免?
这是我的第一篇文章。希望我在这里得到帮助。感谢您的阅读。
简短版本: 当我发送到机器人的链接时,电报显示弹出窗口“打开此链接....?”打开链接之前。 我想避免。有什么想法吗? 另请参阅问题
长版本: 我有一个电报机器人,我正在向Raspberry Pi发送消息 通过PHP。背景是我聪明的家中的一些状态通知。 请参阅下面的代码。
我正在发送带有内联键盘的链接的电报消息,以便我可以为我的智能家园提供一定的响应。 在其他问题中,我看到这连接到“ parse_mode” html。我尝试了不同的模式,但是结果总是相同的。 还检查了Telegram API文档以寻求帮助。
- https://core.telegram.telegram.org/bots/bots/api#formatting-formatting-formatting-formatting-options
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
- 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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我或多或少地找到了我自己问题的答案:
我还没有找到inline_keyboard的解决方案。
如果您评论键盘功能,并且仅使用“文本” paramater中的链接 - &gt;然后电报是不是要求提供额外的确认以打开链接。
请参阅下面的升级代码。
因此解决了问题。至少对我来说。
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.
我参加聚会有点晚。但这可能会帮助某人。
显示了我的弹出窗口,因为我的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