errbot.flow module¶
-
class
errbot.flow.
BotFlow
(bot, name=None)[source]¶ Bases:
object
Defines a Flow plugin ie. a plugin that will define new flows from its methods with the @botflow decorator.
-
activate
() → None[source]¶ Override if you want to do something at initialization phase (don’t forget to super(Gnagna, self).activate())
-
deactivate
() → None[source]¶ Override if you want to do something at tear down phase (don’t forget to super(Gnagna, self).deactivate())
-
name
¶ Get the name of this flow as described in its .plug file.
Returns: The flow name.
-
-
errbot.flow.
FLOW_END
= <errbot.flow._FlowEnd object>¶ Flow marker indicating that the flow ends.
-
class
errbot.flow.
Flow
(root: errbot.flow.FlowRoot, requestor: errbot.backends.base.Identifier, initial_context: Mapping[str, Any])[source]¶ Bases:
object
This is a live Flow. It keeps context of the conversation (requestor and context). Context is just a python dictionary representing the state of the conversation.
-
__init__
(root: errbot.flow.FlowRoot, requestor: errbot.backends.base.Identifier, initial_context: Mapping[str, Any])[source]¶ Parameters: - root (
FlowRoot
) – the root of this flow. - requestor (
Identifier
) – the user requesting this flow. - initial_context – any data we already have that could help executing this flow automatically.
- root (
-
advance
(next_step: errbot.flow.FlowNode, enforce_predicate=True)[source]¶ Move on along the flow. :type enforce_predicate:
bool
:type next_step:FlowNode
:param next_step: Which node you want to move the flow forward to. :param enforce_predicate: Do you want to check if the predicate is verified for this step or not.Usually, if it is a manual step, the predicate is irrelevant because the user will give the missing information as parameters to the command.
-
current_step
¶ The current step this Flow is waiting on.
-
name
¶ Helper property to get the name of the flow.
-
next_autosteps
() → List[errbot.flow.FlowNode][source]¶ Get the next steps that can be automatically executed according to the set predicates.
-
next_steps
() → List[errbot.flow.FlowNode][source]¶ Get all the possible next steps after this one (predicates statisfied or not).
-
root
¶ The original flowroot of this flow.
-
-
class
errbot.flow.
FlowExecutor
(bot)[source]¶ Bases:
object
This is a instance that can monitor and execute flow instances.
-
check_inflight_already_running
(user: errbot.backends.base.Identifier) → bool[source]¶ - Check if user is already running a flow.
Return type: bool
Parameters: user ( Identifier
) – the user
-
check_inflight_flow_triggered
(cmd: str, user: errbot.backends.base.Identifier) → Tuple[Optional[errbot.flow.Flow], Optional[errbot.flow.FlowNode]][source]¶ Check if a command from a specific user was expected in one of the running flow. :type user:
Identifier
:type cmd:str
:param cmd: the command that has just been executed. :param user: the identifier of the person who started this flow :returns: The name of the flow it triggered or None if none were matching.
-
execute
(flow: errbot.flow.Flow)[source]¶ This is where the flow execution happens from one of the thread of the pool.
-
start_flow
(name: str, requestor: errbot.backends.base.Identifier, initial_context: Mapping[str, Any]) → errbot.flow.Flow[source]¶ Starts the execution of a Flow.
-
stop_flow
(name: str, requestor: errbot.backends.base.Identifier) → Optional[errbot.flow.Flow][source]¶ Stops a specific flow. It is a no op if the flow doesn’t exist. Returns the stopped flow if found.
-
trigger
(cmd: str, requestor: errbot.backends.base.Identifier, extra_context=None) → Optional[errbot.flow.Flow][source]¶ Trigger workflows that may have command cmd as a auto_trigger or an in flight flow waiting for command. This assume cmd has been correctly executed. :type requestor:
Identifier
:type cmd:str
:param requestor: the identifier of the person who started this flow :param cmd: the command that has just been executed. :param extra_context: extra context from the current conversation :returns: The flow it triggered or None if none were matching.
-
-
class
errbot.flow.
FlowNode
(command: str = None, hints: bool = True)[source]¶ Bases:
object
This is a step in a Flow/conversation. It is linked to a specific botcmd and also a “predicate”.
The predicate is a function that tells the flow executor if the flow can enter the step without the user intervention (automatically). The predicates defaults to False.
The predicate is a function that takes one parameter, the context of the conversation.
-
__init__
(command: str = None, hints: bool = True)[source]¶ Creates a FlowNone, takes the command to which the Node is linked to. :type hints:
bool
:type command:str
:param command: the command this Node is linked to. Can only be None if this Node is a Root. :param hints: hints the users for the next steps in chat.
-
connect
(node_or_command: Union[FlowNode, str], predicate: Callable[[Mapping[str, Any]], bool] = <function FlowNode.<lambda>>, hints: bool = True)[source]¶ Construct the flow graph by connecting this node to another node or a command. The predicate is a function that tells the flow executor if the flow can enter the step without the user intervention (automatically). :type hints:
bool
:param node_or_command: the node or a string for a command you want to connect this Node to(this node or command will be the follow up of this one)Parameters: - predicate – function with one parameter, the context, to determine of the flow executor can continue automatically this flow with no user intervention.
- hints – hints the user on the next step possible.
Returns: the newly created node if you passed a command or the node you gave it to be easily chainable.
-
-
class
errbot.flow.
FlowRoot
(name: str, description: str)[source]¶ Bases:
errbot.flow.FlowNode
This represent the entry point of a flow description.
-
__init__
(name: str, description: str)[source]¶ Parameters: - name (
str
) – The name of the conversation/flow. - description (
str
) – A human description of what this flow does. - hints – Hints for the next steps when triggered.
- name (
-
connect
(node_or_command: Union[FlowNode, str], predicate: Callable[[Mapping[str, Any]], bool] = <function FlowRoot.<lambda>>, auto_trigger: bool = False, room_flow: bool = False)[source]¶ See: FlowNode except fot auto_trigger
Parameters: - predicate –
see: FlowNode - node_or_command –
see: FlowNode - auto_trigger (
bool
) – Flag this root as autotriggering: it will start a flow if this command is executed in the chat. - room_flow (
bool
) – Bind the flow to the room instead of a single person
- predicate –
-