Esempio n. 1
0
        internal async Task InvokeAsync(HttpContext httpContext)
        {
            try
            {
                if (httpContext.Request.Method == "GET")
                {
                    var webhook = WebhookParser.ParseQuery <T>(httpContext.Request.Query);
                    _handler(webhook);
                }
                else if (httpContext.Request.Method == "POST")
                {
                    var webhook = await WebhookParser.ParseWebhookAsync <T>(httpContext.Request.Body, httpContext.Request.ContentType);

                    _handler(webhook);
                }
                httpContext.Response.StatusCode = 204;
            }
            catch (Exception)
            {
                httpContext.Response.StatusCode = 500;
            }
            if (_invokeNext)
            {
                await _next(httpContext);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> DeliveryReceipt()
        {
            var dlr = WebhookParser.ParseQuery <DeliveryReceipt>(Request.Query);

            Console.WriteLine($"Delivery receipt received for messages {dlr.MessageId} at {dlr.MessageTimestamp}");
            return(NoContent());
        }
Esempio n. 3
0
        public IActionResult InboundSms()
        {
            var sms = WebhookParser.ParseQuery <InboundSms>(Request.Query);

            Console.WriteLine($"SMS Received with message: {sms.Text}");
            return(NoContent());
        }
Esempio n. 4
0
        public IActionResult VerifySms()
        {
            var VONAGE_API_SIGNATURE_SECRET = Environment.GetEnvironmentVariable("VONAGE_API_SIGNATURE_SECRET") ?? "VONAGE_API_SIGNATURE_SECRET";
            var sms = WebhookParser.ParseQuery <InboundSms>(Request.Query);

            if (sms.ValidateSignature(VONAGE_API_SIGNATURE_SECRET, Vonage.Cryptography.SmsSignatureGenerator.Method.md5hash))
            {
                Console.WriteLine("Signature is valid");
            }
            else
            {
                Console.WriteLine("Signature not valid");
            }
            return(NoContent());
        }
Esempio n. 5
0
 internal async Task InvokeAsync(HttpContext httpContext)
 {
     try
     {
         InboundSms sms;
         if (httpContext.Request.Method == "GET")
         {
             sms = WebhookParser.ParseQuery <InboundSms>(httpContext.Request.Query);
         }
         else
         {
             sms = await WebhookParser.ParseWebhookAsync <InboundSms>(httpContext.Request.Body, httpContext.Request.ContentType);
         }
         if (!string.IsNullOrEmpty(_signatureSecret))
         {
             if (sms.ValidateSignature(_signatureSecret, _signatureMethod))
             {
                 httpContext.Response.StatusCode = 204;
                 _delegate(sms);
             }
             else
             {
                 httpContext.Response.StatusCode = 401;
             }
         }
         else
         {
             httpContext.Response.StatusCode = 204;
             _delegate(sms);
         }
     }
     catch (Exception)
     {
         httpContext.Response.StatusCode = 500;
     }
     if (_invokeNextMiddleware)
     {
         await _next(httpContext);
     }
 }
Esempio n. 6
0
        public IActionResult Answer()
        {
            var host = Request.Host.ToString();
            //Uncomment the next line if using ngrok with --host-header option
            //host = Request.Headers["X-Original-Host"];

            var request        = WebhookParser.ParseQuery <Answer>(Request.Query);
            var eventUrl       = $"{Request.Scheme}://{host}/webhooks/asr";
            var speechSettings = new SpeechSettings {
                Language = "en-US", EndOnSilence = 1, Uuid = new[] { request.Uuid }
            };
            var inputAction = new MultiInputAction {
                Speech = speechSettings, EventUrl = new[] { eventUrl }
            };

            var talkAction = new TalkAction {
                Text = "Please speak now"
            };

            var ncco = new Ncco(talkAction, inputAction);

            return(Ok(ncco.ToString()));
        }
Esempio n. 7
0
        public Task GetAsync()
        {
            var dlr = WebhookParser.ParseQuery <DeliveryReceipt>(HttpContext.Request.Query);

            return(_donorService.HandleDlr(dlr));
        }