Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Created March 16, 2022 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swimburger/850988e67e8d0ce28fa2fc68223adaf3 to your computer and use it in GitHub Desktop.
Save Swimburger/850988e67e8d0ce28fa2fc68223adaf3 to your computer and use it in GitHub Desktop.
ASP.NET Minimal API sample for Twilio webhooks
using Microsoft.AspNetCore.Mvc;
using Twilio.AspNet.Core.MinimalApi;
using Twilio.TwiML;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.MapGet("/sms", ([FromQuery] string from, [FromQuery] string body) =>
{
var messageResponse = new MessagingResponse();
messageResponse.Message($"{from} sent {body}");
return Results.Extensions.TwiML(messageResponse);
});
app.MapPost("/sms", (HttpRequest request) =>
{
var from = request.Form["From"];
var body = request.Form["Body"];
var messageResponse = new MessagingResponse();
messageResponse.Message($"{from} sent {body}");
return Results.Extensions.TwiML(messageResponse);
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment