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())
- property name: str¶
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: FlowRoot, requestor: 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: FlowRoot, requestor: 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.
- advance(next_step: FlowNode, enforce_predicate: bool = True)[source]¶
Move on along the flow.
- Parameters:
next_step (
FlowNode
) – Which node you want to move the flow forward to.enforce_predicate (
bool
) – 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.
- check_identifier(identifier: Identifier) bool [source]¶
- property name: str¶
Helper property to get the name of the flow.
- next_autosteps() List[FlowNode] [source]¶
Get the next steps that can be automatically executed according to the set predicates.
- class errbot.flow.FlowExecutor(bot)[source]¶
Bases:
object
This is a instance that can monitor and execute flow instances.
- check_inflight_already_running(user: Identifier) bool [source]¶
Check if user is already running a flow. :rtype:
bool
:type user:Identifier
:param user: the user
- check_inflight_flow_triggered(cmd: str, user: Identifier) Tuple[Flow | None, FlowNode | None] [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: Flow) None [source]¶
This is where the flow execution happens from one of the thread of the pool.
- start_flow(name: str, requestor: Identifier, initial_context: Mapping[str, Any]) Flow [source]¶
Starts the execution of a Flow.
- stop_flow(name: str, requestor: Identifier) Flow | None [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: Identifier, extra_context=None) Flow | None [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) None [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: ~errbot.flow.FlowNode | str, predicate: ~typing.Callable[[~typing.Mapping[str, ~typing.Any]], bool] = <function FlowNode.<lambda>>, hints: bool = True) FlowNode [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).
- Parameters:
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)
predicate – function with one parameter, the context, to determine of the flow executor can continue automatically this flow with no user intervention.
hints (
bool
) – 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:
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.
- connect(node_or_command: ~errbot.flow.FlowNode | str, predicate: ~typing.Callable[[~typing.Mapping[str, ~typing.Any]], bool] = <function FlowRoot.<lambda>>, auto_trigger: bool = False, room_flow: bool = False) FlowNode [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