Beispiel #1
0
        public async Task <TwiMLResult> Index([FromForm] SmsRequest request)
        {
            var response = new MessagingResponse();

            if (whitelist.TryGetValue(request.From, out string email))
            {
                log.LogTrace($"Forwarding message from {request.From}/{email}: {request.Body}");
                await codeRed.SendMessage(email, request.Body);
            }
            else
            {
                log.LogWarning($"Rejected message from {request.From}: {request.Body}");
                response.Message("Unknown number. Page not sent.");
            }

            return(TwiML(response));
        }
        public async Task <IActionResult> Index([FromForm] SendMessageModel model)
        {
            if (ModelState.IsValid)
            {
                if (armed)
                {
                    await codeRed.SendMessage($"{User.FindFirst("email")?.Value}", model.Message);
                }

                return(RedirectToAction(nameof(Success), new SuccessModel
                {
                    When = DateTime.Now.ToString("HH:mm ddd"),
                    Message = (armed ? string.Empty : "[disarmed] ") + model.Message
                }));
            }

            return(View());
        }