-2

How can I get the previous message in messenger chatbot? So that my bot can understand what the user is saying and reply on it. As an example,

(News bot) USER : Show me news about donald trump
BOT : Here's 3 sir!.... Would you like more?
USER: Yes.

So, when user says yes the bot has to know that he wants news from donald trump. So, I need that bot remember about donald trump.

How to get the previous message or how to remember the donald trump phrase?

1 Answers1

0

I wouldn't suggest looking back to the previous message because this can lead to unexpected results. For example, what if the user unexpectedly sends two messages - how would the bot know what message to look for?

Instead, treat the conversation as a series of states that you cache server side. Using this example, when the user sends 'Show me news about donald trump' you should cache something like '{last_query: 'donald trump'} on your server. Then when the user asks for more articles, you can retrieve the query from the most recent conversation state.

amuramoto
  • 2,838
  • 1
  • 11
  • 15
  • If you DO want to get the previous message, you can use the /{conversation-id}/messages endpoint of the graph api https://developers.facebook.com/docs/graph-api/reference/v2.12/conversation/messages – amuramoto May 23 '18 at 17:42