An Azure notification API for Slack, Office 365 and more…

James Dumont le Douarec
Microsoft Azure
Published in
3 min readJul 25, 2022

Introduction

In this article, we will see how to use an Azure Logic App to send Slack messages and Office 365 emails.

Logic Apps provide a simple configuration interface for the most popular business integrations, and your app can call them anytime with an HTTP request.

Azure Resources

You can consult here the overview of all Azure Logic Apps connectors, in this article we will use the following ones:

Designer

The Logic app designer view will tell the following story:

  1. Http calls expect to receive the following body:
{
“type”: “slack”,
”title”: “<!channel> :white_check_mark:”,
”description”: “Welcome on board!”,
“to”: “#my-company-notifications”
}

2. The type parameter must be “slack” or “email” otherwise the Logic app will return an http error code.

3. If the type parameter equals “slack” we will send a Slack notification otherwise if it’s “email” we will send an Office 365 Outlook email.

4. In order to reply the API caller that every things worked as expected we will send an HTTP 200 response. That’s good enough for this tutorial. For more information, see the HTTP request/response reference.

Logic app designer

Procedure

  1. Connect to your Azure subscription, if you don’t have an Azure account with an active subscription your can create an account for free here.

2. Copy paste the following url in your browser to launch the ARM Template deployment that will deploy the Logic app with its two connectors, the source code is available here.

https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FJamesDLD%2FAzureRm-Template%2Fmaster%2FCreate-AzNotificationApi%2Ftemplate.json

If you are not familiar with Azure Logic Apps you can consult this tutorial: Send email and invoke other business processes from App Service that will show you how to create a Logic App from the Azure portal.

Connect both connectors to valid Office 365 and Slack accounts, they are available from the API connectors panel of your Logic App.

Office 365
Slack connector

Demo

You can now call your API through its call back url, the following code demonstrates how to do this through PowerShell.

API Call
Et Voilà!

Security

I have two recommendations here when publishing a such API:

  1. Publish it behind a Web Application Firewall (WAF) like Azure Front Door or Azure Application Gateway.
  2. Automate the regeneration of the callback URL access key of your Logic App, it contains your API secret that can be saved and updated on your Azure Key Vault, automate its renewal is a good practice.

Concerning the first recommendation make sure your Azure Logic Apps accepts network calls only from your WAF. This will look like the following diagram.

Web Application Firewall

Concerning the second recommendation you can regenerate the callback URL access key of your Logic App using the following API: Workflows — Regenerate Access Key.

The following code sample demonstrates how to regenerate the callback URL through PowerShell.

Conclusion

Azure Logic Apps provide a simple configuration interface and come with many connectors that ease our solution developments. Don’t underestimate cyber security even with PaaS service, especially when you use connectors with privileges on your IT resources.

See you in the Cloud

Jamesdld

--

--