title: How do I send an http POST response that will work with chatbot using GAS
body: <p>I am trying to create a webhook for a chatbot to pull information from Google Sheets. Since Google has Google Apps Script that easily works with sheets, I thought I would try running my scripts there. I have managed to work a GET request as required by chatbot returning a string. But I cannot seem to connect the POST request to relay information.I have logged the request and response which look correct and make me think my script is running smoothly, but that there must be something wrong in the http connection.
  The problems I am finding are that GAS sends back a redirect which could be the problem. Is there a way around this to just send a JSON string response?
  Also, when performing the POST request on chatbot, I get an error:</p>
  
  <blockquote>
    <p>Webhook "GAS Order Data" was not executed
        Request failed with status code 405</p>
  </blockquote>
  
  <p>I looked up 405 error and says that </p>
  
  <blockquote>
    <p>Error 405 : HTTP method is not allowed by a web server for a requested URL</p>
  </blockquote>
  
  <p>What would be a way to know where my error is?
  my other option is aws lambda, but haven't gotten that to work either.</p>
  
  <p>This is my doPost function. Everything runs perfectly. It should return a string, but ContentService actually replies with a 302 redirect (tested with talend api tester). My log functions save information to a log sheet since I can't use the script log.</p>
  
  <pre><code>//get order information from an order id
  function doPost(e) {
    startLog(['- NEW POST REQUEST - v'+ver, new Date()]);//e.postData.contents
    var content=JSON.parse(e.postData.contents);
    addLog(JSON.stringify(content));//log input
    if(!verify(e.parameter.token)){//part of chatbot to validate url
      addLog("Token Invalid");
      return ContentService.createTextOutput("Token Invalid");
    }
  
    var response = processPost(content.result.resolvedQuery);//analyze data (return json object)
    addLog(JSON.stringify(response));
    return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.TEXT);
  }
  </code></pre>