fix: Update Teams web UI selectors to match 2025 redesign

Teams changed from data-tid to id attributes for key elements
(hangup-button, callingButtons-showMoreBtn, closed-captions-button).
Aligned selectors with Recall.ai confirmed working implementation:
- URL resolution with suppressPrompt/msLaunch params
- waitForSelector instead of page. for reliable element detection
- Captions: MutationObserver with exposeFunction instead of polling
- Better error diagnostics (URL, title, visible text in error messages)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ValueOn AG 2026-02-15 01:05:47 +01:00
parent 61219ce5a2
commit 36bf5269ac
3 changed files with 356 additions and 222 deletions

View file

@ -1,11 +1,18 @@
import { Page } from 'playwright'; import { Page } from 'playwright';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { TranscriptEntry } from '../types'; import { TranscriptEntry } from '../types';
import { config } from '../config';
/** /**
* Handles enabling and scraping captions from Teams meetings. * Handles enabling and scraping captions from Teams meetings.
* Based on Recall.ai's open-source implementation. * Based on Recall.ai's open-source implementation.
*
* Teams web UI selectors (updated Jan 2025):
* - More button: button[id="callingButtons-showMoreBtn"]
* - Captions button: div[id="closed-captions-button"]
* - Captions container: div[data-tid="closed-caption-renderer-wrapper"]
* - Caption author: span[data-tid="author"]
* - Caption text: span[data-tid="closed-caption-text"]
* - Caption message: .fui-ChatMessageCompact
*/ */
export class CaptionsProcedure { export class CaptionsProcedure {
private _page: Page; private _page: Page;
@ -26,7 +33,7 @@ export class CaptionsProcedure {
/** /**
* Enable live captions in the meeting. * Enable live captions in the meeting.
* Opens the "More" menu and clicks "Turn on live captions". * Opens the "More" menu and clicks the captions button.
*/ */
async enableCaptionsFlow(): Promise<void> { async enableCaptionsFlow(): Promise<void> {
this._logger.info('Enabling live captions...'); this._logger.info('Enabling live captions...');
@ -34,33 +41,51 @@ export class CaptionsProcedure {
// First, open the "More actions" menu // First, open the "More actions" menu
await this._openMoreMenu(); await this._openMoreMenu();
// Then click on "Turn on live captions" // Then click on the captions button
await this._clickEnableCaptions(); await this._clickEnableCaptions();
// Wait for the captions container to appear
await this._waitForCaptionsContainer();
this._logger.info('Live captions enabled'); this._logger.info('Live captions enabled');
} }
/** /**
* Open the "More actions" (...) menu in the call controls. * Open the "More actions" (...) menu in the call controls.
* Primary selector: button[id="callingButtons-showMoreBtn"] (confirmed by Recall.ai).
*/ */
private async _openMoreMenu(): Promise<void> { private async _openMoreMenu(): Promise<void> {
const moreMenuSelectors = [ // Primary selector - confirmed by Recall.ai (Jan 2025)
const primarySelector = 'button[id="callingButtons-showMoreBtn"]';
try {
await this._page.waitForSelector(primarySelector, { timeout: 120000 });
this._logger.info('Found "More" button');
await this._page.click(primarySelector);
this._logger.info('Clicked "More" button');
return;
} catch {
this._logger.info('Primary more button selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'[data-tid="callingButtons-showMoreBtn"]', '[data-tid="callingButtons-showMoreBtn"]',
'button[aria-label*="More actions"]', 'button[aria-label*="More actions"]',
'button[aria-label*="More"]', 'button[aria-label*="More"]',
'[data-tid="more-button"]', '[data-tid="more-button"]',
]; ];
for (const selector of moreMenuSelectors) { for (const selector of fallbackSelectors) {
try { try {
const button = await this._page.$(selector); const button = await this._page.$(selector);
if (button) { if (button) {
await button.click(); await button.click();
await this._page.waitForTimeout(1000); await this._page.waitForTimeout(1000);
this._logger.info('Opened more menu'); this._logger.info(`Opened more menu (fallback: ${selector})`);
return; return;
} }
} catch (error) { } catch {
// Continue // Continue
} }
} }
@ -69,30 +94,43 @@ export class CaptionsProcedure {
} }
/** /**
* Click the "Turn on live captions" option. * Click the captions button in the menu.
* Primary selector: div[id="closed-captions-button"] (confirmed by Recall.ai).
*/ */
private async _clickEnableCaptions(): Promise<void> { private async _clickEnableCaptions(): Promise<void> {
const captionsSelectors = [ // Primary selector - confirmed by Recall.ai (Jan 2025)
const primarySelector = 'div[id="closed-captions-button"]';
try {
await this._page.waitForSelector(primarySelector, { timeout: 120000 });
this._logger.info('Found "Captions" button');
await this._page.click(primarySelector);
this._logger.info('Clicked "Captions" button');
return;
} catch {
this._logger.info('Primary captions button selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'button:has-text("Turn on live captions")', 'button:has-text("Turn on live captions")',
'button:has-text("Live captions")', 'button:has-text("Live captions")',
'[data-tid="captions-toggle"]', '[data-tid="captions-toggle"]',
'button[aria-label*="captions"]', 'button[aria-label*="captions" i]',
'button[aria-label*="Captions"]',
// Menu item selectors
'[role="menuitem"]:has-text("captions")', '[role="menuitem"]:has-text("captions")',
'[role="menuitemcheckbox"]:has-text("captions")', '[role="menuitemcheckbox"]:has-text("captions")',
]; ];
for (const selector of captionsSelectors) { for (const selector of fallbackSelectors) {
try { try {
const button = await this._page.$(selector); const button = await this._page.$(selector);
if (button) { if (button) {
await button.click(); await button.click();
await this._page.waitForTimeout(1000); await this._page.waitForTimeout(1000);
this._logger.info('Clicked enable captions'); this._logger.info(`Clicked enable captions (fallback: ${selector})`);
return; return;
} }
} catch (error) { } catch {
// Continue // Continue
} }
} }
@ -103,8 +141,30 @@ export class CaptionsProcedure {
} }
/** /**
* Start watching the captions DOM for updates. * Wait for the captions container to become visible after enabling.
* Emits transcript events when new captions appear. * Primary selector: div[data-tid="closed-caption-renderer-wrapper"] (confirmed by Recall.ai).
*/
private async _waitForCaptionsContainer(): Promise<void> {
const containerSelector = 'div[data-tid="closed-caption-renderer-wrapper"]';
try {
await this._page.waitForSelector(containerSelector, { timeout: 120000 });
this._logger.info('Found captions container');
} catch {
this._logger.warn('Could not find captions container - captions may not have enabled');
}
}
/**
* Start watching the captions DOM for updates using Recall.ai's approach.
*
* Uses page.exposeFunction() + MutationObserver for real-time caption detection.
* Captions in Teams are rendered inside .fui-ChatMessageCompact elements with:
* - span[data-tid="author"] for the speaker name
* - span[data-tid="closed-caption-text"] for the caption text
*
* Teams updates captions in real-time as the user speaks, adding punctuation
* only when the caption is finalized. We use this to detect final captions.
*/ */
async subscribeToCaptions(): Promise<void> { async subscribeToCaptions(): Promise<void> {
if (this._isSubscribed) { if (this._isSubscribed) {
@ -115,111 +175,116 @@ export class CaptionsProcedure {
this._isSubscribed = true; this._isSubscribed = true;
this._logger.info('Subscribing to captions...'); this._logger.info('Subscribing to captions...');
// Set up a MutationObserver in the browser to watch for caption changes // Expose a callback function from Node.js to the browser context
await this._page.exposeFunction('__onCaptionEvent', (caption: {
speaker: string;
text: string;
timestamp: string;
}) => {
this._handleCaptionEvent(caption);
});
// Verify captions container is present
const containerSelector = 'div[data-tid="closed-caption-renderer-wrapper"]';
try {
await this._page.waitForSelector(containerSelector, { timeout: 120000 });
} catch {
this._logger.warn('Captions container not found, subscribing anyway');
}
this._logger.info('Setting up MutationObserver for captions...');
// Set up MutationObserver in the browser (Recall.ai approach)
await this._page.evaluate(() => { await this._page.evaluate(() => {
// Store captions data on window for retrieval const targetNode = document.querySelector('div[data-tid="closed-caption-renderer-wrapper"]');
(window as any).__captionsBuffer = []; if (!targetNode) {
(window as any).__lastCaptionId = 0; return;
}
// Function to extract caption text const observer = new MutationObserver((mutationsList) => {
const extractCaptions = () => { for (const mutation of mutationsList) {
// Common caption container selectors in Teams if (mutation.type === 'childList') {
const captionSelectors = [ mutation.addedNodes.forEach((node) => {
'[data-tid="closed-captions-renderer"]', if (node.nodeType === Node.ELEMENT_NODE) {
'[data-tid="captions-container"]', const element = node as HTMLElement;
'.captions-container',
'[class*="caption"]',
];
for (const selector of captionSelectors) { // Check if this is a caption element (.fui-ChatMessageCompact)
const container = document.querySelector(selector); const captionMessage = element.querySelector('.fui-ChatMessageCompact');
if (container) { if (!captionMessage) {
// Find individual caption entries return;
const entries = container.querySelectorAll('[data-tid="caption-entry"], [class*="caption-line"], [class*="captionLine"]'); }
entries.forEach((entry, index) => { const authorElement = captionMessage.querySelector('span[data-tid="author"]');
const speakerEl = entry.querySelector('[data-tid="caption-speaker"], [class*="speaker"]'); const contentElement = captionMessage.querySelector('span[data-tid="closed-caption-text"]');
const textEl = entry.querySelector('[data-tid="caption-text"], [class*="text"]');
const speaker = speakerEl?.textContent?.trim() || 'Unknown'; if (authorElement && contentElement) {
const text = textEl?.textContent?.trim() || entry.textContent?.trim() || ''; // Watch for real-time updates in the caption text
const textObserver = new MutationObserver(() => {
const speaker = authorElement.textContent?.trim() ?? 'Unknown';
const text = (contentElement as any).innerText?.trim() ?? '';
if (text && text.length > 0) { (window as any).__onCaptionEvent({
const captionId = `${speaker}-${text}-${index}`;
if (captionId !== (window as any).__lastCaptionId) {
(window as any).__lastCaptionId = captionId;
(window as any).__captionsBuffer.push({
speaker, speaker,
text, text,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
isFinal: true, // Teams captions are typically final
}); });
}
}
});
break;
}
}
};
// Set up observer
const observer = new MutationObserver(() => {
extractCaptions();
}); });
// Observe the entire body for changes (captions can appear anywhere) textObserver.observe(contentElement, {
observer.observe(document.body, {
childList: true, childList: true,
subtree: true, subtree: true,
characterData: true, characterData: true,
}); });
}
}
});
}
}
});
// Initial extraction observer.observe(targetNode, { childList: true, subtree: true });
extractCaptions();
// Store observer reference for cleanup // Store observer reference for cleanup
(window as any).__captionsObserver = observer; (window as any).__captionsObserver = observer;
}); });
// Start polling for new captions this._logger.info('MutationObserver set up for captions');
this._pollCaptions();
} }
/** /**
* Poll the browser for new captions and emit them. * Handle a caption event from the browser MutationObserver.
* Teams updates captions in real-time. We detect finalized captions by
* checking for terminal punctuation (. , ! ?).
*/ */
private async _pollCaptions(): Promise<void> { private _handleCaptionEvent(caption: { speaker: string; text: string; timestamp: string }): void {
while (this._isSubscribed) { if (!this._isSubscribed || !caption.text) {
try { return;
const captions = await this._page.evaluate(() => { }
const buffer = (window as any).__captionsBuffer || [];
(window as any).__captionsBuffer = []; // Teams adds punctuation only to finalized captions
return buffer; const terminalPunctuationRegex = /[.,!?]/;
}); if (!terminalPunctuationRegex.test(caption.text)) {
return; // Not finalized yet
}
// Dedup: strip punctuation and compare to last caption
const punctuationRegex = /[.,'"!?~\-]/g;
const newTextStripped = caption.text.replace(punctuationRegex, '');
const lastTextStripped = this._lastCaptionText.replace(punctuationRegex, '');
if (newTextStripped === lastTextStripped) {
return; // Duplicate
}
for (const caption of captions) {
// Deduplicate based on text
if (caption.text !== this._lastCaptionText) {
this._lastCaptionText = caption.text; this._lastCaptionText = caption.text;
this._onTranscript({ this._onTranscript({
speaker: caption.speaker, speaker: caption.speaker,
text: caption.text, text: caption.text,
timestamp: new Date(caption.timestamp), timestamp: new Date(caption.timestamp),
isFinal: caption.isFinal, isFinal: true,
}); });
} }
}
} catch (error) {
// Page might be closed
if (this._isSubscribed) {
this._logger.error('Error polling captions:', error);
}
}
// Poll every 500ms
await new Promise(resolve => setTimeout(resolve, 500));
}
}
/** /**
* Stop watching for captions. * Stop watching for captions.

View file

@ -1,11 +1,14 @@
import { Page } from 'playwright'; import { Page } from 'playwright';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { config } from '../config'; import { config } from '../config';
import { getMeetingLaunchUrl } from './meetingUrlParser'; import { resolveLaunchUrl, getMeetingLaunchUrl } from './meetingUrlParser';
/** /**
* Handles the Teams meeting join flow. * Handles the Teams meeting join flow.
* Based on Recall.ai's open-source implementation. * Based on Recall.ai's open-source implementation.
*
* Teams web UI uses `id` attributes (not `data-tid`) for many interactive elements
* since the 2025 redesign. Selectors updated accordingly.
*/ */
export class JoinProcedure { export class JoinProcedure {
private _page: Page; private _page: Page;
@ -20,10 +23,22 @@ export class JoinProcedure {
/** /**
* Navigate to the meeting URL and handle the launcher dialog. * Navigate to the meeting URL and handle the launcher dialog.
* Teams shows a "How do you want to join?" dialog first. *
* Teams meeting URLs redirect through several hops. We resolve the redirect
* and add params (suppressPrompt, msLaunch=false, etc.) to skip the
* "Open in Teams app?" native dialog. Then we click "Continue on this browser".
*/ */
async startMeetingLauncherFlow(meetingUrl: string): Promise<void> { async startMeetingLauncherFlow(meetingUrl: string): Promise<void> {
const launchUrl = getMeetingLaunchUrl(meetingUrl); // Resolve the meeting URL redirect and add suppressPrompt params
let launchUrl: string;
try {
launchUrl = await resolveLaunchUrl(meetingUrl);
this._logger.info(`Resolved launch URL: ${launchUrl}`);
} catch (error) {
this._logger.warn(`Could not resolve launch URL, using fallback: ${error}`);
launchUrl = getMeetingLaunchUrl(meetingUrl);
}
this._logger.info(`Navigating to meeting: ${launchUrl}`); this._logger.info(`Navigating to meeting: ${launchUrl}`);
await this._page.goto(launchUrl, { await this._page.goto(launchUrl, {
@ -31,45 +46,58 @@ export class JoinProcedure {
timeout: config.timeouts.pageLoad, timeout: config.timeouts.pageLoad,
}); });
// Wait for the page to stabilize // Handle "Continue on this browser" button
await this._page.waitForTimeout(2000);
// Handle "Continue on this browser" or similar prompts
await this._handleLauncherDialog(); await this._handleLauncherDialog();
} }
/** /**
* Handle the launcher dialog that asks how to join. * Handle the launcher dialog that asks how to join.
* We want to select "Continue on this browser" / "Join on the web instead" * Primary selector: button[data-tid="joinOnWeb"] (confirmed working in Recall.ai).
* Falls back to text-based selectors if the data-tid changes.
*/ */
private async _handleLauncherDialog(): Promise<void> { private async _handleLauncherDialog(): Promise<void> {
this._logger.info('Looking for launcher dialog...'); this._logger.info('Looking for launcher dialog...');
// Common selectors for "Continue on browser" button // Primary selector - confirmed working by Recall.ai (Jan 2025)
const browserJoinSelectors = [ const primarySelector = 'button[data-tid="joinOnWeb"]';
try {
await this._page.waitForSelector(primarySelector, { timeout: 30000 });
this._logger.info(`Found launcher button: ${primarySelector}`);
await this._page.click(primarySelector);
this._logger.info('Clicked "Continue on this browser" button');
return;
} catch {
this._logger.info('Primary launcher selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'button:has-text("Continue on this browser")', 'button:has-text("Continue on this browser")',
'button:has-text("Join on the web instead")', 'button:has-text("Join on the web instead")',
'a:has-text("Continue on this browser")', 'a:has-text("Continue on this browser")',
'a:has-text("Join on the web")', 'a:has-text("Join on the web")',
'[data-tid="joinOnWeb"]', 'button:has-text("Use web app instead")',
'[data-tid="prejoin-join-button"]',
]; ];
for (const selector of browserJoinSelectors) { for (const selector of fallbackSelectors) {
try { try {
const element = await this._page.$(selector); const element = await this._page.$(selector);
if (element) { if (element) {
this._logger.info(`Found launcher button: ${selector}`); this._logger.info(`Found launcher button (fallback): ${selector}`);
await element.click(); await element.click();
await this._page.waitForTimeout(2000); await this._page.waitForTimeout(2000);
return; return;
} }
} catch (error) { } catch {
// Continue to next selector // Continue to next selector
} }
} }
this._logger.info('No launcher dialog found, may already be on join page'); // Log diagnostic info for debugging
const currentUrl = this._page.url();
const title = await this._page.title();
this._logger.info(`No launcher dialog found (URL: ${currentUrl}, Title: ${title}). May already be on join page.`);
} }
/** /**
@ -78,153 +106,141 @@ export class JoinProcedure {
async joinMeetingLobbyFlow(): Promise<void> { async joinMeetingLobbyFlow(): Promise<void> {
this._logger.info('Starting lobby join flow...'); this._logger.info('Starting lobby join flow...');
// Wait for the pre-join screen // Enter the bot name (this also implicitly waits for the pre-join page to load)
await this._page.waitForTimeout(2000);
// Handle microphone/camera permissions - we want them OFF
await this._disableMediaDevices();
// Enter the bot name
await this._enterBotName(); await this._enterBotName();
// Click "Join now" // Click "Join now"
await this._clickJoinNow(); await this._clickJoinNow();
} }
/**
* Disable microphone and camera toggles.
*/
private async _disableMediaDevices(): Promise<void> {
this._logger.info('Disabling media devices...');
// Microphone toggle selectors
const micSelectors = [
'[data-tid="toggle-mute"]',
'[aria-label*="microphone"]',
'[aria-label*="Microphone"]',
'button[id*="microphone"]',
];
// Camera toggle selectors
const cameraSelectors = [
'[data-tid="toggle-video"]',
'[aria-label*="camera"]',
'[aria-label*="Camera"]',
'button[id*="camera"]',
];
// Try to turn off microphone (click if it's ON)
for (const selector of micSelectors) {
try {
const mic = await this._page.$(selector);
if (mic) {
const ariaPressed = await mic.getAttribute('aria-pressed');
const ariaChecked = await mic.getAttribute('aria-checked');
if (ariaPressed === 'true' || ariaChecked === 'true') {
await mic.click();
this._logger.info('Disabled microphone');
}
break;
}
} catch (error) {
// Continue
}
}
// Try to turn off camera
for (const selector of cameraSelectors) {
try {
const camera = await this._page.$(selector);
if (camera) {
const ariaPressed = await camera.getAttribute('aria-pressed');
const ariaChecked = await camera.getAttribute('aria-checked');
if (ariaPressed === 'true' || ariaChecked === 'true') {
await camera.click();
this._logger.info('Disabled camera');
}
break;
}
} catch (error) {
// Continue
}
}
}
/** /**
* Enter the bot name in the name input field. * Enter the bot name in the name input field.
* Primary selector: input[placeholder="Type your name"] (confirmed by Recall.ai).
*/ */
private async _enterBotName(): Promise<void> { private async _enterBotName(): Promise<void> {
this._logger.info(`Entering bot name: ${this._botName}`); this._logger.info(`Entering bot name: ${this._botName}`);
const nameSelectors = [ // Primary selector - confirmed working by Recall.ai (Jan 2025)
const primarySelector = 'input[placeholder="Type your name"]';
try {
await this._page.waitForSelector(primarySelector, { timeout: 15000 });
await this._page.fill(primarySelector, this._botName);
this._logger.info('Bot name entered');
return;
} catch {
this._logger.info('Primary name input selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'input[data-tid="prejoin-display-name-input"]', 'input[data-tid="prejoin-display-name-input"]',
'input[placeholder*="name"]', 'input[placeholder*="name" i]',
'input[placeholder*="Name"]', 'input[placeholder*="Name"]',
'input[aria-label*="name"]', 'input[aria-label*="name" i]',
'#username', '#username',
]; ];
for (const selector of nameSelectors) { for (const selector of fallbackSelectors) {
try { try {
const input = await this._page.$(selector); const input = await this._page.$(selector);
if (input) { if (input) {
await input.fill(this._botName); await input.fill(this._botName);
this._logger.info('Bot name entered'); this._logger.info(`Bot name entered (fallback: ${selector})`);
return; return;
} }
} catch (error) { } catch {
// Continue // Continue
} }
} }
this._logger.warn('Could not find name input field'); // Log diagnostic info
const currentUrl = this._page.url();
const title = await this._page.title();
this._logger.warn(`Could not find name input field (URL: ${currentUrl}, Title: ${title})`);
} }
/** /**
* Click the "Join now" button. * Click the "Join now" button.
* Primary selector: button:has-text("Join now") (confirmed by Recall.ai).
*/ */
private async _clickJoinNow(): Promise<void> { private async _clickJoinNow(): Promise<void> {
this._logger.info('Clicking Join now...'); this._logger.info('Clicking Join now...');
const joinSelectors = [ // Primary selector - confirmed working by Recall.ai (Jan 2025)
const primarySelector = 'button:has-text("Join now")';
try {
await this._page.waitForSelector(primarySelector, { timeout: 15000 });
await this._page.click(primarySelector);
this._logger.info('Clicked "Join now" button');
return;
} catch {
this._logger.info('Primary join button selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'button[data-tid="prejoin-join-button"]', 'button[data-tid="prejoin-join-button"]',
'button:has-text("Join now")',
'button:has-text("Join meeting")', 'button:has-text("Join meeting")',
'button:has-text("Join")',
'[data-tid="joinButton"]', '[data-tid="joinButton"]',
]; ];
for (const selector of joinSelectors) { for (const selector of fallbackSelectors) {
try { try {
const button = await this._page.$(selector); const button = await this._page.$(selector);
if (button) { if (button) {
await button.click(); await button.click();
this._logger.info('Clicked join button'); this._logger.info(`Clicked join button (fallback: ${selector})`);
return; return;
} }
} catch (error) { } catch {
// Continue // Continue
} }
} }
throw new Error('Could not find Join button'); // Diagnostic info for debugging
const currentUrl = this._page.url();
const title = await this._page.title();
const bodyText = await this._page.evaluate(() =>
document.body?.innerText?.substring(0, 500) || '(empty)'
);
throw new Error(
`Could not find Join button. URL: ${currentUrl}, Title: ${title}, ` +
`Visible text (first 500 chars): ${bodyText}`
);
} }
/** /**
* Check if the bot is currently in the lobby (waiting to be admitted). * Check if the bot is currently in the lobby (waiting to be admitted).
* Primary check: text "Someone will let you in shortly" (confirmed by Recall.ai).
*/ */
async isInMeetingLobby(options: { waitForSeconds?: number } = {}): Promise<boolean> { async isInMeetingLobby(options: { waitForSeconds?: number } = {}): Promise<boolean> {
const timeout = (options.waitForSeconds || 5) * 1000; const timeout = (options.waitForSeconds || 5) * 1000;
const lobbySelectors = [ try {
'[data-tid="lobby-screen"]', // Primary: text-based check (Recall.ai approach, most reliable)
await this._page.getByText('Someone will let you in shortly').waitFor({
timeout,
state: 'visible',
});
return true;
} catch {
// Fallback: try other lobby indicators
}
// Fallback selectors
const fallbackSelectors = [
':has-text("waiting for someone to let you in")', ':has-text("waiting for someone to let you in")',
':has-text("Someone in the meeting should let you in soon")', ':has-text("Someone in the meeting should let you in soon")',
'[data-tid="lobby-screen"]',
'[data-tid="waiting-screen"]', '[data-tid="waiting-screen"]',
]; ];
try { try {
await this._page.waitForSelector(lobbySelectors.join(', '), { await this._page.waitForSelector(fallbackSelectors.join(', '), {
timeout, timeout: 1000, // Short timeout since primary already waited
state: 'visible', state: 'visible',
}); });
return true; return true;
@ -235,15 +251,20 @@ export class JoinProcedure {
/** /**
* Check if the bot is currently in the meeting (admitted from lobby). * Check if the bot is currently in the meeting (admitted from lobby).
* Primary selector: button[id="hangup-button"] (confirmed by Recall.ai).
* Note: Teams uses `id` (not `data-tid`) for the hangup button since 2025 redesign.
*/ */
async isInMeeting(options: { waitForSeconds?: number } = {}): Promise<boolean> { async isInMeeting(options: { waitForSeconds?: number } = {}): Promise<boolean> {
const timeout = (options.waitForSeconds || 5) * 1000; const timeout = (options.waitForSeconds || 5) * 1000;
// Indicators that we're in the meeting // Primary selector - confirmed by Recall.ai (Jan 2025)
// Note: Teams now uses id="hangup-button" instead of data-tid="hangup-button"
const inMeetingSelectors = [ const inMeetingSelectors = [
'[data-tid="call-composite"]', 'button[id="hangup-button"]',
'[data-tid="meeting-roster"]', 'button[id="callingButtons-showMoreBtn"]',
// Fallbacks with data-tid (older Teams versions)
'[data-tid="hangup-button"]', '[data-tid="hangup-button"]',
'[data-tid="call-composite"]',
'button[aria-label*="Leave"]', 'button[aria-label*="Leave"]',
'[data-tid="callingButtons-showMoreBtn"]', '[data-tid="callingButtons-showMoreBtn"]',
]; ];
@ -261,27 +282,42 @@ export class JoinProcedure {
/** /**
* Leave the meeting gracefully. * Leave the meeting gracefully.
* Primary selector: button[id="hangup-button"] (confirmed by Recall.ai).
*/ */
async leaveMeetingFlow(): Promise<void> { async leaveMeetingFlow(): Promise<void> {
this._logger.info('Leaving meeting...'); this._logger.info('Leaving meeting...');
const leaveSelectors = [ // Primary selector - confirmed by Recall.ai (Jan 2025)
const primarySelector = 'button[id="hangup-button"]';
try {
await this._page.waitForSelector(primarySelector, { timeout: 5000 });
await this._page.click(primarySelector);
this._logger.info('Clicked leave button');
await this._page.waitForTimeout(2000);
return;
} catch {
this._logger.info('Primary leave selector not found, trying fallbacks...');
}
// Fallback selectors
const fallbackSelectors = [
'[data-tid="hangup-button"]', '[data-tid="hangup-button"]',
'button[aria-label*="Leave"]', 'button[aria-label*="Leave"]',
'button:has-text("Leave")', 'button:has-text("Leave")',
'[data-tid="call-hangup"]', '[data-tid="call-hangup"]',
]; ];
for (const selector of leaveSelectors) { for (const selector of fallbackSelectors) {
try { try {
const button = await this._page.$(selector); const button = await this._page.$(selector);
if (button) { if (button) {
await button.click(); await button.click();
this._logger.info('Clicked leave button'); this._logger.info(`Clicked leave button (fallback: ${selector})`);
await this._page.waitForTimeout(2000); await this._page.waitForTimeout(2000);
return; return;
} }
} catch (error) { } catch {
// Continue // Continue
} }
} }

View file

@ -60,24 +60,57 @@ export function isValidMeetingUrl(url: string): boolean {
return trimmedUrl.includes('/meet/') || trimmedUrl.includes('/l/meetup-join/'); return trimmedUrl.includes('/meet/') || trimmedUrl.includes('/l/meetup-join/');
} }
/**
* Resolves the meeting URL by following redirects and adding params to suppress
* the native app launcher dialog. This is the approach used by Recall.ai.
*
* Teams meeting URLs redirect through several hops. The final URL needs specific
* search params to skip the "Open in Teams app?" dialog in the browser.
*/
export async function resolveLaunchUrl(meetingUrl: string): Promise<string> {
const trimmed = meetingUrl.trim();
try {
const response = await fetch(trimmed, { redirect: 'follow' });
const resolvedUrl = new URL(response.url);
// Add params to suppress the native app launcher dialog
resolvedUrl.searchParams.set('msLaunch', 'false');
resolvedUrl.searchParams.set('type', 'meetup-join');
resolvedUrl.searchParams.set('directDl', 'true');
resolvedUrl.searchParams.set('enableMobilePage', 'true');
resolvedUrl.searchParams.set('suppressPrompt', 'true');
return resolvedUrl.toString();
} catch {
// Fallback: add params to the original URL
return _addLaunchParams(trimmed);
}
}
/**
* Fallback: adds launch params directly to the meeting URL without resolving redirects.
*/
function _addLaunchParams(url: string): string {
try {
const urlObj = new URL(url);
urlObj.searchParams.set('msLaunch', 'false');
urlObj.searchParams.set('suppressPrompt', 'true');
urlObj.searchParams.set('directDl', 'true');
urlObj.searchParams.set('enableMobilePage', 'true');
urlObj.searchParams.set('anon', 'true');
return urlObj.toString();
} catch {
// If URL parsing fails, append as query string
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}msLaunch=false&suppressPrompt=true&directDl=true&enableMobilePage=true&anon=true`;
}
}
/** /**
* Converts a meeting URL to the web app launch URL. * Converts a meeting URL to the web app launch URL.
* Teams web app requires a specific format to join meetings. * @deprecated Use resolveLaunchUrl() instead for proper redirect resolution.
*/ */
export function getMeetingLaunchUrl(url: string): string { export function getMeetingLaunchUrl(url: string): string {
const parsed = parseMeetingUrl(url); return _addLaunchParams(url);
// For short URLs, we can use them directly
if (parsed.type === 'short') {
return parsed.originalUrl;
}
// For classic URLs, ensure we're using the web version
// Add ?anon=true to skip sign-in prompt for anonymous join
let launchUrl = parsed.originalUrl;
if (!launchUrl.includes('anon=')) {
launchUrl += (launchUrl.includes('?') ? '&' : '?') + 'anon=true';
}
return launchUrl;
} }