A Transmitly utility package for handling registration and controllers for channel provider delivery reports.
To use install the NuGet package:
dotnet add package Transmitly.Microsoft.AspnetCore.MvcThen add the model binders using AddTransmitlyDeliveryReportModelBinders():
using Transmitly;
...
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddControllers(options =>
{
//Adds the necessary model binders to handle channel provider specific webhooks (Twilio, Infobip, etc)
//and convert them to delivery reports
options.AddTransmitlyDeliveryReportModelBinders();
})
.AddTransmitly(tly => {...});
}Inheriting the ChannelProviderDeliveryReportController will setup an POST route named, HandleDeliveryReport (example: https://yourapp.com/Communications/HandleDeliveryReport) that will automatically trigger
your registered delivery report handlers for the provided ICommunicationsClient.
The HandleDeliveryReport method can be overridden. Allowing you to customize behaviors and set route specifics.
MyDeliveryReportsController.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Transmitly;
namespace MyApp.Controllers
{
[AllowAnonymous]
[Route("[controller]/[action]")]
public class CommunicationsController : ChannelProviderDeliveryReportController
{
public CommunicationsController(ICommunicationsClient communicationsClient) : base(communicationsClient)
{
}
}
}The [Route] attribute is needed when controllers are mapped with app.MapControllers(). With conventional routing (app.MapDefaultControllerRoute()), it can be omitted.
Or if you prefer to implement it yourself (ChannelProviderDeliveryReportRequest is in the Transmitly.Delivery namespace)
[HttpPost("channel/provider/update", Name = "DeliveryReport")]
public IActionResult ChannelProviderDeliveryReport(ChannelProviderDeliveryReportRequest providerReport)
{
_communicationsClient.DispatchAsync(providerReport.DeliveryReports);
return Ok();
}- See the Transmitly project for more details on how use and configure the library.
Copyright © Code Impressions, LLC. This open-source project is sponsored and maintained by Code Impressions and is licensed under the Apache License, Version 2.0.