shellbot.machines.steps module

class shellbot.machines.steps.Step(attributes, index)[source]

Bases: object

Represents a step in a linear process

say(bot)[source]

Reports on this step

Parameters:bot (ShellBot) – the bit to use

This function posts to the chat space some information on this step.

Example:

step.say(bot)
stop()[source]

Stops a step

trigger(bot)[source]

Triggers a step

Parameters:bot (ShellBot) – the bot to use

This function does everything that is coming with a step: - send a message to the chat space, - maybe in MarkDown or HTML, - maybe with some attachment, - add participants to the channel, - reset and start a state machine

Example:

step.trigger(bot)
class shellbot.machines.steps.Steps(bot=None, states=None, transitions=None, initial=None, during=None, on_enter=None, on_exit=None, **kwargs)[source]

Bases: shellbot.machines.base.Machine

Implements a linear process with multiple steps

This implements a state machine that appears as a phased process to chat participants. On each, it can add new participants, display some information, and run a child state machine..

For example, to run an escalation process:

po_input = Input( ... )
details_input = Input( ... )

decision_menu = Menu( ...)

steps = [

    {
        'label': u'Level 1',
        'message': u'Initial capture of information',
        'machine': Sequence([po_input, details_input]),
    },

    {
        'label': u'Level 2',
        'message': u'Escalation to technical experts',
    },

    {
        'label': u'Level 3',
        'message': u'Escalation to decision stakeholders',
        'participants': 'bob@acme.com',
        'machine': decision_menu,
    },

    {
        'label': u'Terminated',
        'message': u'Process is closed, yet conversation can continue',
    },

]
machine = Steps(bot=bot, steps=steps)
machine.start()
...
current_step

Gets current step

Returns:current step, or None
if_end(**kwargs)[source]

Checks if all steps have been used

Since this function is an integral part of the state machine, it should be triggered via a call of the step() member function.

For example:

machine.step(event='tick')
if_next(**kwargs)[source]

Checks if next step should be engaged

Parameters:event (str) – a label of event submitted to the machine

This function is used by the state machine for testing the transition to the next available step in the process.

Since this function is an integral part of the state machine, it should be triggered via a call of the step() member function.

For example:

machine.step(event='next')
if_ready(**kwargs)[source]

Checks if state machine can engage on first step

To be overlaid in sub-class where complex initialization activities are required.

Example:

class MyMachine(Machine):

    def if_ready(self, **kwargs):
        if kwargs.get('phase') == 'warming up':
            return False
        else:
            return True
next_step()[source]

Moves to next step

Returns:current step, or None

This function loads and runs the next step in the process, if any. If all steps have been consumed it returns None.

If a sub-machine is running at current step, it is stopped before moving to the next step.

on_init(steps=None, **kwargs)[source]

Handles extended initialisation parameters

Parameters:steps (list of Step or list of dict) – The steps for this process
on_reset()[source]

Restore initial state of this machine

If a sub-machine is running at current step, it is stopped first.

step_has_completed(**kwargs)[source]

Checks if the machine for this step has finished its job

Returns:False if the machine is still running, True otherwise