【问题标题】:Send a scheduled message in my telegram bot linked to a google spreadsheet在链接到谷歌电子表格的电报机器人中发送预定消息
【发布时间】:2021-08-20 04:26:41
【问题描述】:

我使用此视频中的指导构建了一个电报机器人:

https://www.youtube.com/watch?v=mKSXd_od4Lg&t=348s

有没有什么方法可以编辑 sendText 函数,让机器人在设定的时间发送消息?

function sendText(id,text){
  var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
  var response = UrlFetchApp.fetch(url);
}

谢谢!

【问题讨论】:

  • 你的意思是像使用时间驱动触发器?

标签: javascript google-sheets bots telegram telegram-bot


【解决方案1】:

您可以在代码中包含对 ClockTrigger 的调用

为此,您需要将idtext 临时存储在script properties 中,因为您无法将参数传递给时钟触发器。

示例:


const props = PropertiesService.getScriptProperties();

function sendText(id,text){
  props.setProperty('id', JSON.stringify(id));
  props.setProperty('text', text);
  ScriptApp.newTrigger("fetch")
    .timeBased()
    .after(10 * 60 * 1000)
    .create();
}

function fetch(){
  var id = JSON.parse(props.getProperty('id'));
  va text =  props.getProperty('text');
  var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
  var response = UrlFetchApp.fetch(url);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-19
    • 2016-03-11
    • 2017-09-01
    • 2021-09-10
    • 2020-08-25
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多