From 30afc6d6d063500d53b19d83b8eade611b9e3331 Mon Sep 17 00:00:00 2001 From: Giorgi Dalakishvili Date: Wed, 10 Aug 2022 23:00:44 +0400 Subject: [PATCH] Extension methods to convert VoiceResponse and MessagingResponse to TwiMLResult --- .../MinimalApiTwiMLResult.cs | 17 ++++++++++++++++ src/Twilio.AspNet.Core/TwiMLExtensions.cs | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/Twilio.AspNet.Core/TwiMLExtensions.cs diff --git a/src/Twilio.AspNet.Core/MinimalApiTwiMLResult.cs b/src/Twilio.AspNet.Core/MinimalApiTwiMLResult.cs index cd77532..e2ca0b9 100644 --- a/src/Twilio.AspNet.Core/MinimalApiTwiMLResult.cs +++ b/src/Twilio.AspNet.Core/MinimalApiTwiMLResult.cs @@ -1,6 +1,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Twilio.TwiML; // ReSharper disable once CheckNamespace namespace Twilio.AspNet.Core.MinimalApi; @@ -53,4 +54,20 @@ public Task ExecuteAsync(HttpContext httpContext) httpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(twiML); return httpContext.Response.WriteAsync(twiML); } +} + +// ReSharper disable once InconsistentNaming +public static class TwiMLExtensions +{ + // ReSharper disable once InconsistentNaming + public static TwiMLResult ToTwiMLResult(this VoiceResponse voiceResponse) + { + return new TwiMLResult(voiceResponse); + } + + // ReSharper disable once InconsistentNaming + public static TwiMLResult ToTwiMLResult(this MessagingResponse messagingResponse) + { + return new TwiMLResult(messagingResponse); + } } \ No newline at end of file diff --git a/src/Twilio.AspNet.Core/TwiMLExtensions.cs b/src/Twilio.AspNet.Core/TwiMLExtensions.cs new file mode 100644 index 0000000..6189f2f --- /dev/null +++ b/src/Twilio.AspNet.Core/TwiMLExtensions.cs @@ -0,0 +1,20 @@ +using Twilio.TwiML; + +namespace Twilio.AspNet.Core +{ + // ReSharper disable once InconsistentNaming + public static class TwiMLExtensions + { + // ReSharper disable once InconsistentNaming + public static TwiMLResult ToTwiMLResult(this VoiceResponse voiceResponse) + { + return new TwiMLResult(voiceResponse); + } + + // ReSharper disable once InconsistentNaming + public static TwiMLResult ToTwiMLResult(this MessagingResponse messagingResponse) + { + return new TwiMLResult(messagingResponse); + } + } +} \ No newline at end of file