View Categories

Cara Guna Integration Webhook Waapify ( Demo google Form )

< 1 min read

Webhook Waapify Script
function onSubmitForm(e) {
  var formData = e.values; // Get the form response values
  var headers = e.range.getSheet().getRange(1, 1, 1, e.range.getLastColumn()).getValues()[0]; // Get the header row
  var webhookUrl = PropertiesService.getScriptProperties().getProperty('webhookUrl');
  
  if (!webhookUrl) {
    // Prompt the user to set the webhook URL if it's not set
    Logger.log("Webhook URL is not set. Please set it using setWebhookUrl() function.");
    return;
  }
  
  // Create the payload to send to the webhook
  var payload = {};
  for (var i = 0; i < headers.length; i++) {
    payload[headers[i]] = formData[i]; // Associate each response value with its corresponding header (row name)
  }
  
  // Send the payload to the webhook URL
  var options = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify(payload)
  };
  
  UrlFetchApp.fetch(webhookUrl, options);
}

function setWebhookUrl(url) {
  PropertiesService.getScriptProperties().setProperty('webhookUrl', url);
}