Created
June 22, 2022 17:22
-
-
Save preetjdp/96c5a59d088d844888b7ee13404ff29e to your computer and use it in GitHub Desktop.
The sample webhook for demo
This file contains hidden or 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.Builder; | |
using Microsoft.AspNetCore.Http; | |
using System; | |
public class WebhookData | |
{ | |
public int Id { get; set; } | |
public string _fu { get; set; } | |
public string _fn { get; set; } | |
public string _ca { get; set; } | |
} | |
public static class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | |
WebApplication app = builder.Build(); | |
var helloHandler = () => "Hello World!"; | |
var webhookHandler = async (HttpRequest request) => { | |
// JSON is present in the request body | |
// ReadFromJsonAsync converts un-structured JSON to Structured WebhookData | |
var webhookData = await request.ReadFromJsonAsync<WebhookData>(); | |
Console.WriteLine(webhookData.Id); | |
Console.WriteLine(webhookData._fu); | |
Console.WriteLine(webhookData._fn); | |
Console.WriteLine(webhookData._ca); | |
//query the db to find the user | |
//....... | |
return Results.Ok(new { Staus = "Success" }); | |
}; | |
app.MapGet("/", helloHandler); | |
app.MapPost("/webhook", webhookHandler); | |
app.Run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment