Skip to content

Instantly share code, notes, and snippets.

@preetjdp
Created June 22, 2022 17:22
Show Gist options
  • Save preetjdp/96c5a59d088d844888b7ee13404ff29e to your computer and use it in GitHub Desktop.
Save preetjdp/96c5a59d088d844888b7ee13404ff29e to your computer and use it in GitHub Desktop.
The sample webhook for demo
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