如何使用 Telegram Bot 在消息中发送 url link 或显示打开 URL link 的按钮

How to send url link in the message using Telegram Bot or Show a button to open the URL link

Bot 的消息文本为:

点击打开URL

URL 是 http://www.example.com/

参考图片为:

有两种方法可以让用户选择在 bot-message 中打开 URL,如:

API 端点- https://api.telegram.org/bot{MENTION_YOUR_BOT_TOKEN*}/sendMessage

API 方法- GET

  1. 在消息中显示URL

用这个原始 JSON 数据命中 API-

{
    "chat_id" : MENTION_USER_CHAT_ID*,
    "text" : "Click to Open [URL](http://example.com)",
    "parse_mode" : "markdown"
}
  1. 在消息下方显示一个 URL 按钮

用这个原始 JSON 数据命中 API-

{
    "chat_id" : MENTION_USER_CHAT_ID*,
    "text" : "Click to Open URL",
    "parse_mode" : "markdown",
    "reply_markup" : {
        "inline_keyboard" : [
            [
                {
                    "text" : "Open link",
                    "url" : "http://example.com"
                }
            ]
        ]
   }
}

注意:根据您的数据替换 * 标记的变量。