Created
March 16, 2022 21:35
-
-
Save Swimburger/850988e67e8d0ce28fa2fc68223adaf3 to your computer and use it in GitHub Desktop.
ASP.NET Minimal API sample for Twilio webhooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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