Trunk allows you to create custom workflows to send customized messages to Microsoft Teams channels through webhooks.

This guide will walk you through sending Microsoft Teams messages using event-triggered webhooks. By the end of this tutorial, you'll receive Microsoft Teams messages for test status changes. This guide should take 10 minutes to complete.
Microsoft has two different concepts for accepting incoming webhooks. Connectors that are being deprecated and Workflows that are for newly created teams. This guide is for the newer Workflows. The workflow for configuring webhooks is similar, but you may see small differences. You can find more about the soon to be deprecated connectors in Microsoft's documentation.
- Open the team in which you want to add the webhook and select the kebab menu (•••) from the upper-right corner.
- Select Workflows from the dropdown menu.
- Search for
Post to a channel when a webhook request is received
, select the workflow, then click Next. - Configure the workflow's Microsoft Teams Team and Microsoft Teams Channel, then click Add workflow.
- When the workflow is added correctly, you can copy the URL displayed, then click Done.
Trunk uses Svix to integrate with other services, such as Microsoft Teams messages through webhooks.
You can create a new endpoint by:
-
Login to Trunk Flaky Tests
-
From your profile on the top right, navigate to Settings
-
Under Organization > Webhooks, click Teams
-
Paste your Microsoft Teams Workflow URL from the previous step into Endpoint URL.
-
Review the transformation code automatically generated for Teams messages. You can customize this transformation at any time. Learn more about customizing transformations.
-
Create the new endpoint. You will be redirected to the endpoint configuration view.
Transformations are custom code snippets you can write to customize the Microsoft Teams messages created by the webhook. A working template transformation will be added automatically for your webhook, but you can further customize the behavior of this webhook.
- In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
- Click Edit transformation to update your transformation code, and click Save to update the transformation.
- 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 4.
Below is an example of a webhook transformation to format the messages as Actionable Messages. If you're having trouble adding a new webhook endpoint with Svix, please see the Adding Endpoint docs from Svix.
/**
* @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) {
// See https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook
webhook.payload = summarizeTestCase(webhook.payload);
return webhook;
}
function summarizeTestCase(payload) {
if (!payload || typeof payload !== 'object' || !payload.test_case) {
return {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
contentUrl: null,
content: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
type: "AdaptiveCard",
version: "1.2",
body: [{
type: "TextBlock",
text: "Error: Invalid or missing payload received by Trunk Flaky Test Webhook Transformation.",
color: "attention"
}]
}
}]
};
}
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 statusTimestamp = status.timestamp
? new Date(status.timestamp).toLocaleString()
: "Unknown";
const failureBlocks = most_common_failures.map(failure => ({
type: "TextBlock",
text: `• ${failure.summary}`,
wrap: true,
spacing: "small"
}));
return {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
contentUrl: null,
content: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
type: "AdaptiveCard",
version: "1.2",
body: [
{
type: "TextBlock",
text: name,
size: "large",
weight: "bolder"
},
{
type: "TextBlock",
text: file_path,
isSubtle: true,
spacing: "none"
},
{
type: "FactSet",
facts: [
{
title: "Status",
value: `${status.value || "Unknown"} (${status.reason?.trim() || "N/A"})`
},
{
title: "Last Updated",
value: statusTimestamp
},
{
title: "Quarantine Status",
value: quarantine ? "Quarantined" : "Not Quarantined"
},
{
title: "Failure Rate (7d)",
value: `${(failure_rate_last_7d * 100).toFixed(1)}%`
},
{
title: "PRs Impacted (7d)",
value: pull_requests_impacted_last_7d.toString()
},
{
title: "Codeowners",
value: codeowners.join(", ") || "None"
}
]
},
{
type: "TextBlock",
text: "Most Common Failures",
weight: "bolder",
spacing: "medium"
},
...failureBlocks,
{
type: "ActionSet",
actions: [
{
type: "Action.OpenUrl",
title: "View Repository",
url: repository.html_url || "#"
},
{
type: "Action.OpenUrl",
title: "View Test Details",
url: html_url || "#"
},
{
type: "Action.OpenUrl",
title: "View Related Ticket",
url: ticket.html_url || "#"
}
]
}
]
}
}]
};
}
You can send test messages to your Microsoft Teams 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
{% include "../../.gitbook/includes/monitoring-webhooks (1).md" %}
You should now receive notifications in your Teams channel when a test's status changes. You can further modify your transformation script to customize your messages.

See the Trunk webhook event catalog