using System.Text.RegularExpressions; using Microsoft.Playwright; namespace BadmintonBooker; public static class OTPExtractor { public static async Task GetEgovOTP(IBrowserContext context, IPage originalPage) { var msgPage = await context.NewPageAsync(); await msgPage.GotoAsync("https://messages.google.com/web/u/0/conversations/CgjwUsdGGwxxGhIBNw", new PageGotoOptions { WaitUntil = WaitUntilState.Load }); var messageElement = msgPage.Locator("mws-text-message-part").Last; string messageText = await messageElement.InnerTextAsync(); await originalPage.BringToFrontAsync(); var match = Regex.Match(messageText, @"\b\d{5,}\b"); if (match.Success) { return match.Value; } else { Console.WriteLine("No OTP found in the message."); return null; } } }