【问题标题】:Create hyperlink in Telegram message sent by bot via script / google sheets在机器人通过脚本/谷歌表发送的电报消息中创建超链接
【发布时间】:2021-01-29 09:38:53
【问题描述】:

我当前的脚本是:

function EnviarTelegram(botSecret, chatId, body) {
var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
}

我用来发送消息的 Google 表格中的公式是:

=EnviarTelegram("Code to Bot","Code to ChatId","Created Message")

我希望能够创建以下消息:

"Full list of games tomorrow

Click here to access"

Click here to access 我希望有一个超链接,例如:www.google.com/testtesttesttest

有什么方法可以调整脚本或为此创建的文本?

【问题讨论】:

    标签: google-apps-script google-sheets telegram telegram-bot


    【解决方案1】:

    在您的查询参数中,使用了parse_mode=HTML。所以我认为在这种情况下,HTML标签可以用于text。当你想使用=EnviarTelegram("Code to Bot","Code to ChatId","Created Message")时,下面的修改怎么样?

    发件人:

    =EnviarTelegram("Code to Bot","Code to ChatId","Created Message")
    

    收件人:

    =EnviarTelegram("Code to Bot","Code to ChatId","Full list of games tomorrow\n\n<a href='https://www.google.com/testtesttesttest'>Click here to access</a>")
    

    【讨论】:

    • 嗨@Tanaike,跟随错误"Exception: Request failed for https://api.telegram.org returned code 400. Truncated server response: {"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Unsupported start tag \"br\" at byte offset 27"}"
    • @Brondby IF 感谢您的回复。我带来的不便表示歉意。从你的错误信息来看,在这种情况下,将Full list of games tomorrow&lt;br&gt;&lt;br&gt;&lt;a href='https://www.google.com/testtesttesttest'&gt;Click here to access&lt;/a&gt; 修改为Full list of games tomorrow\n\n&lt;a href='https://www.google.com/testtesttesttest'&gt;Click here to access&lt;/a&gt; 怎么样?还是Full list of games tomorrow%0A%0A&lt;a href='https://www.google.com/testtesttesttest'&gt;Click here to access&lt;/a&gt;
    • 嗨@Tanaike 这是完美的搭档,对空格线进行一次编辑:/n/n 双击ALT+ENTER
    • @Brondby IF 感谢您再次回复和测试。我很高兴你的问题得到了解决。根据您的回复,我更新了我的答案。
    猜你喜欢
    • 2021-08-20
    • 1970-01-01
    • 2016-05-03
    • 2017-03-19
    • 2016-03-11
    • 1970-01-01
    • 2023-03-22
    • 2020-02-05
    • 2017-09-01
    相关资源
    最近更新 更多