Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel

{tocify} $title={Table of Contents}


Introduction

In most of the interfaces there is a need send some alert message to stake holders notifying about some errors or about some specific conditions.

Recently, in one of the interface the ask was to send alert messages(warning/issue/errors) to a slack channel where the business users were able to get notified instantly.

What is Slack Channel?

Slack is a messaging app for business that connects people to the information they need. (On same line as Microsoft Teams)

And Slack channel is a dedicated space for conversations that can be created for any project, topic, or team

 
So how do we integrate Logic App with Slack channel? Is there a out of box connector available for Slack?

Ways to connect to Slack channel


There are couple of ways to go about it, 

1. Using connector

Yes, there is a connector provided by Microsoft to connect to Slack.

Before we use connector, let's first create a workspace in Slack. Go to slack (https://slack.com/intl/en-in/get-started#/createnew)

Enter your email address and continue. Provide the code received over email and continue.


On the first step, provide the name of your workspace 


Provide your name and photo(optional)


Add team members in the workspace


In the last step provide the name of channel. And we are ready to use it.

We will post message to this channel from Logic app using the slack connector

Let's create logic app


Create logic app, provide name, region and select plan type.


For the sake of demo, creating a simple logic app which will be triggered by http request and will post to slack (same message received over http trigger).

Add new action and search for Slack. Select Post message (V2) from Actions


The screen will ask you to Sign in , click on it


Click on Allow to permit Logic App to interact with Slack workspace


Once connected to the workspace, Configure Post message slack action


select the Channel name(demoproject) where you want to post messages and provide value against Message Text(body of http request)

Save the workflow and that's it, ready for testing. 

Now run the logic app, with some data . And check the slack channel if message is reached.



As can be seen in above image, message reached to Slack channel which was sent by Logic App.


2. Using Http action (calling slack channel webhook)

Another option is to use http action in logic app and interact with slack channel, but for that we need to create an App in slack and webhook on top of slack channel.

Go to https://api.slack.com/apps


Click on Create an App to create slack workspace app


create an app from scratch


Provide name for App and select workspace for which you want to create app


App is created, Select Incoming webhooks



Select Incoming webhooks and against Activate Incoming Webhooks - ON it

Click on Add New Webhook to Workspace


Grant permission to the App ,select the channel for which you want webhook to be created.


Copy the webhook url and use it in Logic app to post messages

We will post message to this channel from Logic app over the webhook url

Let's create logic app


For the sake of demo, creating a simple logic app which will be triggered by http request and will post to slack channel over the webhook (same message received over http trigger).


Followed by Http action, with method as POST, configure slack webhook url against URI and against Body -

                                            {
                                                  "text": "@{triggerBody()}"
                                            }

So whatever is received over http request is pushed to slack channel.

Note: using text is mandatory and payload should be valid JSON, else it will not be accepted.

Save the logic app and test it.


If you see in above snap, it shows that message is posted by DemoProjectApp and not Logic app. 

It is because we had created the webhook for channel through this App, and the url generated is associated to this App.


Summary

We saw that we have two options to post messages to slack channel and off course this will raise a question - which one to use?

What I observed is that - with slack connector you have to manually authorize every time you deploy the logic app to another environment .




And that is not required in case of webhook url, as the auth code is already part of the URL .

So, my preferred option is go with Webhook way !!!




This post first appeared on TechFindings, please read the originial post: here

Share the post

Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel

×

Subscribe to Techfindings

Get updates delivered right to your inbox!

Thank you for your subscription

×