⚠️ Update: I experienced some issues running this on a Subscription Plan. Errors included multiple alert messages per trigger, and some few messages being lost. I suspect this to be related to cold starting. I strongly suggest testing it for a certain period of time before going to production, and I would also suggest considering an App Service Plan for the function to run in a dedicated 24/7 VM. Read more here: https://blogs.msdn.microsoft.com/appserviceteam/2018/02/07/understanding-serverless-cold-start/


If you follow the official PagerDuty integration guide for Microsoft Teams, you are instructed to configure a generic webhook which posts to an official PagerDuty Connector in Teams. This works like a charm, and you’ll be up and running in minutes. The output, however, is not very rich, and you’ll be left with no actual information about what the alert is about: Default PagerDuty Teams integration To circumvent the limitations of the official integration, I set out to give the webhook another jump before it hits Teams, to be able to manipulate and enrich messages sent. To do this, I created a very simple web API endpoint using an Azure Functions App and a few lines of JavaScript code. It basically works by having PagerDuty post to the Azure Function, which in turn massages the content, and finally relays it on to the Teams Connector (webhook). Azure Function code here Here’s how to set it up:


1. Set up the Teams Connector

First go to the channel in which you want alerts to be posted. There you’ll find the “Connectors” option: Teams Connectors menu option From there you’ll be able to configure a new Incoming Webhook. Give it a name and upload an icon (optional). After the creation you will be presented with the URL of the webhook. Remember to copy this URL, as you’ll need it later.


2. Create the Azure Function App

Log on to your Azure Portal and create a new Functions App. Give it a name and select a hosting location. Go with Windows OS. Once the Function App has been created, add a new “HTTP trigger” function, and name it something meaningful (i.e. “pagerduty”). The language setting must be set to “JavaScript”: New Azure Function Http trigger Next, go to the “Integrate” menu option below your newly created function, and set the “Allowed HTTP methods” option to “Selected methods”. Make sure only “POST” is checked: Azure Http trigger configuration Then go to the function code view and paste the contents of this file. After pasting it, replace the teamsWebhookPath variable with the webhook URL you created in step 1. Make sure to only add the path of the URL, without the domain name (see example below): Paste Azure Function code and set URL Now click the “Get function URL” link, and you will be presented with the function URL used to post requests to your new endpoint. Copy it, you’ll need it in a minute. Next, hit save, and the function should be up and running!


3. Configure the PagerDuty extension

The only remaining step is to set up an extension in PagerDuty from which alerts will be sent when a service triggers an alert. Log on to your company PagerDuty account, go to the Extensions menu (Configuration -> Extensions), and add a new “Generic V2 Webhook” extension, using the function URL as the webhook URL, and map it to a service: PagerDuty webhook extension  

4. Test it!

The integration should now be up an running. Test it by manually creating an incident or by triggering an actual alert from the service. As alerts are being triggered, acknowledged and resolved, messages should appear in your Teams channel: Microsoft Teams alerts from PagerDuty If there’s something you want to change, simply make changes to the code in the Azure Function to better suit your needs. You should be able to add more information about who the incident is assigned to, notes and more. These useful tools will help you get it right:

If you come up with a better design layout, or have any other improvements or suggestions, let me know!


Please note: These comments are exports from an older platform, and are no longer active.

Ben Horstmann - Oct 3, 2018

Sindre this is great, thank you for sharing with the community! In your example, do the contents of your ‘Azure Function’ file get pasted into one of the default files (function.json or run.csx)? Or did you create a new index.js file (index.js is not a file in new functions). Thanks again for sharing this with the community and keep up the great work! -Ben from STL

sssss - Jun 3, 2020

I Have changed the card, but the data is not reflecting in my format. where can I update the format.

Luke - May 3, 2019

Is there a way to make this so that replies in teams are added to pagerduty as notes? or to add a acknowledge button in teams?

Gandhi - Jun 1, 2019

So this is 2-way integration? Can we create an issue in pagerduty via ms teams as well?

sindre - Jun 1, 2019

This is a one-way integration for publishing PagerDuty incident updates in a Microsoft Teams channel.

sindre - May 4, 2019

Hi Ben, Sorry for the late reply - I’m sure you’ve figured it out by now! When you create a new JavaScript Function, the index.js file should be created by default. If you’re seeing a run.csx file, you’ve probably created a C# Function. -Sindre

sindre - May 4, 2019

I did make an attempt to set up MessageCards with Acknowledge and Resolve buttons, and got it working, but it was a rather complicated setup with return API calls to the PagerDuty API via additional Azure Functions. I never got it to be as seamless as the Slack bot integration, which is really good. I hope (and expect) PagerDuty to make an official integration similar to the Slack bot at some point. I suspect the only way to make a truly interactive integration with notes and action buttons would be by creating a bot, in which case I think the Microsoft Bot Framework might be a good starting point.