title: Google script: take telegram message and write to a cell
body: <p>I wrote this little script to dump messages log and write to a specific sheet cell</p>
  <p>It worked for some time, then all of a sudden decided not to work anymore. I think there's a bug in google script as even after modifying the code several time I still got the same old message dumps on my phone</p>
  <p>it ought to dump my message to sheet Outputs, and date and time of message to sheet telegram. Atm nothing is working</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var token = "CENSORED"; 
  var telegramUrl = "https://api.telegram.org/bot" + token; 
  var webAppUrl = "https://script.google.com/macros/s/AKfycbwZD1K7Q0q6yXVgIVdl3w3PKISmTBBH89zKF1BQdkOgyDzJu4s/exec"; 
  var ss = SpreadsheetApp.openById("CENSORED");
  
  function setWebhook() {
    var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
    //var response = UrlFetchApp.fetch(url);
  }
  
  function sendMessage(chat_id, text) {
    var url = telegramUrl + "/sendMessage?chat_id=" + chat_id + "&amp;text="+ text;
    //var response = UrlFetchApp.fetch(url);
  }
  
  
  function doPost(e) {
    var contents = JSON.parse(e.postData.contents);
    var chat_id = contents.message.from.id; 
    var user = contents.message.chat.first_name;
    
    sendMessage(chat_id, answer);
    var answer = "Hi " + user;
    sendMessage(chat_id, answer);
    
    var text = contents.message.text;
    SpreadsheetApp.openById("CENSORED").getSheetByName("telegram").appendRow([new Date(), chat_id, user, text]);
  
    var sheet = ss.getSheetByName("Outputs");
    var cell =  sheet.getRange("G45");
    cell.setValue(text); // write to cell message log</code></pre>
  </div>
  </div>
  </p>