Skip to content

Instantly share code, notes, and snippets.

@MaryamZi
Created March 24, 2018 04:48
Show Gist options
  • Save MaryamZi/4de24042c00d44aaae69ae239c9c79db to your computer and use it in GitHub Desktop.
Save MaryamZi/4de24042c00d44aaae69ae239c9c79db to your computer and use it in GitHub Desktop.
Ballerina GitHub Webhook - Sample Ballerina WebSub subscriber service.
import ballerina/log;
import ballerina/mime;
import ballerina/net.http;
import ballerina/net.websub;
endpoint websub:SubscriberServiceEndpoint websubEP {
host:"localhost",
port:8181
};
@websub:SubscriberServiceConfig {
basePath:"/githubwebhook",
secret: "XKslk30SNF2AChs2"
}
service<websub:SubscriberService> githubwebhookListener bind websubEP {
onNotification (endpoint client, http:Request request) {
http:Response response = { statusCode:202 };
_ = client -> respond(response);
match (request.getJsonPayload()) {
json jsonPayload => { log:printInfo("WebSub Notification Received: " + jsonPayload.toString()); }
mime:EntityError => { log:printError("Error occurred extracting WebSub Notification"); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment