public async Task NextStage(Incident incident) { incident.WentToVoicemail = false; var stage = CallSequence[incident.Index]; if (stage.Attempts > 1 && incident.Attempt < stage.Attempts) { incident.Attempt++; await StatusHub.UpdateClientAsync(incident.UserId, "phoneDelay", stage.Delay.ToString(), HttpContext); await Task.Delay(stage.Delay * 1000); } else { incident.Index++; incident.Attempt = 1; if (incident.Index >= CallSequence.Count) { await StatusHub.UpdateClientAsync(incident.UserId, "phoneFail", null, HttpContext); return; } stage = CallSequence[incident.Index]; } var phoner = new Phoner(); await phoner.CallAsync(incident, stage, Configuration["Twilio:FromNumber"], HttpContext); }
public async Task <IActionResult> Post(string studentName, string room, int priority) { if (string.IsNullOrWhiteSpace(studentName) || string.IsNullOrWhiteSpace(room) || priority < 1 || priority > 2) { return(StatusCode(500, "Invalid inputs.")); } if (!BritishTime.IsSchoolHours()) { return(StatusCode(500, "This service is unavailable out of hours.")); } var userId = User.Identity.GetUserId(); var incident = new Incident(Guid.NewGuid().ToString("D"), studentName.Split(',')[0].ToTitleCase(), room, User.Identity.Name, userId); if (priority == 1) { Cache.Set(incident.Id, incident, TimeSpan.FromMinutes(20)); var phoner = new Phoner(); await phoner.CallAsync(incident, CallSequence[0], Configuration["Twilio:FromNumber"], HttpContext); } var mailer = new Mailer(Configuration["Email:SenderEmail"], Configuration["Email:SenderPassword"], Configuration["Email:To"], Configuration["Email:Bcc"]); await mailer.SendAsync(studentName, room, User.Identity.Name, priority, User.Identity.GetEmail()); await StatusHub.UpdateClientAsync(userId, "emailSent", priority, HttpContext); return(new EmptyResult()); }