feat(scripts): add getEventById and join-url extractor
This commit is contained in:
parent
95cb27e53a
commit
997e9411b9
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 = '<a href="https://teams.microsoft.com/l/meetup-join/19%3aabc/0?context=foo">Join</a>';
|
||||
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('<p>nothing</p>'), null);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue