LogoLogo
SlackLogin
  • Overview
    • Welcome
  • Setup & Configuration
    • Connecting to Trunk
    • Managing Your Organization
      • GitHub App Permissions
  • Integration with Slack
  • Flaky Tests (Beta)
    • Overview
    • Get Started
      • Test Frameworks
        • Android
        • Bazel
        • Behave
        • cargo-nextest
        • Cypress
        • Dart Test
        • Go
        • GoogleTest
        • Gradle
        • Jasmine
        • Jest
        • Karma
        • Maven
        • minitest
        • Mocha
        • Nightwatch
        • NUnit
        • Pest
        • PHPUnit
        • Playwright
        • Pytest
        • Robot Framework
        • RSpec
        • Swift Testing
        • Vitest
        • XCTest
        • Other Test Frameworks
      • CI Providers
        • Azure DevOps Pipelines
        • BitBucket Pipelines
        • Buildkite
        • CircleCI
        • Drone CI
        • GitHub Actions
        • GitLab
        • Jenkins
        • Semaphore CI
        • TeamCity
        • Travis CI
        • Other CI Providers
    • Dashboard
    • Flaky Test Detection
    • Quarantining
    • PR Comments
    • Ticketing Integrations
      • Jira Integration
      • Linear Integration
      • Other Ticketing Platforms
    • Webhooks
      • Slack Integration
      • Microsoft Teams Integration
      • GitHub Issues Integration
      • Linear Integration
    • Uploader CLI Reference
  • Code Quality
    • Overview
    • Why Metalinters?
      • How does it work?
      • Why Code Quality?
    • Setup & Installation
      • Initialize Trunk
      • Local Linting
      • Linting in CI
      • Nightly Report (Deprecated)
    • IDE Integration
      • VSCode
      • Neovim
      • GitHub Codespaces
    • Linters
      • Supported Linters
        • Actionlint
        • Ansible-lint
        • Autopep8
        • Bandit
        • Biome
        • Black
        • Brakeman
        • buf
        • Buildifier
        • cfnlint
        • Checkov
        • circleci
        • ClangFormat
        • clang-tidy
        • Clippy
        • cmake-format
        • codespell
        • cspell
        • cue-fmt
        • dart
        • deno
        • Detekt
        • djlint
        • dotenv-linter
        • dotnet-format
        • dustilock
        • ESLint
        • Flake8
        • git-diff-check
        • Gitleaks
        • Gofmt
        • gofumpt
        • goimports
        • gokart
        • golangci-lint
        • golines
        • google-java-format
        • graphql-schema-linter
        • hadolint
        • haml-lint
        • isort
        • iwyu
        • ktlint
        • kube-linter
        • markdown-link-check
        • markdown-table-prettify
        • Markdownlint
        • markdownlint-cli2
        • mypy
        • nancy
        • nixpkgs-fmt
        • opa
        • OSV-Scanner
        • Oxipng
        • perlcritic
        • perltidy
        • php-cs-fixer
        • phpstan
        • pmd
        • pragma-once
        • pre-commit-hooks
        • Prettier
        • prisma
        • psscriptanalyzer
        • Pylint
        • pyright
        • regal
        • remark-lint
        • renovate
        • rome
        • rubocop
        • Ruff
        • rufo
        • rustfmt
        • scalafmt
        • semgrep
        • ShellCheck
        • shfmt
        • sort-package-json
        • sourcery
        • sql-formatter
        • SQLFluff
        • sqlfmt
        • squawk
        • standardrb
        • stringslint
        • stylelint
        • stylua
        • SVGO
        • swiftformat
        • swiftlint
        • taplo
        • Terraform
        • terragrunt
        • terrascan
        • TFLint
        • tfsec
        • tofu
        • Trivy
        • Trufflehog
        • txtpbfmt
        • vale
        • Yamllint
        • yapf
      • Run Linters
      • Manage Linters
      • Configure Linters
      • Ignoring Issues and Files
      • Custom Linters
      • Shared Configs
      • Upgrades
    • CI Setup
      • GitHub Integration
      • Manual Setup
    • Debugging
    • Licensing
  • Merge Queue
    • Overview
    • How does it work?
    • Setup
      • Quick Start
      • Settings
      • Integration for Slack
    • Concepts and Optimizations
      • Predictive Testing
      • Optimistic Merging
      • Pending Failure Depth
      • Anti-Flake Protection
      • Batching
      • Parallel Queues
        • Bazel
        • Nx
        • API
      • FAQ
    • Priority
    • Managing Merge Queue
      • Using the Merge UI
      • Metrics
      • Command Line
    • Webhooks
    • Reference
  • CLI & API References
    • CLI Reference
      • Install
      • Getting Started
        • Code Quality
        • Merge Queue
        • Flaky Tests
        • Tools
        • Actions
          • Git Hooks
        • Announce
      • Compatibility
      • Caching
      • Commands Reference
        • Code Quality
        • Actions
        • Merge
      • Configuration
        • Plugins
          • Share Config Between Codebases
          • Exporting Linter Configs
        • Runtimes
        • Tools
        • Lint
          • Definitions
          • Commands
          • Output
          • Output Parsing
          • Files and Caching
          • Dependencies
          • Auto-Enable
        • Actions
          • Notifications
          • Logging and Troubleshooting
        • Merge
        • Telemetry
        • Per User Overrides
    • API Reference
      • Flaky Tests
      • Merge Queue
      • Webhooks Reference
  • Pricing & Security
    • Security
  • Billing
  • Community & Support
  • Links
    • Open App
    • Slack Community
    • Changelog
    • Feature Requests
