How to do it...

Perform the following steps:

  1. Create a new function by choosing the HTTP trigger, and name it ValidateTwitterFollowerCount.
  1. Navigate to the Integrate tab and add a new output binding, SendGrid, by clicking on the New Output button:

  1. Replace the default code with the following and click on Save. The following code just checks the followers count and if it is greater than 200, it sends out an email:
#r "Newtonsoft.Json"
#r "SendGrid"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using SendGrid.Helpers.Mail;
public static async Task<IActionResult> Run(HttpRequest req, IAsyncCollector<SendGridMessage> messages, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string name = req.Query["name"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);

string strTweet = "";
SendGridMessage message = new SendGridMessage();
if(data.followersCount >= 200)
{
strTweet = "Tweet Content" + data.tweettext;

message.SetSubject($"{data.Name} with {data.followersCount} followers has posted a tweet");
message.SetFrom("donotreply@example.com");
message.AddTo("prawin2k@gmail.com");
message.AddContent("text/html", strTweet);

}
else
{
message = null;
}
await messages.AddAsync(message);
return (ActionResult)new OkObjectResult($"Hello");
}
  1. Test the function using Postman by choosing the parameters highlighted in the following screenshot. In the next steps, after we integrate the ValidateTwitterFollowerCount Azure Function, all the following input parameters, such as followersCount, tweettext, and Name, will be posted by the Twitter connector of the Logic App:

  1. Create a new Logic App named NotifywhenTweetedbyPopularUserUsingFunctions.
  2. Start designing the app with the Blank logic app template, choose the Twitter connector, and configure Search text, Frequency, and Interval.
  1. Click on New step to add an action. In the Choose an action section, choose Azure Functions as a connector, as shown in the following screenshot:

  1. Clicking on Azure Functions will list all the available Azure function apps, as shown in the following screenshot:

  1. Click on the function app in which you have created the ValidateTwitterFollowerCount function. Now, select the ValidateTwitterFollowerCount function, as shown in the following screenshot:

  1. Now you need to prepare the JSON input that needs to be passed from the Logic App to the ValidateTwitterFollowerCount HTTP trigger function that we developed. Let's frame the input JSON in the same way that we did when testing the HTTP trigger function using Postman, as shown in the following screenshot (the only difference is that the values, such as followersCount, Name, and tweettext, are dynamic now):

  1. Once you have reviewed all the parameters that the ValidateTwitterFollowerCount function expects, click on the Save button to save these changes.
  2. You can wait for a few minutes or post a tweet with the hashtag that you have configured in the Search text input field.