Skip to content

Instantly share code, notes, and snippets.

@yogeshnarayanan
Last active August 21, 2023 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogeshnarayanan/5a27588052bd24d282de0343bbf1fbaf to your computer and use it in GitHub Desktop.
Save yogeshnarayanan/5a27588052bd24d282de0343bbf1fbaf to your computer and use it in GitHub Desktop.
Google Form <> Gallabox WhatsApp Template Message
const GENERIC_WEBHOOK_URL = "XXXXXXX";
// Pick the Webhook Url from
// https://app.gallabox.com/integration/genericWebhook
function sendPostRequest(e) {
var resp = {};
var itemResponses = e.response.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
var itemTitle = itemResponse.getItem().getTitle();
var specialCharsPattern = /[^a-zA-Z0-9]/g;
var parsedItemTitle = itemTitle.replace(specialCharsPattern, '_');
resp[parsedItemTitle] = itemResponse.getResponse();
}
Logger.log(JSON.stringify(resp));
var options = {
'method': 'post',
'contentType': 'application/json',
headers: {
'Accept': 'application/json'
},
'payload': JSON.stringify(resp)
};
var fetchResp = UrlFetchApp.fetch(GENERIC_WEBHOOK_URL, options);
Logger.log(fetchResp.getContentText());
}
// Add New Triggers
// Event: From form - On form submit
// Function: sendPostRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment