Retrieving the UserProfile information in the SendNotifications trigger

Perform the following steps:

  1. Navigate to the SendNotifications function, in the run.csx file and add the NewtonSoft.Json reference and the namespace. 
  1. The Queue Trigger will receive the input in the form of a JSON string. We will use the JsonConvert.Deserializeobject method to convert the string into a dynamic object so that we can retrieve the individual properties. Replace the existing code with the following code where we are dynamically populating the properties of SendGridMessage from the code:
#r "SendGrid"
#r "Newtonsoft.Json"
using System;
using SendGrid.Helpers.Mail;
using Newtonsoft.Json;

public static void Run(string myQueueItem,
out SendGridMessage message,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed:
 {myQueueItem}");
dynamic inputJson = JsonConvert.DeserializeObject(myQueueItem);
string FirstName=null, LastName=null, Email = null;
FirstName=inputJson.FirstName;
LastName=inputJson.LastName;
Email=inputJson.Email;
log.LogInformation($"Email{inputJson.Email}, {inputJson.FirstName + " " + inputJson.LastName}");
message = new SendGridMessage();
message.SetSubject("New User got registered successfully.");
message.SetFrom("donotreply@example.com");
message.AddTo(Email,FirstName + " " + LastName);
message.AddContent("text/html", "Thank you " + FirstName + " " + LastName +" so much for getting registered to our site.");
}
  1. Let's run a test by adding a new input field email to the test request payload, shown as follows:
        {
"firstname": "Praveen",
"lastname": "Sreeram",
"email":"example@gmail.com",
"ProfilePicUrl":"A Valid url here"
}
  1. This is the screenshot of the email that I have received: