Skip to content

Use AI and Slack's workflow builder to review incidents and generate important details for an incident postmortem

License

Notifications You must be signed in to change notification settings

Slack-Partner-Engineering/ai-for-incidents

Repository files navigation

AI for Incidents

Outline

Overview

This app is built using Bolt for JavaScript and includes two custom functions for Bolt. These functions are meant to be deployed on your own infrastructure. This is different from the previously released workflow apps built with the Deno Slack SDK and are hosted on Slack's infrastructure.

The functions are modular! Once the app is installed, any builder with access to the functions can use them in their own workflows and mix-and-match as needed for their use case.

🧵 Get all thread replies Fetch all replies from the referenced Slack thread. The timestamp, author, & text of each message are extracted and output via the replies property as a stringified array to be used in subsequent steps.

🤖 Summarize incident with ChatGPT This step expects an array of Slack messages describing an incident and includes several hardcoded system prompts that instruct ChatGPT on how to interpret the inputs and what outputs are expected. ChatGPT returns a JSON object that is parsed and assigned to individual outputs: summary, cause, impact, resolution, duration, & timeline. Each can be used as individual variables in subsequent workflow steps.

Setup

Deploy

Before getting started, first make sure you have a developer workspace where you have permission to install apps. Please note that the features in this project require that the workspace be part of a Slack paid plan.

Clone the Template

Start by cloning this repository:

# Clone this project onto your machine
$ slack create ai-for-incidents -t Slack-Partner-Engineering/ai-for-incidents

# Change into the project directory
$ cd ai-for-incidents

# Install dependencies
$ npm install
  1. Create a new app from api.slack.com/apps using the included manifest.json file.
  2. Ensure your app has opted into the Org-wide apps feature.
  3. Install the app. If you are building in an Enterprise Grid, you must install at the org-level. If you are building on a standalone workspace, this does not apply.
  4. Create a copy of .env.sample, rename to .env and provide the required values: an OpenAI API key and three tokens from your newly created app.
  5. Run your app locally with the npm start command or deploy to a hosting platform of your choice such as Heroku.
  6. Open Workflow Builder and create a new workflow that includes one or both of the provided functions. They will appear in the Custom section of the steps list for all users that have been granted access.

Using functions in Workflow Builder

With your server running, your function is now ready for use in Workflow Builder! They will appear in the Custom section of the steps list for all users that have been granted access.

Download the included workflow JSON file to get started rebuilding this workflow in Slack. At this time, exporting a workflow does not support non built-in steps. This means that the two custom steps in this app won't appear when imported. Add them yourself and made any edits as needed, specifically within the Create a canvas step where you will need to update the marked variable references to the outputs of the Summarize incident with ChatGPT step.

📥 Example workflow (json)

Example workflow

Implementation details

The get_thread function outputs a replies JSON string. Here is an example of what you can expect this function to output for a Slack thread with a parent message and two nested replies:

{
  "messages": [    
    {
      "author": "Adam",
      "message": "Our payments system stopped working",
      "datetime": "2024-04-11T22:59:01.000Z"
    },
    {
      "author": "Adam",
      "message": "10 customers have contacted our support team",
      "datetime": "2024-04-11T22:59:31.000Z"
    },
    {
      "author": "Jennifer",
      "message": "Not sure what is wrong, checking logs",
      "datetime": "2024-04-11T22:59:55.000Z"
    }
  ]
}

Project Structure

.slack/

Contains apps.dev.json and config.json, which include installation details for your project.

app.js

app.js is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests.

manifest.json

manifest.json is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.

slack.json

Used by the Slack CLI to interact with the project's SDK dependencies. It contains script hooks that are executed by the CLI and implemented by @slack/cli-hooks. You have the option to specify a deploy hook for your app, such that when you run slack deploy, your specified instructions will run.

Linting

Run ESLint for code formatting and linting:

$ npm run lint

About

Use AI and Slack's workflow builder to review incidents and generate important details for an incident postmortem

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published