public static ActivityResult SendSmsChallenge( [ActivityTrigger] VerificationParameter phone, [Microsoft.Azure.WebJobs.Table("approval", "AzureWebJobsStorage")] CloudTable table, ILogger log, [TwilioSms(AccountSidSetting = "TwilioAccountSid", AuthTokenSetting = "TwilioAuthToken", From = "%TwilioPhoneNumber%")] out CreateMessageOptions message) { try { int challengeCode = GetChallengeCode(); log.LogInformation($"Sending verification code {challengeCode} to {phone.Payload}."); var entity = new ApprovalEntity(phone.OrchestrationId, "NewMember", challengeCode, EventNameSms); log.LogInformation(SimpleJson.SimpleJson.SerializeObject(entity)); table.AddToTableStorageASync(entity).GetAwaiter().GetResult(); message = new CreateMessageOptions(new PhoneNumber(phone.Payload)); message.Body = $"Your verification code is {challengeCode:0000}"; return(new ActivityResult { HasError = false, Value = challengeCode }); } catch (Exception ex) { message = null; return(new ActivityResult { HasError = true, Value = ex.Message }); } }
public static async Task <ActivityResult> SendEMailVerification( [ActivityTrigger] VerificationParameter eMail, [Microsoft.Azure.WebJobs.Table("approval", "AzureWebJobsStorage")] CloudTable table, ILogger log, Microsoft.Azure.WebJobs.ExecutionContext context) { var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", true, true) .AddEnvironmentVariables() .Build(); string uriFlow = config["flowRESTTarget"]; log.LogInformation(config.ToString()); int challengeCode = GetChallangeCode(); try { var valueObject = new SendMail { emailadress = eMail.Payload, emailSubject = "Confirmation of membership - " + challengeCode, emailBody = $"http://{Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME")}/api/approve/{challengeCode}" }; var entity = new ApprovalEntity(eMail.OrchestrationId, "NewMember", challengeCode, EventNameEMail); await table.AddToTableStorageASync(entity); var client = new RestClient(uriFlow); var request = new RestRequest(Method.POST); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("undefined", SimpleJson.SimpleJson.SerializeObject(valueObject), ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (!response.IsSuccessful) { log.LogError(new EventId(1, "EMail not sent"), $"EMail to receiver {valueObject.emailadress} could not be sent. Error: {response.Content}"); } return(new ActivityResult { HasError = false, Value = challengeCode }); } catch (Exception ex) { return(new ActivityResult { HasError = true, Value = ex.Message }); } }