-
-
Save ypcode/88fd47e34eef2985a5f0d2b870ce36ef 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 } from "@azure/functions"; | |
import { IBusinessTaskArgs } from "../entities/IBusinessTaskArgs"; | |
import { GraphHttpClient } from "@pnp/graph-commonjs/graphhttpclient"; | |
import { configure } from "../helpers/configure"; | |
const queueTrigger: AzureFunction = async function (context: Context, taskArgs: IBusinessTaskArgs): Promise<void> { | |
// The calendar event is post process by our custom logic | |
context.log(`Received arguments: ${JSON.stringify(taskArgs)}`); | |
configure(context); | |
try { | |
// TODO Here implement custom logic | |
// e.g. Update the updated event's title | |
const resourceAbsoluteUrl = `https://graph.microsoft.com/v1.0/${taskArgs.eventResourceUri}`; | |
const client = new GraphHttpClient(); | |
const eventResponse = await client.get(resourceAbsoluteUrl); | |
const event: { subject: string; } = await eventResponse.json(); | |
// If event is not already processed | |
// Since we are updating the notified updated event, we have to check the custom task is not already done | |
// Otherwise, a notification will be resent and cause an "infinite" loop | |
if (event.subject.indexOf("[UPDATED]") != 0) { | |
const eventUpdate = { | |
subject: `[UPDATED] ${event.subject}` | |
} | |
const patchResponse = await client.patch(resourceAbsoluteUrl, { | |
body: JSON.stringify(eventUpdate) | |
}); | |
if (patchResponse.ok) { | |
console.log("Event has been updated."); | |
} else { | |
console.log("Event could not be updated"); | |
} | |
} | |
} | |
catch (error) { | |
context.log.error("An error occured while processing custom business task", error); | |
} | |
}; | |
export default queueTrigger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment