Skip to content

Instantly share code, notes, and snippets.

@anilahir
Forked from lifehome/webhook.gs
Last active December 4, 2020 07:24
Show Gist options
  • Select an option

  • Save anilahir/1e3f902eb4b46dcdd90bcfe89f837f4c to your computer and use it in GitHub Desktop.

Select an option

Save anilahir/1e3f902eb4b46dcdd90bcfe89f837f4c to your computer and use it in GitHub Desktop.

Revisions

  1. anilahir revised this gist Dec 4, 2020. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions webhook.gs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    var POST_URL = "http://localhost:3000";

    function onFormSubmit(e) {

    var data = {
    "form": {
    "id": e.source.getId(),
    @@ -17,7 +20,7 @@ function onFormSubmit(e) {
    }, this).reduce(function(r, y) {
    r[y.h] = y.k;
    return r
    }, {});
    }, {}),
    },
    };

    @@ -27,5 +30,5 @@ function onFormSubmit(e) {
    contentType: "application/json; charset=utf-8",
    };

    UrlFetchApp.fetch("http://n07-dynamic.lifeho.me:3000", options);
    };
    UrlFetchApp.fetch(POST_URL, options);
    };
  2. @lifehome lifehome created this gist Aug 24, 2016.
    31 changes: 31 additions & 0 deletions webhook.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    function onFormSubmit(e) {
    var data = {
    "form": {
    "id": e.source.getId(),
    "title": e.source.getTitle() ? e.source.getTitle() : "Untitled Form",
    "is_private": e.source.requiresLogin(),
    "is_published": e.source.isAcceptingResponses(),
    },
    "response": {
    "id": e.response.getId(),
    "timestamp": e.response.getTimestamp(),
    "payload": e.response.getItemResponses().map(function(y) {
    return {
    h: y.getItem().getTitle(),
    k: y.getResponse()
    }
    }, this).reduce(function(r, y) {
    r[y.h] = y.k;
    return r
    }, {});
    },
    };

    var options = {
    method: "post",
    payload: JSON.stringify(data, null, 2),
    contentType: "application/json; charset=utf-8",
    };

    UrlFetchApp.fetch("http://n07-dynamic.lifeho.me:3000", options);
    };