- Azure Serverless Computing Cookbook
- Praveen Kumar Sreeram
- 221字
- 2021-06-10 18:56:01
How to do it...
Perform the following steps:
- Navigate to the Application settings blade of the function app and add two keys to store TwilioAccountSID and TwilioAuthToken, shown as follows:
- Go the Integrate tab of the SendNotifications function, click on New Output, and choose Twilio SMS.
- Click on Select and provide the following values to the Twilio SMS output bindings. Please install the extensions of Twilio. The From number is the one that is generated in the Twilio portal, which we discussed in the Getting ready section of this recipe:
- Navigate to the code editor and add the following lines of code, highlighted in bold. In the following code, I have hardcoded the To number. However, in real-world scenarios, you would dynamically receive the end user's mobile number and send the SMS via code:
...
...
#r "Twilio"
#r "Microsoft.Azure.WebJobs.Extensions.Twilio"
...
...
using Microsoft.Azure.WebJobs.Extensions.Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
public static void Run(string myQueueItem,
out SendGridMessage message,
IBinder binder,
out CreateMessageOptions objsmsmessage,
ILogger log)
...
...
...
message.AddAttachment(FirstName +"_"+LastName+".log",
System.Convert.ToBase64String
(System.Text.Encoding.UTF8.GetBytes(emailContent)),
"text/plain",
"attachment",
"Logs"
);
objsmsmessage = new CreateMessageOptions(new PhoneNumber
("+91 98492*****"));
objsmsmessage.Body = "Hello.. Thank you for getting
registered.";
}
- Now, do a test run of the RegisterUser function using the same request payload.
- The following is the screenshot of the SMS that I have received: