title: How to get previous message's text with a Telegram bot?
body: <p>I am building a reply keyboard oriented bot using java and I need it to treat differently two scenarios in which the latest message's text is the same based on the text of the previous message. How can I get or store the text of the previous message as a public variable?</p>
  
  <p>My conceptual modelling is as follows:</p>
  
  <p>I have a large If-Else-If statement where the condition for each If block goes along the lines of <code>if(update.hasMessage() &amp;&amp; messageText.equals("aaa"))</code> where "aaa" is some text that appears on a reply keyboard that popped up for the user earlier (since the keyboard buttons send the string on them as text and there is no option for a button press event in Telegram bot's api). messageText is defined as update.getMessage().getText().</p>
  
  <p>I want the code to treat differently two scenarios in which messageText is the same based on the message that came before it. <code>if(update.hasMessage() &amp;&amp; messageText.equals("aaa") &amp;&amp; previousMessage.equals("bbb")) { } else if(update.hasMessage() &amp;&amp; messageText.equals("aaa") &amp;&amp; previousMessage.equals("ccc")){}</code>. How can I store the previous message without it getting updated upon a new message recieved?</p>