Skip to content

Instantly share code, notes, and snippets.

@checklyalex
Created April 24, 2024 11:32
Show Gist options
  • Save checklyalex/207b286dfd846113934dcff5f2449f56 to your computer and use it in GitHub Desktop.
Save checklyalex/207b286dfd846113934dcff5f2449f56 to your computer and use it in GitHub Desktop.
const { expect, test } = require('@playwright/test')
const twilio = require('twilio');
import { fetchLatestSMS } from './smsHelpers.ts';
const TWILIO_ACCOUNT_SID = ""
const TWILIO_AUTH_TOKEN = ""
test('Verify SMS code', async ({ page }) => {
const twilioClient = twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
const toNumber = "+44xxxxxxxxxx"
// Retrieve the SMS message
try {
const smsBody = await fetchLatestSMS(twilioClient, toNumber);
const matchResult = (smsBody as string).match(/(\d+)$/); // Match a number from the string
if (matchResult) {
const verificationCode = matchResult[0];
} else {
console.error('No matching code found');
// Handle the case where no match is found
}
} catch (error) {
console.error('Failed to retrieve or process SMS:', error);
}
});
@checklyalex
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment