Conditions#

Conditions are one of the most important components of the dialog graph. They determine the possibility of transition from one node of the graph to another. The conditions are used to specify when a particular transition should occur, based on certain criteria. This module contains a standard set of scripting conditions that can be used to control the flow of a conversation. These conditions can be used to check the current context, the user’s input, or other factors that may affect the conversation flow.

exact_match(match, skip_none=True)[source]#

Return function handler. This handler returns True only if the last user phrase is the same Message as the match. If skip_none the handler will not compare None fields of match.

Parameters:
  • match (Message) – A Message variable to compare user request with.

  • skip_none (bool) – Whether fields should be compared if they are None in match.

Return type:

Callable[[Context, Pipeline], bool]

regexp(pattern, flags=0)[source]#

Return function handler. This handler returns True only if the last user phrase contains pattern with flags.

Parameters:
  • pattern (Union[str, Pattern]) – The RegExp pattern.

  • flags (Union[int, RegexFlag]) – Flags for this pattern. Defaults to 0.

Return type:

Callable[[Context, Pipeline], bool]

check_cond_seq(cond_seq)[source]#

Check if the list consists only of Callables.

Parameters:

cond_seq (list) – List of conditions to check.

_any(iterable, /)#

_any is an alias for any.

_all(iterable, /)#

_all is an alias for all.

aggregate(cond_seq, aggregate_func=<built-in function any>)[source]#

Aggregate multiple functions into one by using aggregating function.

Parameters:
  • cond_seq (list) – List of conditions to check.

  • aggregate_func (Callable) – Function to aggregate conditions. Defaults to _any().

Return type:

Callable[[Context, Pipeline], bool]

any(cond_seq)[source]#

Return function handler. This handler returns True if any function from the list is True.

Parameters:

cond_seq (list) – List of conditions to check.

Return type:

Callable[[Context, Pipeline], bool]

all(cond_seq)[source]#

Return function handler. This handler returns True only if all functions from the list are True.

Parameters:

cond_seq (list) – List of conditions to check.

Return type:

Callable[[Context, Pipeline], bool]

negation(condition)[source]#

Return function handler. This handler returns negation of the condition(): False if condition() holds True and returns True otherwise.

Parameters:

condition (Callable) – Any condition().

Return type:

Callable[[Context, Pipeline], bool]

has_last_labels(flow_labels=None, labels=None, last_n_indices=1)[source]#

Return condition handler. This handler returns True if any label from last last_n_indices context labels is in the flow_labels list or in the NodeLabel2Type list.

Parameters:
  • flow_labels (Optional[List[str]]) – List of labels to check. Every label has type str. Empty if not set.

  • labels (Optional[List[Tuple[str, str]]]) – List of labels corresponding to the nodes. Empty if not set.

  • last_n_indices (int) – Number of last utterances to check.

Return type:

Callable[[Context, Pipeline], bool]

true()[source]#

Return function handler. This handler always returns True.

Return type:

Callable[[Context, Pipeline], bool]

false()[source]#

Return function handler. This handler always returns False.

Return type:

Callable[[Context, Pipeline], bool]

agg(cond_seq, aggregate_func=<built-in function any>)#

agg() is an alias for aggregate().

Return type:

Callable[[Context, Pipeline], bool]

neg(condition)#

neg() is an alias for negation().

Return type:

Callable[[Context, Pipeline], bool]