Skip to content

Instantly share code, notes, and snippets.

@MaryamZi
Created March 28, 2018 00:43
Show Gist options
  • Save MaryamZi/2c6f8062e2f3f790de7f327fccde98ad to your computer and use it in GitHub Desktop.
Save MaryamZi/2c6f8062e2f3f790de7f327fccde98ad to your computer and use it in GitHub Desktop.
//Method that accepts intent verification requests
onVerifyIntent (endpoint client, http:Request request) {
//Build the response for the subscription intent verification request that was received
var subscriptionVerificationResponse = websub:buildSubscriptionVerificationResponse(request);
http:Response response = {};
match (subscriptionVerificationResponse) {
//Intent verification request was responded to successfully
http:Response httpResponse => {
log:printInfo("Intent verified for subscription request");
response = httpResponse;
}
//Error occurred responding to the intent verification request
null => {
log:printInfo("Intent verification for subscription request denied");
response = { statusCode:404 };
}
}
_ = client -> respond(response);
}
//Method that accepts content delivery requests
onNotification (endpoint client, http:Request request) {
http:Response response = { statusCode:202 };
_ = client -> respond(response);
var reqPayload = request.getJsonPayload();
match (reqPayload) {
//JSON payload retrieval from the request was successful
json jsonPayload => { log:printInfo("WebSub Notification Received: " + jsonPayload.toString()); }
//An error occurred attempting retrieval of the JSON payload from the request
mime:EntityError => { log:printInfo("Error occurred processing WebSub Notification"); }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment