How can I make my Google App Script wait for an answer in telegram bot then run the if statement?

How do I make my google app script wait for an answer in telegram bot and run my IF statement afterwards?

my idea of the code is;
When I type /survey, it will run the following code which will post a question, how are you? The script will wait for me to type any text, afterwards run my IF statement afterward I typed an answer.

Hope you are able to help and thanks in advanced!

function survey(data){
  var Q1 = {
    'chat_id': data.message.chat.id,
    'text': 'how are you?'
  }
  var method = 'sendMessage';
  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'payload' : JSON.stringify(Q1)
  }
  var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + telegramToken + '/' + method, options);

var text = data.message.text;
if(text == ""){
   currentstep = '3'; //need help here
}

Source: Ask Javascript Questions

LEAVE A COMMENT