twilio-aspnet icon indicating copy to clipboard operation
twilio-aspnet copied to clipboard

Extend SmsRequest with collection of media links for MMS webhook

Open dmitry-pavlov opened this issue 2 years ago • 0 comments
trafficstars

Would be great to extend SmsRequest class wrapping the Twilio POST webhook request for incoming MMS with the property bound to media files collection. Now to retrieve the media files from Twilio webhook call on ASP.NET Core API (while I am getting incoming MMS from external phone number) I have to read from Request.Form to retrieve media related parameters.

    [HttpPost("message")]
    [AllowAnonymous]
    public async Task<TwiMLResult> MessageWebhook(SmsRequest request, CancellationToken token) {
        ...
        for (int i = 0; i < request.NumMedia; i++)
        {
            string? mediaUrl = Request.Form[$"MediaUrl{i}"];
            string? contentType = Request.Form[$"MediaContentType{i}"];
            ...
        }
    }

Would be great to just mark SmsRequest request as [FromForm] SmsRequest request and access media related items like this:

List<MediaFile> mediaFiles = request.MediaFiles;

So ASP.NET Core controller for handling SMS/MMS webhooks woul dlook like this:

using Twilio.AspNet.Common; using Twilio.AspNet.Core; // or .Mvc for .NET Framework using Twilio.TwiML;

public class WebhookController : TwilioController
{
    [HttpPost("message")]
    [AllowAnonymous]
    public async Task<TwiMLResult> MessageWebhook([FromForm] SmsRequest request, CancellationToken token) {
        ...
        foreach (var media in request.MediaFiles)
        {
            string mediaUrl = media.Url;
            string contentType = media.ContentType;
         }
        ... 
    }
}

dmitry-pavlov avatar Apr 06 '23 16:04 dmitry-pavlov