Random Someone
Random Someone

Reputation: 392

How to manage context/state in a chat bot?

I am developing a chat bot using Python, celery, and the MS bot framework. I want to add small dialogs like the following:

User: Hi

User: Order me fries.

Bot: ok. address?

User: xyz, state, 82288

Bot: Got it. I will order fries for you.

Here, how can I temporarily store fries to access it after the user gives me the address?

Also, I think it should be acceptable for my use case to forget what the order was if the user does not respond for 2-3 minutes. So, I can also have a timeout for the stored variable.

I thought of using redis. I am thinking of storing something like the following in a redis db:

{
 'conversationId':['orderitem':'fries','address':'state, pincode']
}

basically a key,value pair with key=conversationId and value='order,address'.

So, does this look a good option?

Upvotes: 0

Views: 2244

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

You should consider using the Bot State REST API to manage state within the bot.

The bot can manage 3 types of state data, out-of-the-box:

  1. State data for a user on a specific channel (UserData)
  2. State data for a conversation on a specific channel (ConversationData)
  3. State data for a user within the context of a specific conversation (PrivateConversationData)

Upvotes: 3

Related Questions