Integration with Slack

Inferable provides an integration which supports two use cases:

  • Programatically Sending Approval Requests notifications to Slack
  • Starting conversations with Inferable (Runs) from your Slack workspace.

Installation

Connect your Slack workspace to a Cluster in the Playground UI by navigating to the Cluster’s “Integrations” tab and selecting “Slack”. This will ask you to authorise your Slack workspace with Inferable.

Your Slack workspace can only be connected to one Cluster at a time. Connecting another Cluster to the same workspace will replace the existing integration.

Approval Request Notifications

Your Workflows and Tools can programatically notify Slack when human approval is required.

The Interrupt.approval() function can accept a notification object to configure the Slack notification.

import { Inferable, Interrupt, approvalRequest } from "inferable";

const inferable = new Inferable({
  apiSecret: process.env.INFERABLE_API_SECRET,
});

const deleteUserWorkflow = inferable.workflows.create({
  name: "deleteUser",
  inputSchema: z.object({
    executionId: z.string(),
    userId: z.string(),
  }),
});

deleteUserWorkflow.version(1).define(async (ctx, input) => {
  if (!ctx.approved) {
    return Interrupt.approval({
      message: `I need your approval to delete the user ${input.userId}. Is this ok?`,
      destination: {
        type: "slack",
        // The email address of the Slack user to notify
        email: "[email protected]",
        // Or Slack user ID
        userId: z.string().optional(),
        // Or Slack channel ID
        channelId: z.string().optional(),
      },
    });
  }
  //...
});

Conversations / DMs

As well as programatically notifying Slack as described above, you can also start conversations directly from Slack by messageing the Inferable Slack app via DM.

Responses will be posted to the message’s thread, you can continue the conversation by replying in the thread (Replying outside the thread will trigger another Run).

The Inferable Slack app will not currently respond to @ mentions outside of the DM. This will be supported in a future release.

Approval Requests

If a conversation triggered from Slack requires human approval, the Inferable Slack app will post a message to the thread and provide a UI for the user to approve or reject the request.

If a conversation is triggered from Slack, approval requests will automatically be sent to the thread. This is in addition to any programtic notifications configured for the Tool.

Authenticating Users

The Inferable Slack app will not respond to messages from users unless they meet the following criteria:

  • The user’s Slack email address is verified
  • The user is a member of the Cluster’s Inferable organisation and has the same email address as their Slack account

Auth Context

All functions in a Run initiated by the Slack integration will have access to an authContext object containing the user’s Slack email address and Id in the following structure:

{
  "slack": {
    "email": "[email protected]",
    "id": "U123456789"
  }
}

Usage

This can be used to authorize user actions.

inferable.tools.register({
  name: "deleteUser",
  description: "Permanently deletes a user account",
  schema: {
    input: z.object({
      userId: z.string(),
    }),
  },
  func: async (input, context) => {
    if (context.authContext.slack.email !=== "[email protected]") {
      throw new Error("Unauthorized");
    }

    return db.customers.delete({
      userId: input.userId,
    });
  },
});