0

Currently, I've a Python code. That process the incomming message from a Facebook messenger User. But this is a pasive chat against the chat bot. I'd like to do the following.

User: Pay
Bot: Please type the username of the person you want to pay.
User: eddwinpaz
Bot: Please type the amount you want to send.
User: 100.00
Bot: Are you sure you want to send 100.00 to Eddwinpaz?

Some how if the user in this conversation does not answers on the exact order the app wont be able to do the payment. There is a way to get the previous text and see if its answering in the correct order. Or give some logic in order to store in a session_array[sender_id,username,amount] and after I send the user a Button(Yes,No) I can actually perform the payment.

Because I need to store on the server the values regarding a question. Other example is.

Bot: what is your email?
User: myemail@gmail.com
Bot: your email has been saved! 
Eddwin Paz
  • 2,842
  • 4
  • 28
  • 48
  • What about input validation? For instance, a first answer has to be a valid username that exists in the payment system? The second is a valid digit, etc – taras May 21 '17 at 03:44
  • but somehow I need to know the context. Because I only get the answer but Don't get the context. I can get a Yes but yes from what? :( Im trying to store this on a session but still from what question does that text comes from? html forms hold name="myfield" and value="myvalue" – Eddwin Paz May 21 '17 at 03:52
  • If I make a question to the bot I can answer it. like whats the weather.. but not the other way around. Because bot knows the context but I do not. – Eddwin Paz May 21 '17 at 03:53
  • I am sorry, it is very hard to understand what is the problem without an experience of FB bots creation unless there is more information about architecture. Could you please describe a request/response format of communication between a user, a bot and a server? – taras May 21 '17 at 04:16
  • @Taras User types Pay and facebook sends this pay text message to my server, after this I parse a if condition if "pay" in message_text: then I execute a series of questions like you see above. the issue is that he could answer anything and I wont be able to follow the proper context I need to find a way to get the previous message of "what i asked the user" so I could actualy send him the next question and validate the information properly. So far its impossible for me. – Eddwin Paz May 21 '17 at 04:21
  • You get the user ID in every single request from Facebook – WizKid May 21 '17 at 04:27

1 Answers1

2

Facebook does not provide a way to do this, it is up to you to handle state in your code.

This is what bot frameworks are for! Conversation management, aka state management. It comes down to either holding the past messages in a db to have state, or persisting "conversations" in memory.

There is no "right" way to do this (in my opinion) and if you want a simple answer to your question it is: use a bot framework instead of writing this functionality from scratch.

Jon Church
  • 2,320
  • 13
  • 23