Workflows

Build complex business logic for your SaaS using SaasRock's simple and flexible workflow engine.

  • Alexandro MartΓ­nez
    Author
    by Alexandro MartΓ­nez
    1 years ago
  • Introducing SaasRock Workflows

    Hey there! With SaasRock Workflows in the fresh v0.9.2 release, tackling complex tasks just got a whole lot easier with no-code. Also, a new Starter edition has been released!

    TLDR: Watch the demo.

    admin-worklows-builder.png

    Summarizing the v0.9.2 release:

    Why is this not v1.0 yet? Help Desk and Affiliates are the 2 missing features. But in order to build Help Desk, I needed to build a workflow engine first.

    Concepts

    • Blocks: Triggers and Actions.

    • Variables and Credentials: Global variables and encrypted credentials.

    • Executions: A single run of a Workflow.

    • Workflow Context: Inputs and Outputs within a workflow execution.

    Execution Modes

    Choose between different modes for triggering a workflow:

    • Manual: Manually trigger a Workflow.

    • API πŸͺ¨: Use the API to trigger a Workflow @ /api/workflows/run/$id.

    • Stream πŸš€: Get updates from a stream (chat-like).

    Tenants/Accounts can also create and run their own Workflows πŸͺ¨.


    Workflow Features

    There are 4 workflows editions:

    See the full feature comparison in the following table.

    Screenshot 2023-11-25 at 20.42.35.png

    Workflow Blocks

    Triggers

    • Manual: By clicking a button

    • Row Event πŸš€: created, updated, deleted

    Actions

    • IF: True and False paths

    • HTTP Request: Set method, URL, Body, and Headers

    • Log: Logs to system

    • Alert User: Sends alert to current user

    • Switch πŸͺ¨: Default, case1, case2... etc, paths

    • Iterator πŸͺ¨: For loop using a variable

    • Variable πŸͺ¨: Set a context variable

    • Wait for Input πŸš€: Waits for user input (support in Manual, API, and streaming)

    • GPT Chat Completion πŸš€: Call OpenAI API

    • Row Get πŸš€: Create an entity row

    • Row Create πŸš€: Create an entity row

    • Row Update πŸš€: Update an entity row

    • Row Delete πŸš€: Delete an entity row

    Plus, on the Enterprise Edition πŸš€, I'll work on (long-term):

    • Crons support (Sleep, Delayed until...)

    • Send Emails

    • Global workflows (create a workflow in the admin dashboard for all tenants)

    • Advanced Workflow Analytics (i.e. percentages paths in a funnel)


    Variables and Credentials

    Variables
    Sometimes it's useful to have a global state. For example, you may have multiple GPT blocks across many workflows, and if there's a new model released, you could create a variable {{$vars.gptModel}}.

    admin-worklows-variables.png

    Credentials
    In the case of credentials πŸš€, the only difference between them is that they're encrypted before storing and decrypted before using it, click here to see the method.


    Workflow Context

    A workflow execution will always have an output similar to this:

    {
      "$params": {},
      "$session": {
        "tenant": {},
        "user": {},
      },
      "$vars": {},
      ...blocksOutputs
    }

    Explanation:

    • $params: Every execution starts with a JSON input

    • $session.tenant: If the execution is on the admin side, it's null

    • $session.user: If the execution is not started manually by a user, it's null

    • $vars: Global variables are injected

    Finally, each executed block will have a value with the block name. For example, the following output is from the "GPT Simulator" workflow template.

    {
      "$params": {},
      "$session": { "tenant": null, "user": null },
      "$vars": {
        "gptModel": "gpt-3.5-turbo"
      },
      "waitForInput": {
        "input": "Hi"
      },
      "if": {
        "condition": false,
        "expression": "{{waitForInput.input}} Equals bye"
      },
      "gpt": {
        "result": "Hello! How can I assist you today?"
      }
    }

    Using Variables

    Since the workflow context has everything you need from the workflow execution, you now can access values from previous blocks. Using the previous example:

    • {{gpt.result}} will be "Hello! How can I assist you today?"

    • {{$session.tenant}} will be an empty string

    • {{$credentials.OPENAI_API_KEY}} will decrypt the value on the fly and destroy it

    This is possible thanks to Handlebars.js.


    Workflow Templates

    I created a few templates that use every supported block, some of them are Core and/or Enteprise-only.

    Screenshot 2023-11-25 at 18.50.51.png

    Input Examples

    While building and testing your workflows, it's useful to set a few input examples instead of having to type the input body every time. For example:

    • Existing item: The input is { id: 10 }, so you know the workflow must go through the success path

    • ID parameter not provided: This tests that the initial execution (manually, via the API or in streaming mode) is sent correctly.

    And so on.


    Input Validation

    The Manual Trigger has a special "validation" field that receives a JSON configuration. This validates the schema using Ajv JSON schema validator:

    {
      "type": "object",
      "properties": {
        "id": {
          "type": "number"
        }
      },
      "required": [
        "id"
      ]
    }

    You can create any necessary validation schema to ensure the correct execution of a workflow.

    Executions

    Finally, analyze workflow execution results:

    admin-worklows-executions.png

    I hope you're as excited as I am for workflows!

    Let me know what you think on the Discord server or subscribe to my newsletter to get notified on new saasrock features.

    We respect your privacy.

    TLDR: We use cookies for language selection, theme, and analytics. Learn more.