-
-
Save ypcode/003dc8505c7d641b1af2e33fee61d3e5 to your computer and use it in GitHub Desktop.
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 { AzureFunction, Context, HttpRequest } from "@azure/functions" | |
import { INotificationsPayload } from "../entities/INotification"; | |
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> { | |
context.log('HTTP trigger function processed a request.'); | |
// Validate the subscription creation | |
if (req.query.validationToken) { | |
context.log('Validating new subscription...'); | |
context.log('Validation token:'); | |
context.log(req.query.validationToken); | |
context.res = { | |
headers: { | |
'Content-Type': 'text/plain' | |
}, | |
body: req.query.validationToken | |
}; | |
} | |
else { | |
context.log('Received new notification from Microsoft Graph...'); | |
context.log('Notifications: '); | |
const payload = req.body as INotificationsPayload; | |
payload.value.forEach((n,i) => { | |
context.log(` Notification #${i} `); | |
context.log(`----------------------------------------------------------`); | |
context.log(`Subscription Id : ${n.subscriptionId}`); | |
context.log(`Expiration : ${n.subscriptionExpirationDateTime}`); | |
context.log(`Change Type : ${n.changeType}`); | |
context.log(`Client State : ${n.clientState}`); | |
context.log(`Resource : ${n.resource}`); | |
context.log(`Resource Data : ${n.resourceData}`); | |
context.log(`----------------------------------------------------------`); | |
}); | |
context.res = { body: "" }; | |
} | |
}; | |
export default httpTrigger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment