1 | |
2 |
|
3 | |
4 | * Find Meeting Times |
5 | * Suggest meeting times that work for the connected account and the given attendees, within a window of local times in `time_zone`. Work or school accounts only. `extra` takes any other findMeetingTimes property (e.g. `minimumAttendeePercentage`, `isOrganizerOptional`). Requires Calendars.Read.Shared, which is not a connection default: tick it when connecting. |
6 | */ |
7 | export async function main( |
8 | auth: RT.MsOutlook, |
9 | attendees: string[], |
10 | start: string, |
11 | end: string, |
12 | time_zone: string = "UTC", |
13 | duration_minutes: number = 30, |
14 | max_candidates: number | undefined, |
15 | extra: { [key: string]: any } | undefined |
16 | ) { |
17 | const body: { [key: string]: any } = { |
18 | ...(extra ?? {}), |
19 | attendees: attendees.map((address) => ({ |
20 | type: "required", |
21 | emailAddress: { address }, |
22 | })), |
23 | timeConstraint: { |
24 | timeSlots: [ |
25 | { |
26 | start: { dateTime: start, timeZone: time_zone }, |
27 | end: { dateTime: end, timeZone: time_zone }, |
28 | }, |
29 | ], |
30 | }, |
31 | meetingDuration: `PT${duration_minutes}M`, |
32 | } |
33 | if (max_candidates != null) body.maxCandidates = max_candidates |
34 |
|
35 | const response = await fetch( |
36 | "https://graph.microsoft.com/v1.0/me/findMeetingTimes", |
37 | { |
38 | method: "POST", |
39 | headers: { |
40 | Authorization: `Bearer ${auth.token}`, |
41 | "Content-Type": "application/json", |
42 | Accept: "application/json", |
43 | Prefer: `outlook.timezone="${time_zone}"`, |
44 | }, |
45 | body: JSON.stringify(body), |
46 | } |
47 | ) |
48 |
|
49 | if (!response.ok) { |
50 | throw new Error(`${response.status} ${await response.text()}`) |
51 | } |
52 |
|
53 | return await response.json() |
54 | } |
55 |
|