Articles in this section

Send flow step error count to a Slack channel

You can build a custom flow that gets the open error count from a flow step and posts it to a Slack channel, so your team can review and prioritize errors without checking integrator.io directly. This article covers building that flow. If you'd rather consolidate errors across multiple flows first, see Consolidate errors in a single report. For the related postSubmit-hook and listener patterns this article builds on, see Automate error handling with custom hooks.

The flow you'll build has two steps: an export that gets open errors for a flow step and transforms them into a count, and an import that sends the count to Slack.

Example flow that sends the error count to Slack

Before you start

Create both connections you'll need before building the export and import, so they're ready to select:

  • An HTTP connection to your own integrator.io account, so the flow can call the integrator.io API to retrieve error details. Set this up as a token-based HTTP connection using a "Full access" scope API token.

    HTTP connection settings

    HTTP connection settings, continued

  • A Slack connection, so the flow can post to a channel.

Step 1: Create an export to get open errors

  1. Go to Resources resources-icon.png, and then select Exports.
  2. On the Exports page, select + Create export in the top-right corner.
  3. Configure the export's connection and general settings.

    Export general settings

  4. For Export type, select All to always export every open error, or Delta to get only new open errors since the export last ran.
  5. Add custom fields for the flow ID and step ID you want to export errors from. Select Launch form builder under Custom settings (or open the flow's Settings and add the same code there):

    {
      "fieldMap": {
        "flowId": {
          "id": "Flow_id",
          "name": "Flow_id",
          "type": "text",
          "helpText": "When you are viewing a flow step error table, you can find the flow id and step id by matching the URI with this URI pattern: https://api.integrator.io/v1/flows/{_flowid}/{stepId}/errors",
          "label": "Flow id."
        },
        "stepId": {
          "id": "Step_id",
          "name": "Step_id",
          "type": "text",
          "helpText": "When you are viewing a flow step error table, you can find the flow id and step id by matching the URI with this URI pattern: https://api.integrator.io/v1/flows/{_flowid}/{stepId}/errors",
          "label": "Step id."
        }
      }
    }

    You need Manage (write) access to a resource to define custom settings for it.

  6. Under Custom settings, enter the flow ID and step ID whose errors you want to export.

    Custom settings with the flow ID and step ID

  7. Select Save & close.

Step 2: Transform the export into an error count

  1. Select the plus sign (+) next to the export, then select the transform icon (Transform icon) to open the Define transformation Advanced Field Editor.
  2. Select JavaScript, then add a transformation script that counts errors by code and message:

    /*
    * transformFunction stub:
    * The function will be passed one 'options' argument that has the following fields:
    *   'record' - object {} or array [] depending on the data source.
    *   'settings' - all custom settings in scope for the transform currently running.
    * The function needs to return the transformed record.
    * Throwing an exception will return an error for the record.
    */
    function transform(options) {
      const errors = options.record.errors;
      const uniqueCounts = {
        errorCode: {},
        errorMessage: {},
      };
      let totalErrorCount = 0;
      errors.forEach((error) => {
        const errorMessage = error.message;
        const errorCode = error.code;
        totalErrorCount += 1;
        if (!uniqueCounts.errorCode[errorCode]) {
          uniqueCounts.errorCode[errorCode] = { code: errorCode, count: 1 };
        } else {
          uniqueCounts.errorCode[errorCode].count += 1;
        }
        if (!uniqueCounts.errorMessage[errorMessage]) {
          uniqueCounts.errorMessage[errorMessage] = { message: errorMessage, count: 1 };
        } else {
          uniqueCounts.errorMessage[errorMessage].count += 1;
        }
      });
      const result = {
        errorCodeCounts: Object.values(uniqueCounts.errorCode),
        errorMessageCounts: Object.values(uniqueCounts.errorMessage),
        totalErrorCount: totalErrorCount,
      };
      return result;
    }
  3. Select Save and close once the preview shows the error counts as expected.

    Transformation preview with the error counts

Step 3: Create the import to Slack

  1. Go to Resources resources-icon.png, and then select Imports.
  2. On the Imports page, select + Create import in the top-right corner.
  3. Configure the general details, selecting your Slack connection.

    Slack import general settings

  4. Select Save and close.
  5. Map the fields: set the channel to the Slack channel you want the count posted to (for example, "testflows"), and map the message text using the transformed error-count fields. You can use a Handlebars expression in the source field to customize the message — for example, to post counts by error code instead of by message.

    Slack import field mapping

Run the flow

Schedule the flow to run at a regular interval so error counts stay current. Once it runs, members of the target Slack channel receive a message with the overall error count.

Slack message with the error count