Skip to content Skip to sidebar Skip to footer

Run Function Asynchronously In Google Apps Script

I'm making a Slack bot that calls a GAS function. Everything is working except Slack shows an error message because it only waits 3 seconds for a response when calling an API. Can

Solution 1:

Promises doesn't work. Use triggers instead:

function doPost(e) {
  runAfter1s('everyDay2');
  return ContentService.createTextOutput('thinking...🧘');
}

const runAfter1s = func =>
  ScriptApp.newTrigger(func)
    .timeBased()
    .after(1000)
    .create();

Make sure to delete the created trigger inside everyDay2 after being triggered.

Post a Comment for "Run Function Asynchronously In Google Apps Script"