Skip to content

feat: add webhooks#30

Open
null8626 wants to merge 22 commits intoTop-gg-Community:masterfrom
null8626:split/webhooks
Open

feat: add webhooks#30
null8626 wants to merge 22 commits intoTop-gg-Community:masterfrom
null8626:split/webhooks

Conversation

@null8626
Copy link
Member

The following pull request is a toned down version of #29. This pull request focuses solely on adding a webhooks wrapper for ASP.NET Core/Blazor.

@velddev
Copy link
Contributor

velddev commented Sep 17, 2025

This is not how a ASP.NET Core webhook endpoint should look like. Prefer using the minimal API to create a route at build-time. This will let the internal ASP.NET core router handle all of the actual context.

public static class RoutingExtension {
  public static void UseVoteWebhook(IRouteEndpointBuilder router, string path, ...) {
    router.MapGet(path, (req) => {
      ...
    });  
  }
}

@null8626
Copy link
Member Author

Will work on it.

@null8626
Copy link
Member Author

Done. Made it more similar to Node.js SDK' webhooks wrapper.

Example usage:

using DiscordBotsList.Api.Webhooks;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

var webhooks = new Webhooks("my webhook secret");

app.MapPost("/webhooks", webhooks.Listener((context, vote) =>
{
    Console.WriteLine($"A user with the ID of {vote.VoterId} has voted us on Top.gg!");

    return Task.CompletedTask;
}));

app.Run();

@null8626 null8626 force-pushed the split/webhooks branch 3 times, most recently from b84b479 to 094a304 Compare February 3, 2026 15:47
@williamdevgg
Copy link

looks good to me

Copy link
Contributor

@velddev velddev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this wouldn't work with the actual api. Refer to the docs here for more information.

https://docs.top.gg/docs/API/v1/webhooks/
https://docs.top.gg/docs/API/v1/integrations

Comment on lines 50 to 52
var hmac = new HMACSHA256(authorization);

hmac.TransformFinalBlock(transformBuffer, 0, transformBuffer.Length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done without an allocation an hmac object every request by using

HMACSHA256.HashData(authorization, data);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return;
}

var vote = JsonSerializer.Deserialize<Vote>(body, serializerOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break on additional other values. See; https://docs.top.gg/docs/API/v1/webhooks/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. What do you think of this diff?


namespace DiscordBotsList.Api.Webhooks
{
public class Vote
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong Type, this is the legacy payload

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@null8626
Copy link
Member Author

Most of this wouldn't work with the actual api. Refer to the docs here for more information.

https://docs.top.gg/docs/API/v1/webhooks/ https://docs.top.gg/docs/API/v1/integrations

So sorry! I was too fixated on top-gg/webhooks-v2-nodejs-example that I didn't notice the new webhook events. My bad. I've addressed them now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants