@@ -188,4 +188,118 @@ final String widgetUrl = Widget.owner(Widget.Type.DISCORD_BOT, "5746527517457776
188188
189189``` java
190190final String widgetUrl = Widget . social(Widget . Type . DISCORD_BOT , " 574652751745777665" );
191+ ```
192+
193+ ### Webhooks
194+
195+ #### Being notified whenever someone voted for your bot
196+
197+ ##### Spring Boot
198+
199+ In your ` TopggWebhookFilterConfig.java ` :
200+
201+ ``` java
202+ import org.discordbots.api.client.entity.Vote ;
203+ import org.discordbots.api.client.webhooks.SpringBoot ;
204+
205+ import org.springframework.boot.web.servlet.FilterRegistrationBean ;
206+ import org.springframework.context.annotation.Bean ;
207+ import org.springframework.context.annotation.Configuration ;
208+
209+ @Configuration
210+ public class TopggWebhookFilterConfig {
211+ @Bean
212+ public FilterRegistrationBean<SpringBoot<Vote > > registerVoteWebhook () {
213+ final FilterRegistrationBean<SpringBoot<Vote > > registrationBean = new FilterRegistrationBean<> ();
214+
215+ registrationBean. setFilter(new SpringBoot<> (Vote . class, System . getenv(" MY_TOPGG_WEBHOOK_SECRET" )) {
216+ @Override
217+ public void callback (final Vote vote ) {
218+ System . out. println(" A user with the ID of " + vote. getVoterId() + " has voted us on Top.gg!" );
219+ }
220+ });
221+
222+ registrationBean. addUrlPatterns(" /votes" );
223+ registrationBean. setOrder(1 );
224+
225+ return registrationBean;
226+ }
227+ }
228+ ```
229+
230+ ##### Dropwizard
231+
232+ In your ` MyVoteListener.java ` :
233+
234+ ``` java
235+ import org.discordbots.api.client.entity.Vote ;
236+ import org.discordbots.api.client.webhooks.Dropwizard ;
237+
238+ import jakarta.ws.rs.Path ;
239+
240+ @Path (" /votes" )
241+ public class MyVoteListener extends Dropwizard<Vote > {
242+ public MyVoteListener () {
243+ super (Vote . class, System . getenv(" MY_TOPGG_WEBHOOK_SECRET" ));
244+ }
245+
246+ @Override
247+ public void callback (final Vote vote ) {
248+ System . out. println(" A user with the ID of " + vote. getVoterId() + " has voted us on Top.gg!" );
249+ }
250+ }
251+ ```
252+
253+ In your ` MyServer.java ` :
254+
255+ ``` java
256+ import io.dropwizard.core.Application ;
257+ import io.dropwizard.core.Configuration ;
258+ import io.dropwizard.core.setup.Environment ;
259+ import io.dropwizard.jersey.setup.JerseyEnvironment ;
260+
261+ public class MyServer extends Application<Configuration > {
262+ public static void main (String [] args ) throws Exception {
263+ new MyServer (). run(args);
264+ }
265+
266+ @Override
267+ public void run (Configuration config , Environment env ) {
268+ final JerseyEnvironment jersey = env. jersey();
269+
270+ jersey. register(new MyVoteListener ());
271+ }
272+ }
273+ ```
274+
275+ ##### Eclipse Jetty
276+
277+ In your ` MyServer.java ` :
278+
279+ ``` java
280+ import org.discordbots.api.client.entity.Vote ;
281+ import org.discordbots.api.client.webhooks.EclipseJetty ;
282+
283+ import org.eclipse.jetty.server.Server ;
284+ import org.eclipse.jetty.servlet.ServletContextHandler ;
285+ import org.eclipse.jetty.servlet.ServletHolder ;
286+
287+ public class MyServer {
288+ public static void main (String [] args ) throws Exception {
289+ final Server server = new Server (8080 );
290+ final ServletContextHandler handler = new ServletContextHandler ();
291+
292+ handler. setContextPath(" /" );
293+ handler. addServlet(new ServletHolder (new EclipseJetty<> (Vote . class, System . getenv(" MY_TOPGG_WEBHOOK_SECRET" )) {
294+ @Override
295+ public void callback (final Vote vote ) {
296+ System . out. println(" A user with the ID of " + vote. getVoterId() + " has voted us on Top.gg!" );
297+ }
298+ }), " /votes" );
299+
300+ server. setHandler(handler);
301+ server. start();
302+ server. join();
303+ }
304+ }
191305```
0 commit comments