- Azure Serverless Computing Cookbook
- Praveen Kumar Sreeram
- 218字
- 2021-06-10 18:55:59
Retrieving the UserProfile information in the SendNotifications trigger
Perform the following steps:
- Navigate to the SendNotifications function, in the run.csx file and add the NewtonSoft.Json reference and the namespace.
- 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.");
}
- 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"
}
- This is the screenshot of the email that I have received: