Waiting for a text reply with a Facebook messenger bot
<p>I am writing a Facebook messenger bot and am trying to store a text reply after a postback. What I mean by this is I have a message that sends a post back and depending on what option they choose, they can type a message back and I store that text. The problem is I only want to store this text after they select an option for the post back message. Also the text can be anything, so I can't write an if statement for it. </p>

<p>Here is my code: </p>

<pre><code>app.post('/', function (req, res) {
  messaging_events = req.body.entry[0].messaging;
  for (i = 0; i &lt; messaging_events.length; i++) {

    event = req.body.entry[0].messaging[i];
    sender = event.sender.id;

    if (event.message &amp;&amp; event.message.text) {
      text = event.message.text;

      if (text == "Start") {
        sendTextMessage(sender, "Hey User! I'm a bot");
      }
    }

    else if (event.postback) {
      // These are for chosing availibility
      if (JSON.stringify(event.postback) == '{"payload":"postback"}') {
        setTextMessage(sender, "Postback recieved");
      }
    }
}
</code></pre>

<p>Everything is set up and running. But when the postback is received I want to wait for a reply from the user before finishing so I can save the text. Like I said earlier it can be anything meaning I can't just write an if statement like I did with "Start". I also only want to save the text after they click the postback button.</p>

<p>I was thinking about adding a while loop and waiting for text to be received before finishing the postback function but couldn't figure it out.</p>

<p>So how would I wait for text after I sent a message with a postback?</p>

<p>Any help is appreciated, thanks!</p>