【发布时间】:2019-12-01 16:43:01
【问题描述】:
我想使用 Google App Script 让 Telegram Bot 在聊天中发布消息。当我使用这行代码时,效果很好:
var message = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + chat_id_Testgruppe + "&text=HelloWorld");
但如果我用这样的变量替换“HelloWorld”:
var body = threads[i].getMessages().pop().getPlainBody(); // Gets the message-String from a Gmail-Thread
var message = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + chat_id_Testgruppe + "&text=" + body);
然后我得到一个无效的参数错误,即使显示为 fetch 函数的非法参数的参数有效,如果我将它复制并粘贴到我的浏览器。
【问题讨论】:
-
如果不了解您的其他变量,我们将无法解决此问题。
-
添加了我的 body 声明,另外两个变量是硬编码的字符串,它们在其他上下文中正常工作
-
如果您执行
Logger.log(body);,会记录什么?你也试过使用body.toString()吗? -
见 this more general question 以及 this one -- 在
body上尝试encodeURIcomponent();还要记住there may be issues with the length of the message