ChatterBot supports the ability to have multiple concurrent chat sessions. A chat session is where the chat bot interacts with a person, and supporting multiple chat sessions means that your chat bot can have multiple different conversations with different people at the same time.
A session is an ordered collection of statements that are related to each other.
Object to hold and manage multiple chat sessions.
Return a session given a unique identifier.
Create a new conversation.
Add a conversance to a given session if the session exists.
Each session object holds a queue of the most recent communications that have occurred during that session. The queue holds tuples with two values each, the first value is the input that the bot received and the second value is the response that the bot returned.
An extension of the FixedSizeQueue class with utility methods to help manage the conversation.
Return the last response that was given.
Return the last statement that was received.
ChatBot instances are created, each will have sessions separate from each other.
An adapter can access any session as long as the unique identifier for the session is provided.
The following example is taken from the Django
ChatterBotView built into ChatterBot.
In this method, the unique identifiers for each chat session are being stored in Django’s
session objects. This allows different users who interact with the bot through different
web browsers to have separate conversations with the chat bot.
def post(self, request, *args, **kwargs): """ Return a response to the statement in the posted data. """ input_data = json.loads(request.read().decode('utf-8')) self.validate(input_data) chat_session = self.get_chat_session(request) response = self.chatterbot.get_response(input_data, chat_session.id_string) response_data = response.serialize() return JsonResponse(response_data, status=200)