Created
March 24, 2018 04:48
-
-
Save MaryamZi/4de24042c00d44aaae69ae239c9c79db to your computer and use it in GitHub Desktop.
Ballerina GitHub Webhook - Sample Ballerina WebSub subscriber service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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