这是我的第一篇帖子。希望我能在这里得到帮助。感谢您的阅读。
短版本:当我发送一个链接到我的机器人,电报显示一个弹出的“打开这个链接. ?”在打开链接之前。我想避免那样做。有什么想法吗?另见问题
长版本:我有一个电报机器人,我正在通过从一个Raspberry pi发送消息。背景是我的智能家居的一些状态通知。请参阅下面的代码。
我发送了一封电报信息,并附上了一个内置键盘的链接,这样我就可以为我的智能家居提供一定的响应。在其他问题中,我看到这是连接到"parse_mode“html。我尝试过不同的模式,但是结果总是一样的。还检查了电报api文档以获得帮助。
因为这只是为了我自己,而且只在当地运行,我不关心化妆品或安全。
如果有任何帮助或新想法,我将不胜感激。
这是我的代码供参考
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>";
}
}
发布于 2022-06-21 11:49:52
我现在或多或少找到了我自己的问题的答案:我还没有找到inline_keyboard的解决方案。如果您将键盘功能注释掉,并且只使用"text“参数中的链接->则电报是,而不是,它要求提供额外的确认来打开链接。请参阅下面的向上代码。所以问题解决了。至少对我来说。
$params = [
'chat_id'=>chatId,
'text'=> 'open this link: 192.168.1.1/test.php',
//'reply_markup' => @$encodedKeyboard,
//'one_time_keyboard' => $setting,
'parse_mode'=> 'Markdown'
];
https://stackoverflow.com/questions/72688326
复制相似问题