bot#
- class besser.bot.core.bot.Bot(name)[source]#
Bases:
objectThe bot class.
- Parameters:
name (str) – The bot’s name
- _platforms_threads#
The threads where the platforms are run
- Type:
- _config#
The bot configuration parameters
- Type:
ConfigParser
- _trained#
Weather the bot has been trained or not. It must be trained before it starts its execution.
- Type:
- global_initial_states#
List of tuples of initial global states and their triggering intent
- global_state_component#
Dictionary of global state components, where key is initial global state and values is set of states in corresponding global component
- _init_global_states()[source]#
Initialise the global states and add the necessary transitions.
Go through all the global states and add transitions to every state to jump to the global states. Also add the transition to jump back to the previous state once the global state component has been completed.
- property config#
The bot configuration parameters.
- Type:
ConfigParser
- delete_session(session_id)[source]#
Delete an existing bot session.
- Parameters:
session_id (str) – the session id
- get_property(prop)[source]#
Get a bot property’s value
- Parameters:
prop (Property) – the property to get its value
- Returns:
the property value, or None
- Return type:
Any
- initial_state()[source]#
Get the bot’s initial state. It can be None if it has not been set.
- Returns:
the initial state of the bot, if exists
- Return type:
State or None
- load_properties(path)[source]#
Read a properties file and store its properties in the bot configuration.
An example properties file, config.ini:
[websocket_platform] websocket.host = localhost websocket.port = 8765 streamlit.host = localhost streamlit.port = 5000 [telegram_platform] telegram.token = YOUR-BOT-TOKEN [nlp] nlp.language = en nlp.region = US nlp.timezone = Europe/Madrid nlp.stemmer = True nlp.intent_threshold = 0.4
- Parameters:
path (str) – the path to the properties file
- receive_message(session_id, message)[source]#
Receive a message from a specific session.
Receiving a message starts the process of inferring the message’s intent and acting properly (e.g. transition to another state, store something in memory, etc.)
- reset(session_id)[source]#
Reset the bot current state and memory for the specified session. Then, restart the bot again for this session.
- set_global_fallback_body(body)[source]#
Set the fallback body for all bot states.
The fallback body is a state’s callable function that will be run whenever necessary to handle unexpected scenarios (e.g. when no intent is matched, the current state’s fallback is run). This method simply sets the same fallback body to all bot states.
See also:
set_fallback_body()- Parameters:
body (Callable[[Session], None]) – the fallback body
- set_property(prop, value)[source]#
Set a bot property.
- Parameters:
prop (Property) – the property to set
value (Any) – the property value
- use_telegram_platform()[source]#
Use the
TelegramPlatformon this bot.- Returns:
the telegram platform
- Return type:
- use_websocket_platform(use_ui=True)[source]#
Use the
WebSocketPlatformon this bot.- Parameters:
use_ui (bool) – if true, the default UI will be run to use this platform
- Returns:
the websocket platform
- Return type: