Web captioner, webhooks and Google Apps Script

Push data from Web Captioner to Google Sheets via webhooks built using Apps Script.

Web captioner, webhooks and Google Apps Script
Web captioner, webhooks and Google Apps Script

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