转换URL外观并由Telegram bot发送

问题描述 投票:0回答:1

我正在使用电报Bot从python脚本发送信息。

我向电报机器人发送消息的功能是:

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

我有两个问题:

  1. 当我使用其他变量时,一切正常。但是,发送URL变量,什么也没有发生,并且我没有收到任何消息
  2. 如何接收链接为“短名称链接”而不是整个链接?例如,接收“ Google”而不是“ www.google.com”吗?
python python-3.x telegram telegram-bot python-telegram-bot
1个回答
1
投票

1]markdownparseMode需要有效的markdown语法,我想您示例URL中的_会启动一个永远不会关闭的Markdown italic text,Telegram返回错误并且消息将不会发送。用parse_mode: HTML禁用此功能。 (html parsemode中没有parse_mode: HTML元素)

2)_markDown解析模式都提供了向消息添加超链接的选项;

HTML

HTML

MarkDown

<a href="https://www.google.com/">Google</a>
[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)") 中查看。

© www.soinside.com 2019 - 2024. All rights reserved.