There are currently 2 state adapters available in the library: JsonState MongodbState * Microsoft Bot Framework API (comming soon)



JsonState requires write privileges to the working directory or the configured directory.


MongodbState requires a working Mongodb Database. See the following url for a good guide on installing. If using Heroku you can also the resources to add "mLab MongoDB :: Mongodb, Sandbox".

In addition the pymongo library is required. It can be installed with the following command.

pip install pymongo

Conversation tracking

The MsBot and Response can be setup to save all incoming and outgoing conversations. By default this is disabled.

This can be configured in 4 ways.

Inline string arguments
bot = MsBot(state='MongodbState')

activity_members = GetActivityMembers(conversationId="asdfwetjerjbbvwre",
Inline object arguments
config = Config()
bot = MsBot(state=MongodbState(config))

This allows you to build your own State objects using the same API by extending the State Abstract Class

    state: JsonState   # state to use
    database: statedatabase     # defaults to microsoft bot framework
Environment variables
# in linux
export STATE=JsonState

Get Conversation Tracking

You can get the saved conversation as follows. count is the number of records to return, default 10 conversation_id will only get records regarding to that conversation, default all * simple will respond with an array of the text strings from the activities rather than the whole activities.

json_state = JsonState()
json_state.get_activities(self, count=10, conversation_id=None, simple=False)

Configuring State Objects

objects can be configured in 3 ways

inline arguments
bot = MsBot(state=RedisCache(config))

bot = MsBot(state=JsonCache('cache.json'))
config.yaml (Mongodb Only)
    uri: mongodb://
environment variables (Mongodb Only)
# in linux
export MONGODB_URI=redis://localhost:6379

State Objects

To access state create a state object as follows:

mongodb_state = MongodbState(config=Config())
json_state = JsonState()

You can set, get and state against a few combinations of: channel conversation_id * user_id

values should be a dictionary of values.

json_state = JsonState()

values = {'name': 'Sam', 'age': 23}

json_state.set_user_data_on_channel(values, channel, user_id)
json_state.set_conversation_data_on_channel(values, channel, conversation_id)
json_state.set_private_conversation_data_on_channel(values, channel, conversation_id, user_id)
json_state.set_user_data(values, user_id)
json_state.set_channel_data(values, channel)

json_state.get_user_data_on_channel(channel, user_id)
json_state.get_conversation_data_on_channel(channel, conversation_id)
json_state.get_private_conversation_data_on_channel(channel, conversation_id, user_id)

json_state.delete_user_data_on_channel(channel, user_id)
json_state.delete_conversation_data_on_channel(channel, conversation_id)
json_state.delete_private_conversation_data_on_channel(channel, conversation_id, user_id)

# Deletes all state on a channel for a user
json_state.delete_state_for_user(channel, user_id)

All methods also have a fill argument which will autofill the 3 required fields if passed a message.

json_state = JsonState()
json_state.set_user_data_on_channel(values, fill=message)

When using the fill method you can also pass bot=True to use the bots id as the user_id

json_state = JsonState()
json_state.set_user_data_on_channel(values, fill=message, bot=True)