Base class for new actions creation

The ActionRunner class is the base class used for creating any new actions in Diffgram. It includes several methods and attributes that will help you achieves things like saving output data, executing action logic, adding pre condition filters, etc.

To use the ActionRunner class you need to inherit it and fill all the required attributes. See the below example:

from eventhandlers.action_runners.base.ActionRunner import ActionRunner
from eventhandlers.action_runners.base.ActionTrigger import ActionTrigger
from eventhandlers.action_runners.base.ActionCondition import ActionCondition
from eventhandlers.action_runners.base.ActionCompleteCondition import ActionCompleteCondition

class MySampleAction(ActionRunner):
    public_name = 'your_action_name'
    icon = '' #Url for image of action
    kind = 'my_sample_action'  # The kind has to be unique to all actions
    category = 'some_category'  # Optional

    # What events can this action listen to?
    trigger = ActionTrigger(default_event = 'some_diffgram_event',
                            event_list = ['some_diffgram_event'])

    # What pre-conditions can this action have?
    condition_data = ActionCondition(default_event = 'some_diffgram_event',
                                     event_list = ['some_diffgram_event'])

    # How to declare the actions as completed?
    completion_condition_data = ActionCompleteCondition(default_event = 'some_diffgram_event',
                                                        event_list = ['some_diffgram_event'])

    def execute_pre_conditions(self, session) -> bool:
        # Return true if no pre-conditions are needed.
        return True

    def execute_action(self, session):
        # Your core Action logic will go here.


All the attributes described below live in the context of an action execution. In other words, an event has already been created and there has been a match with the events the action listens to.


The Action object that was triggered for action execution.


The serialized event data of the action. This includes the event kind and any other referential ids to objects in diffgram. For example a task_created event kind will include also a task_id key on the event_data attribute.


Python dictionary to store any execution information or errors in case of failure.


The name to be displayed on the UI for this action.


The url to an SVG icon or image for this action.


The action kind. This must be a unique name to identify your action across the diffgram installation.


The action category (optional)


A longer description of what the action does to explain users of Diffgram.


The object of type ActionTrigger that holds the trigger data events. See the reference of ActionTrigger for more details.


The object of type ActionCondition that holds the pre condition data events. See the reference of ActionCondition for more details.


The object of type ActionCompleteCondition that holds the completion condition data events. See the reference of ActionCompleteCondition for more details.


The object of type ActionRun . This represents the execution of an action. It holds the action_id and any data related to the isolated execution of the Action. The ActionRun is also able to store output information.


save_html_output(session: Session, html_data: str)

Saves the given html string on the output of the action run and caches it on the output of the action.

execute_pre_conditions(self, session: Session) -> bool

Function to determine if pre conditions for execution are met. Returns true if action can be executed and False if actions cannot be executed. This is implemented on the subclasses of the ActionRunner

execute_action(self, session: Session) -> None

Function that executes main action logic. This is implemented on the subclasses of the ActionRunner

verify_registration_data() -> None

Verifies the actions registered data is complete and valid. Used when registering the action at startup time.

run() -> None

Executes the action. This method does not need to be overriden. The method calls execute_pre_conditions and then execute_action. Finally it calls declare_action_complete or declare_action_failed depending on outcome.