Skip to content

Instantly share code, notes, and snippets.

@MaryamZi
Last active April 9, 2018 09:57
Show Gist options
  • Save MaryamZi/138cf119d3bc54698afbf5db2b14155f to your computer and use it in GitHub Desktop.
Save MaryamZi/138cf119d3bc54698afbf5db2b14155f to your computer and use it in GitHub Desktop.
Sample demonstrating usage of the GitHubWebhook service, introduced extending Ballerina's WebSub subscriber service.
import ballerina/io;
import ballerina/http;
import ballerina/webhook;
import ballerina/websub;
endpoint webhook:GitHubListener githubListenerEP {
host:"localhost",
port:8181
};
@websub:SubscriberServiceConfig {
basePath:"/githubWebhook",
secret: "Kslk30SNF2AChs2"
}
service<webhook:GitHubService> githubWebhook bind githubListenerEP {
onIssueCommentCreated (websub:NotificationRequest notification) {
string notificationPayload = notification.payload.toString() but { () => "" };
io:println("[onIssueCommentCreated] WebSub Notification Received: " + notificationPayload);
}
onIssueCommentEdited (websub:NotificationRequest notification) {
string notificationPayload = notification.payload.toString() but { () => "" };
io:println("[onIssueCommentEdited] WebSub Notification Received: " + notificationPayload);
}
onIssueCommentDeleted (websub:NotificationRequest notification) {
string notificationPayload = notification.payload.toString() but { () => "" };
io:println("[onIssueCommentDeleted] WebSub Notification Received: " + notificationPayload);
}
onIssuesEdited (websub:NotificationRequest notification) {
string notificationPayload = notification.payload.toString() but { () => "" };
io:println("[onIssuesEdited] WebSub Notification Received: " + notificationPayload);
}
onWatch (websub:NotificationRequest notification) {
string notificationPayload = notification.payload.toString() but { () => "" };
io:println("[onWatch] WebSub Notification Received: " + notificationPayload);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment