session#

class besser.bot.core.session.Session(session_id, bot, platform)[source]#

Bases: object

A user session in a bot execution.

When a user starts interacting with a bot, a session is assigned to him/her to store user related information, such as the current state of the bot, the conversation history, the detected intent with its parameters or any user’s private data. A session can be accessed from the body of the states to read/write user information.

Parameters:
  • session_id (str) – The session id, which must unique among all bot sessions

  • bot (Bot) – The bot the session belongs to

  • platform (Platform) – The platform where the session has been created

_id#

The session id, which must unique among all bot sessions

Type:

str

_bot#

The bot the session belongs to

Type:

str

_platform#

The platform where the session has been created

Type:

str

_current_state#

The current state in the bot for this session

Type:

str

_dictionary#

Storage of private data for this session

Type:

str

_message#

The last message sent to the bot by this session

Type:

str

_predicted_intent#

The last predicted intent for this session

Type:

str

_file#

File or None: The last file sent to the bot.

chat_history#

The session chat history

Type:

str

flags#

A dictionary of boolean flags. A predicted_intent flag is set to true when an intent is received. When the evaluation of the current state’s transitions is done, the flag is set to false. It may happen that a transition different from the one associated with this intent is triggered (e.g. one evaluating some condition). In the following state, if there is a transition associated with the same intent, it should not be triggered as the time for this intent passed (unless the same intent is detected, in such case the flag will be set to true again). Another flag file_flag is used for the same purpose but for files sent by the user

Type:

dict[str, bool]

property current_state#

The current bot state of the session.

Type:

State

delete(key)[source]#

Delete an entry of the session private data storage.

Parameters:

key (str) – the entry key

property file#

The last file sent to the bot.

Type:

str

get(key)[source]#

Get an entry of the session private data storage.

Parameters:

key (str) – the entry key

Returns:

the entry value, or None if the key does not exist

Return type:

Any

property id#

The session id.

Type:

str

property message#

The last message sent to the bot.

Type:

str

move(transition)[source]#

Move to another bot state.

Parameters:

transition (Transition) – the transition that points to the bot state to move

property platform#

The session platform.

Type:

Platform

property predicted_intent#

The last predicted intent for this session.

Type:

str

reply(message)[source]#

A bot message (usually a reply to a user message) is sent to the session platform to show it to the user.

Parameters:

message (str) – the bot reply

set(key, value)[source]#

Set an entry to the session private data storage.

Parameters:
  • key (str) – the entry key

  • value (Any) – the entry value