On this page
  • 1. Configure Slack Webhooks
  • 2. Customize Your Transformation
  • 3. Test Your Webhook
  • 4. Monitoring Webhooks
  • Congratulations!
Edit on GitHub
  1. Flaky Tests (Beta)
  2. Webhooks

Slack Integration

Learn how to use flaky test webhooks to power Slack notifications

Last updated 1 month ago

Trunk allows you to create custom workflows to send customized messages to Slack through webhooks.

This guide will walk you through sending Slack messages using event-triggered webhooks. By the end of this tutorial, you'll receive Slack messages for test status changes. This guide should take 10 minutes to complete.

1. Configure Slack Webhooks

Trunk uses Svix to integrate with other services, such as Slack, through webhooks.

You can add the new Slack Webhook URL to Svix by following these steps:

  1. From your profile on the top right, navigate to Settings

  2. Under Organization > Webhooks, click Slack

  3. Click Connect to Slack and select the server and channel to connect to.

  4. By default, this connection will send messages about Trunk Merge and Flaky Tests events. If you only want Flaky Test events, unselect all events other than test_case.status_changed.

  5. Create the new endpoint. You will be redirected to the endpoint configuration view.

2. Customize Your Transformation

Transformations are custom code snippets you can write to customize the Slack messages sent by the webhook. A working template transformation will be added automatically for your webhook, but you can further customize the behavior of this webhook.

  1. In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.

  2. Click Edit transformation to update your transformation code, and click Save to update the transformation.

/**
 * @param webhook the webhook object
 * @param webhook.method destination method. Allowed values: "POST", "PUT"
 * @param webhook.url current destination address
 * @param webhook.eventType current webhook Event Type
 * @param webhook.payload JSON payload
 * @param webhook.cancel whether to cancel dispatch of the given webhook
 */
function handler(webhook) {
  const payload = {"text": summarizeTestCase(webhook.payload)}
  
  webhook.payload = payload
  return webhook
}

function summarizeTestCase(payload) {
    if (!payload || typeof payload !== 'object' || !payload.test_case) {
        return "Error: Invalid or missing payload.";
    }

    const {
        test_case: {
            name = "N/A",
            file_path = "N/A",
            status = {},
            quarantine = false,
            repository = {},
            codeowners = [],
            failure_rate_last_7d = 0,
            most_common_failures = [],
            pull_requests_impacted_last_7d = 0,
            ticket = {},
            html_url = "N/A"
        }
    } = payload;

    const statusSummary = `Status: ${status.value || "Unknown"} `
        + `(Reason: ${status.reason?.trim() || "N/A"}, `
        + `Updated: ${status.timestamp ? new Date(status.timestamp).toLocaleString() : "Unknown"})`;

    const quarantineStatus = quarantine 
        ? "This test is currently quarantined." 
        : "This test is not quarantined.";

    const failureSummary = most_common_failures.map(failure =>
        `- ${failure.summary} (${failure.occurrence_count || 0} occurrences, `
        + `last seen: ${failure.last_occurrence ? new Date(failure.last_occurrence).toLocaleString() : "Unknown"})`
    ).join("\n");

    const repoLink = `Repository: ${repository.html_url || "N/A"}`;
    const testLink = `Test Details: ${html_url}`;
    const ticketLink = `Related Ticket: ${ticket.html_url || "N/A"}`;
    const ownerSummary = `Codeowners: \`${codeowners.join(", ") || "None"}\``;
    const statsSummary = `Failure rate (last 7 days): ${(failure_rate_last_7d * 100).toFixed(1)}% `
        + `| PRs Impacted: ${pull_requests_impacted_last_7d}`;

    return [
        `Test Name: \`${name}\``,
        `File Path: \`${file_path}\``,
        statusSummary,
        quarantineStatus,
        `Most Common Failures:\n${failureSummary}`,
        ownerSummary,
        statsSummary,
        repoLink,
        testLink,
        ticketLink
    ].join("\n");
}

3. Test Your Webhook

You can send test messages to your Slack channels as you make updates. You can do this by:

  1. In the endpoint configuration view, navigate to the Testing tab and select a Send event

  2. Under Subscribed events, select test_case.status_changedas the event type to send.

  3. Click Send Example to test your webhook

4. Monitoring Webhooks

You can monitor the events and the webhook's delivery logs in the Overview tab of an endpoint configuration view.

You can see an overview of how many webhook deliveries have been attempted, how many are successful, how many are in flight, and how many fail in the Attempt Delivery Status modal.

Congratulations!

You should now receive notifications in your Slack workspace when a test's status changes. You can further modify your transformation script to customize your messages.

Login to

Review the transformation code automatically generated for GitHub issues. You can customize this transformation at any time. Learn more about .

If you're having trouble adding a new webhook endpoint with Svix, please see the .

You can test the transformation by selecting the test_case.status_changed payload and clicking Run Test. This will test the transformation but not send a message. You will learn to send a test message in .

An example transformation script is provided below and you can customize your Slack integration by following the and documentation.

You can see a list of past delivery attempts in the Message Attempts modal. You can filter this list by Succeeded and Failed status, and you can click on each message to see the Message content, response code, and error message of each attempt. You can learn more about and in the Svix docs.

Trunk Flaky Tests
Adding Endpoint docs from Svix
Slack
Svix transformations
replaying messages
filtering logs
See the Trunk webhook event catalog
Learn more about consuming webhooks in the Svix docs
Learn more about the Slack API
customizing transformations
step 3