From 997e9411b908d74a6445a268a91a41462afcfac5 Mon Sep 17 00:00:00 2001 From: beo3000 Date: Wed, 6 May 2026 20:59:23 +0200 Subject: [PATCH] feat(scripts): add getEventById and join-url extractor --- scripts/lib/o365-calendar.js | 34 +++++++++++++++++++++++++++++- scripts/test/o365-calendar.test.js | 16 ++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/scripts/lib/o365-calendar.js b/scripts/lib/o365-calendar.js index dd06871..38f341b 100644 --- a/scripts/lib/o365-calendar.js +++ b/scripts/lib/o365-calendar.js @@ -95,4 +95,36 @@ async function getCalendarEvents(daysAhead = 7) { return (response.value || []).map(parseEventToMeeting); } -module.exports = { isRecurring, parseEventToMeeting, formatEventChoice, getCalendarEvents }; +function extractJoinUrlFromBody(body) { + if (!body) return null; + const m = body.match(/https:\/\/teams\.microsoft\.com\/l\/meetup-join\/[^\s"'<>]+/); + return m ? m[0] : null; +} + +async function getEventById(eventId) { + const env = loadEnv(); + const cca = new ConfidentialClientApplication({ + auth: { + clientId: env.AZURE_CLIENT_ID, + clientSecret: env.AZURE_CLIENT_SECRET, + authority: `https://login.microsoftonline.com/${env.AZURE_TENANT_ID}` + } + }); + const tokenResponse = await cca.acquireTokenByClientCredential({ + scopes: ['https://graph.microsoft.com/.default'] + }); + const client = Client.init({ + authProvider: (done) => done(null, tokenResponse.accessToken) + }); + + const event = await client + .api(`/users/${env.AZURE_USER_EMAIL}/events/${eventId}`) + .select('id,subject,start,end,body,attendees,seriesMasterId,onlineMeeting') + .get(); + return event; +} + +module.exports = { + isRecurring, parseEventToMeeting, formatEventChoice, + getCalendarEvents, getEventById, extractJoinUrlFromBody +}; diff --git a/scripts/test/o365-calendar.test.js b/scripts/test/o365-calendar.test.js index ae1cbd1..c4d5731 100644 --- a/scripts/test/o365-calendar.test.js +++ b/scripts/test/o365-calendar.test.js @@ -80,3 +80,19 @@ describe('isRecurring', () => { assert.equal(isRecurring({ seriesMasterId: null }), false); }); }); + +const { extractJoinUrlFromBody } = require('../lib/o365-calendar.js'); + +describe('extractJoinUrlFromBody', () => { + it('extracts teams meeting join URL from body html', () => { + const html = 'Join'; + assert.equal( + extractJoinUrlFromBody(html), + 'https://teams.microsoft.com/l/meetup-join/19%3aabc/0?context=foo' + ); + }); + + it('returns null when no teams url present', () => { + assert.equal(extractJoinUrlFromBody('

nothing

'), null); + }); +});