Created
April 24, 2024 11:32
-
-
Save checklyalex/207b286dfd846113934dcff5f2449f56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
smsHelpers.ts -> https://gist.github.com/checklyalex/cf44dc668ba124aa4a8efe82eb1f48ee