How to use Microsoft Flow to send an email when an event occurs- Experiment #102

Discover How to use Microsoft Flow to send an email when an event occurs- Experiment #102 

In this new post we are going to show you how to use Microsoft Flow to automatically send an email when a database record with negative sentiment is created. As part of our Experiment #102 this flow will help the hotel staff to manage critical situations and solve problems quickly.


1.  Preliminary Considerations


We have created a very simple C# console project to simulate the reception of hotel reviews. The program makes HTTP requests to the different services we have previously deployed to collect all the information from the image and text of the review. These services include containerized services like Summarize or Classification and Cognitive Services like Computer Vision or Text Analytics.

All review data will be stored in a SQL database. This is the database definition:


CREATE TABLE [dbo].[review](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [text] [nvarchar](MAX) NULL,
    [class] [nvarchar](64) NULL,
    [sentiment] [nvarchar](64) NULL,
    [summary] [nvarchar](2048) NULL,
    [keys] [nvarchar](1024) NULL,
    [image] [nvarchar](1024) NULL,
    [captions] [nvarchar](1024) NULL,
    [categories] [nvarchar](1024) NULL,
    [tags] [nvarchar](1024) NULL,
    CONSTRAINT [PK_review] PRIMARY KEY ([id])


Here it is a service request example using Microsoft Azure Cognitive Services NuGet packages to extract the sentiment of the review text:


public static TextAnalyticsClient AuthenticateText(string endpoint, string key)
    TextAnalyticsClient client =
        new TextAnalyticsClient(new ApiKeyServiceClientCredentials(key))
        { Endpoint = endpoint };
    return client;

public static async Task SentimentAnalysis(TextAnalyticsClient client, string text)
    var analysis = await client.SentimentAsync(text, "en");

    var sentiment = string.Empty;

    if (analysis.Score < 0.4)
        sentiment = "Negative";
    else if (analysis.Score > 0.6)
        sentiment = "Positive";
        sentiment = "Neutral";

    review.Sentiment = sentiment;


When a review has been analyzed, a new database record is created and then, the Microsoft Flow process is launched.


2. Create the Microsoft Flow Template


Microsoft Flow has a lot of templates with different triggers, but we are going to create a custom flow for our Experiment. We must start by visiting the Microsoft Flow website.

In the next animation you will see how to configure all the steps:



Our flow will be triggered when a new review arrives to the database. After that, we will check the ‘sentiment’ field of the new record. If the value is equal to “Negative” an email with all the information will be sent to the hotel staff.


3. See the Experiment #102 in action


Now, it’s time to see the Experiment #102 in action. We will send some simulated reviews with text and image with the help of our console application and then we will follow all the process from the analysis to the email sending:


Stay up to date!

Leave a comment