Skip to content

Webserver with single endpoint for managing webhooks and receiving payloads from clients. [This is a mirror from GitLab, please interact with the repository there.]

License

Notifications You must be signed in to change notification settings

elypia/webhooker

Webhooker

Matrix Discord Maven Central Docs Build Coverage Donate

About

Webhooker is a small library for hosting webhook callbacks to receive and dispatch callbacks from external services such as Twitch or Slack. This is done by running a webserver using SparkJava and serializing JSON with GSON, and then managing Clients to map the request URL to callback(s).

The Gradle/Maven import string can be found at the `maven-central badge above!

Quick-Start

public class Main {
    
    /**
    * This example assumes a reverse proxy is routing
    * requests from `webhooks.elypia.org` to `localhost:4567`.
    * If no reverse proxy is desired, `http://your.public.ip:4567/:uuid` is fine.
    * 
    * @param args
    */
    public static void main(String[] args) {
        // `publicUrl` must specify route parameter `uuid`.
        Webhooker hooker = new Webhooker("https://webhooks.elypia.org/:uuid", 4567);

        // Add a new client to the client controller.
        Client client = hooker.getController().add(new Client());
        
        // Perform these callbacks whenever this client receives payload in the order provided.
        client.addCallbacks((payload) -> System.out.println(payload.getRequest().body()));

        // Get the callback url for this client, this will be provided to a service to POST to.
        String callbackUrl = hooker.getUrl(client);
                
        // Subscribe to payloads from a third party service.
        TwitchNotifier notifier = new TwitchNotifier();
        notifier.subscribe(callbackUrl, "https://api.twitch.tv/helix/users/follows?first=1&from_id=31415");
    }
}

About

Webserver with single endpoint for managing webhooks and receiving payloads from clients. [This is a mirror from GitLab, please interact with the repository there.]

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages