电报机器人必须在 force_reply
处于事件状态的情况下向用户发送消息。
在地址栏中插入链接有效;机器人发送消息并且answer
功能已处于事件状态。由 Google Apps 脚本中的代码生成的相同链接不起作用;机器人不会发送任何内容。
工作链接:(我用 BOT_TOKEN
和 CHAT_ID
替换了我的机器人 ID 和聊天 ID)
https://api.telegram.org/BOT_TOKEN/sendMessage?chat_id=CHAT_ID&text=force_replyTest&reply_markup={"force_reply":true}
生成链接的代码
var url = "https://api.telegram.org/bot" + token;
function sendText(idChat,text) {
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup={"force_reply":true}');
Logger.log(response.getContentText());
}
if(text == "/p"){
sendText(idChat,"force_reply test");
}
最佳答案
感谢@TheMaster 使用此代码
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup=' + encodeURIComponent('{"force_reply":true}'));
关于javascript - force_reply 在地址栏中工作,但在 Google Apps 脚本中的代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57695732/