【问题标题】:Any idea why my doPost function isn't able to read my start(data) function知道为什么我的 doPost 函数无法读取我的 start(data) 函数
【发布时间】:2021-08-18 01:28:33
【问题描述】:

我正在尝试从谷歌应用脚​​本向我的电报机器人发送问题,但现在当我向电报机器人键入 /start 时,我的代码似乎没有执行我的启动功能。请指教。

function start(data) {
    var reply = {
    'text': "Please type /survey to start using it's service.",
    'parse_mode': 'Markdown',
    'disable_web_page_preview': true
        };
  var method = 'sendMessage.';
  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'payload' : JSON.stringify(reply)
  };
  var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + telegramToken + '/' + method, 
  options);
}

function doPost(e){
    var data = JSON.parse(e.postData.contents);
    var text = data.message.text;
  
    if(text == '/start'){
        start(data);
    } else if (text == '/survey' || text == '/survey') {
        survey(data);
    } else {
        invalid(data);
    }
}

【问题讨论】:

    标签: google-apps-script telegram-bot


    【解决方案1】:

    我对google-apps-script没有太多经验,但是你需要添加chat_id。

    在你的情况下,你可以从data.message.chat.id获取聊天ID

    这是一个示例网址:

    https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Please type /survey to start using it's service.&parse_mode=Markdown&disable_web_page_preview=true
    

    【讨论】:

      猜你喜欢
      • 2013-11-07
      • 2023-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多