a couple months ago i'd published a few tips on building a reliable, secure & scalable architecture using apps script but it wasn't until much later that i'd actually gotten a neat little use-case to demo that πŸ˜‰
aside: thanks to martin hawksey for sharing the problem statement!

context

i've always been a huge fan of being able to work with webhooks and spreadsheets - you might recall the subtle credit from here - and this post is -

  1. to bolster the fact that one can build / create webhooks using apps script (don't know why google's official docs don't mention using web apps as webhooks πŸ€·πŸ½β€β™€οΈ)
  2. the needle on reliability can be moved by using some of the underrated apps script features & functions
  3. i'm way too late on coming around to publish this post as everything that i'll be sharing now (it's 17 nov, 2020 at the time of drafting this post) is a result of something that took place in late-july, 2020

problem statement

I was just playing with webcaptioner.com which lets you specify a webhook url. I was experimenting with adding captions to a Google Doc in realtime but Apps Script couldn't keep up dropping ~20% of the captions sent via the hook

try reading πŸ‘†πŸ½ in martin's voice and in case you don't know who that is or how they sound, give totally unscripted a watch!

prior reading

codebase

this took roughly about 10-lines of code to design -

var lock = LockService.getScriptLock();

function doPost(e) {
  lock.waitLock(30000);  
  var params = JSON.parse(e.postData.contents);
  var transcript = params.transcript;
  var sequence = params.sequence;
  SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().appendRow([transcript,sequence]);
  lock.releaseLock();
  return ContentService.createTextOutput("transcript: " + transcript + "; sequence: " + sequence);
}
code.gs

demo

web captioner, webhooks and google apps script