【问题标题】:Attach image to the text sent by the Telegram bot via google sheets将图像附加到电报机器人通过谷歌表发送的文本
【发布时间】:2021-01-30 11:11:38
【问题描述】:

我当前的脚本是:

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","Lista de jogos na TV 

<a href='https://www.google.com/testtesttesttest'>CLIQUE AQUI E ACESSE JÁ</a>")

我希望能够创建一条带有图像连接到文本的消息,如下所示:

我要使用的图片链接是这样的:
https://drive.google.com/file/d/testestest

有没有办法把图片附加到文字上?

【问题讨论】:

  • 当你的共享图片使用时,例如=EnviarTelegram("Code to Bot","Code to ChatId","sample text 1\n&lt;img src='https://drive.google.com/uc?id=1IztJm_pxa-ZaPfg7Ki9NU2z9vmqczjDy&amp;export=download'&gt;\nsample text 2")使用parse_mode=markdown?或者,=EnviarTelegram("Code to Bot","Code to ChatId","sample text 1 ![](https://drive.google.com/uc?id=1IztJm_pxa-ZaPfg7Ki9NU2z9vmqczjDy&amp;export=download) sample text 2") 使用 parse_mode=markdown 怎么样?但我不确定这些是否与您期望的方向相同。所以我提出它作为评论。对此我深表歉意。

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


【解决方案1】:

您正在使用/sendMessage 方法。

如果您想发送带有可选标题的图片,请使用sendPhoto 方法。

你的函数可能会变成这样;

function EnviarTelegram(botSecret, chatId, photoUrl, caption) {
    var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendPhoto?caption=" + encodeURIComponent(caption) + "&photo=" + encodeURIComponent(photoUrl) + "&chat_id=" + chatId + "&parse_mode=HTML");
}
=EnviarTelegram("Code to Bot","Code to ChatId", "https://example.com/image.jog", "Lista de jogos na TV 

<a href='https://www.google.com/testtesttesttest'>CLIQUE AQUI E ACESSE JÁ</a>")

【讨论】:

  • 感谢朋友的支持。我已经在answear中发现了两个小错误,把caption改成bodyLista之前,你需要在公式中有一个",结果是"Lista...。如果您已经想通过修改此详细信息来编辑答案。
  • 很高兴你把它整理好了!忘记替换那些参数名称,缺少" 是由复制/粘贴错误引起的。我已经在我的回答中修正了这些错误!
  • 顺便说一句;如果有人answers your question,请考虑upvotingaccepting 的答案。这向更广泛的社区表明您找到了解决方案,并为回答者和您自己赢得了一些声誉。
  • 是的,我的朋友。我会投票并将其标记为最佳答案,我只是在进行测试以确保它运行良好并且已解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
  • 2016-02-24
相关资源
最近更新 更多