transition#

class besser.bot.core.transition.Transition(name, source, dest, event, event_params)[source]#

Bases: object

A bot transition from one state (source) to another (destination).

A transition is triggered when an event occurs.

Parameters:
  • name (str) – the transition name

  • source (State) – the source state of the transition (from where it is triggered)

  • dest (State) – the destination state of the transition (where the bot moves to)

  • event (Callable[[Session, dict], bool]) – the event that triggers the transition

  • event_params (dict) – the parameters associated to the event

name#

The transition name

Type:

str

source#

The source state of the transition (from where it is triggered)

Type:

State

dest#

The destination state of the transition (where the bot moves to)

Type:

State

event#

The event that triggers the transition

Type:

Callable[[Session, dict], bool]

event_params#

The parameters associated to the event

Type:

dict

is_auto()[source]#

Check if the transition event is auto (i.e. a transition that does not need any event to be triggered).

Returns:

true if the transition’s intent matches with the target one, false

Return type:

bool

is_event_true(session)[source]#

Given a session, returns true if the event associated to the transition returns true, and false otherwise. (Applicable to any event)

Parameters:

session (Session) – the session in which some user data can be stored and used within the event

Returns:

true if the transition’s event returned true, false otherwise

Return type:

bool

is_intent_matched(session)[source]#

For intent-matching transitions, check if the predicted intent (stored in the given session) matches with the transition’s expected intent (stored in the transition event parameters).

If the transition event is not intent_matched, return false.

Parameters:

session (Session) – the session in which the to be compared value is stored

Returns:

true if the transition’s intent matches with the target one, false otherwise

Return type:

bool

is_variable_matching_operation(session)[source]#

For session-value-comparison transitions, check if the given operation on a stored session value and a given target value (stored in the transition event parameters) returns true.

If the transition event is not variable_matches_operation, return false.

Parameters:

session (Session) – the session in which the value to be compared is stored

Returns:

true if the operation on stored and target values returns true, false otherwise

Return type:

bool

log()[source]#

Create a log message for the transition. Useful when transitioning from one state to another to track the bot state.

Example: intent_matched (hello_intent): [state_0] –> [state_1]

Returns:

the log message

Return type:

str