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

chat_history#

The session chat history

Type:

str

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

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

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