Skip to content

Instantly share code, notes, and snippets.

@ypcode
Created January 12, 2020 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/003dc8505c7d641b1af2e33fee61d3e5 to your computer and use it in GitHub Desktop.
Save ypcode/003dc8505c7d641b1af2e33fee61d3e5 to your computer and use it in GitHub Desktop.
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