变换 URL 外观并通过 Telegram 机器人发送
Transform URL appearance and send it by Telegram bot
我正在使用 Telegram Bot 从 python 脚本发送信息。
我向 Telegram Bot 发送消息的功能是:
def telegram_bot_sendtext(bot_message):
bot_token = 'token'
bot_chatID = 'id'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()
其中一个信息是一个名为"URL"的变量,其中包含URL,例如这个:https://www.sezane.com/fr/product/collection-printemps-all-0804/robe-will?cou_Id=859
我有两个问题:
- 当我使用其他变量时,一切正常。但是,发送 URL 变量,没有任何反应,我也没有收到任何消息
- 我怎样才能将 link 作为 "link with short name" 而不是完整的 link 接收?例如,接收 "Google" 而不是 "www.google.com" ?
1) markdown
parseMode 需要有效的 markdown 语法,我猜你的例子中的 _
url 启动了 Markdown italic text which is never closed, Telegram returns a error and the message will not be send. Use parse_mode: HTML
来禁用它。 (html 解析模式中没有 _
个元素)
2) markDown
和 HTML
解析模式都提供了向消息添加超链接的选项;
HTML
<a href="https://www.google.com/">Google</a>
MarkDown
[Google](https://www.google.com/)
telegram_bot_sendtext("Please press this [link](https://www.sezane.com/fr/product/collection-printemps-all-0804/robe-will?cou_Id=859)")
更多信息,请看documentation。
我正在使用 Telegram Bot 从 python 脚本发送信息。
我向 Telegram Bot 发送消息的功能是:
def telegram_bot_sendtext(bot_message):
bot_token = 'token'
bot_chatID = 'id'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
return response.json()
其中一个信息是一个名为"URL"的变量,其中包含URL,例如这个:https://www.sezane.com/fr/product/collection-printemps-all-0804/robe-will?cou_Id=859
我有两个问题:
- 当我使用其他变量时,一切正常。但是,发送 URL 变量,没有任何反应,我也没有收到任何消息
- 我怎样才能将 link 作为 "link with short name" 而不是完整的 link 接收?例如,接收 "Google" 而不是 "www.google.com" ?
1) markdown
parseMode 需要有效的 markdown 语法,我猜你的例子中的 _
url 启动了 Markdown italic text which is never closed, Telegram returns a error and the message will not be send. Use parse_mode: HTML
来禁用它。 (html 解析模式中没有 _
个元素)
2) markDown
和 HTML
解析模式都提供了向消息添加超链接的选项;
HTML
<a href="https://www.google.com/">Google</a>
MarkDown
[Google](https://www.google.com/)
telegram_bot_sendtext("Please press this [link](https://www.sezane.com/fr/product/collection-printemps-all-0804/robe-will?cou_Id=859)")
更多信息,请看documentation。