Slack Integration
Last updated
Last updated
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.
You need to create a Slack app for your Slack workspace to receive webhooks from Trunk Flaky Tests.
Head to Slack API
Click Create New App to create a new app
This will open the Create an App modal. Select From scratch.
Fill in a display name for your Slack bot under App Name and select the Workspace to which the bot will post messages.
Click Create App. You will be redirected to your App's settings
For the new Slack app created, you need to enable incoming webhooks and add a webhook to your workspace.
In your Slack app's settings, under Features, navigate to Incoming Webhooks
Toggle Activate Incoming Webhooks
Click Add New Webhook to Workspace and select the channel messages should be posted in. Click Allow to add the new endpoint.
Copy the Webhook URL, such as https://hooks.slack.com/services/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
Trunk uses Svix to integrate with other services, such as Slack, through webhooks.
You can add the new Slack Webhook URL to Svix by:
Login to Trunk Flaky Tests
From your profile on the top right, navigate to Settings
Under Organization > Webhooks, click Add Endpoint
Paste the Webhook URL from Slack into Endpoint URL
Under Subscribe to events, select test_case.status_changed
Create the new endpoint. You will be redirected to the endpoint configuration view.
If you're having trouble adding a new webhook endpoint with Svix, please see the Adding Endpoint docs from Svix.
Next, you need to create a custom transformation to turn the Trunk Flaky Tests event into a Slack message.
In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
Click Edit transformation to create a custom transformation script.
Copy and paste the transformation script below and click Save. You can modify this script to customize your Slack message. You can find what's available in the webhook payload in the events reference.
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 step 5.
An example transformation script is provided below and you can customize your Slack integration by following the Slack and Svix transformations documentation.
You can send test messages to your Slack channels as you make updates. You can do this by:
In the endpoint configuration view, navigate to the Testing tab and select a Send event
Under Subscribed events select test_case.status_changed
as the event type to send.
Click Send Example to test your webhook
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.
See the Trunk webhook event catalog
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 Stats modal.
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 replaying messages and filtering logs in the Svix docs.
Want to chat with Trunk's engineers? Join us and 1500+ fellow engineers on Slack.