Creating A Function App And Integrating With Azure Logic Apps

Introduction

In this article I will explain about integrating the function app with Azure logic application. It means that the function app will be used with the third party services, so that we can do it by using the function app with both logic and cognitive services for the analyzing and monitoring of Twitter recent posts by triggering the function of HTTPS triggered functions.

Prerequisites

  • An active Azure subscription
  • An outlook email id or gmail id for sending the notifications, (I will recommend gmail for sending the email notifications since the outlook mail id will be logged in while using the azure services).

First we need to create the cognitive service account

Step 1

Login into Azure portal.

Step 2

Click->new->Data+Analytics and select->Cognitive services.

Step 3

Now we need to configure some of the basic settings such as,

  • Provide a unique name for the service.
  • Now select the API type as-> Text analytics API(Preview).
  • Select the location of the data center
  • Select the pricing tier of the service as your wish.
  • Create a resource group of the service and
  • Click->Create, the service will be created and the successful notifications will be displayed after few minutes.

Step 4

From the created service select->keys make a note down of the keys, since it will be used later in process.

Now begins the process of creating the function app

Step 5

Click New->Compute->Function app.

Step 6

Now, we need to provide the requirements given below for Functions app.

We need to provide an app name for Function app with the unique name.

Create a resource group and provide a name for your resource group.

The hosting part consists of consumption plan & app Service plan.

The consumption plan is default plan, but when we choose the consumption plan; we need to choose the location.

In concept of app Service plan; we need to create an app plan +location. It defines the location and features with cost with the sources with the app.

The storage account has to be configured, so that we can either choose the existing storage or we can create a new storage account.

Step 7

Click->Create to deploy Function app.

Step 8

For creating a HTTP triggered function, we need to create a function in new function application. In the function app expand the function app and select + button in the functions, and select the scenario with the desired programming language. I have selected C# but you can select the programming template of your own desire and click-> create functions for view of complete set of function templates of it.

Step 9

Now select->HTTP triggered-c# template and provide a name for the function and click->create.

Step 10

After selecting the template and with renaming the function, we need to replace the code in run.csx fle and click->save. I have provided the code for replacing in run.csx

 

  1. using System.Net;  
  2. publicstatic async Task < HttpResponseMessage > Run(HttpRequestMessage req, TraceWriter log) {  
  3.     // The sentiment category defaults to 'GREEN'.  
  4.     string category = "GREEN";  
  5.     // Get the sentiment score from the request body.  
  6.     double score = await req.Content.ReadAsAsync < double > ();  
  7.     log.Info(string.Format("The sentiment score received is '{0}'.", score.ToString()));  
  8.     // Set the category based on the sentiment score.  
  9.     if (score < .3) {  
  10.         category = "RED";  
  11.     }  
  12.     elseif(score < .6) {  
  13.         category = "YELLOW";  
  14.     }  
  15.     return req.CreateResponse(HttpStatusCode.OK, category);  
  16. }  

 

Step 11

After saving the run.csx file, we can test the function. Click->test in right side and type a value of 0.2 in request body and click->run. Soon the response will be generated with the value RED as shown. So far now we have created a function app and cognitive service and we can proceed to next step.

Proceed for Creating a logic app

Step 12

Click New->Enterprise Intergration ->Logic app.

Step 13

Now, we need to configure the basic settings for an Azure Logic app. Provide a unique name for Logic app and select a Resource group. If you already have an existing resource group, select Existing group or select a New resource group. Select Datacenter location. Click->Create.

Step 14

The creation of Logic app shows the basic templates. Now, we can select the blank Logic app, so that we can create Logic app.

Step 15

Now we can use the logic app for adding the services to the applications. In the designer click->Twitter and you will be need to sign-in into the twitter account and click->sign-in.

Step 16

After sign-ing in in to your Twitter account, use the Twitter triggered settings and click->save for connecting to Twitter account.

Step 17

The account will be connected and now we can add the sentiment detection.

->Click->new step and select->Add an action.

->From the action selection-> click->Text analytics and this is where we need to paste the cognitive service name and the key that we have noted down on creating the cognitive service and click->create.




Step 18 

Select->Tweet text and click->save for configuring the detection of the sentiment.

Connecting the sentiment to the output of the function

Step 19

In app designer, click->New step-> add an action and click->Azure functions.

Step 20

From the request body of it, click->score and click->save.

Step 21

Here comes the last part of the workflow, now we need to trigger the email service and use the outlook connector or you can use gmail connector. I recommend use of gmail, since the outlook has been signed in with azure portal you can’t use the outlook connector.

Step 22

In the designer of logic app click->new step and select->Add a condtion.

Step 23

Choose the value of the body and click->body and select->is equal to and click->choose a value and click->save.

Step 24

In YES DO NOTHING, click-> Add an action and search for gmail and click->send an email and sign-in into gmail account

Step 25

Use the email settings in send email action and click->save.

Step 26

In logic app designer select->overview and in left column we can see the status of the logic app working.

Step 27

select->one of the run to see the details of execution, and hence we have integrated the functions into logic app.

I hope you have learned something new, Thanks for reading and have a nice day.

Up Next
    Ebook Download
    View all
    Learn
    View all