Set OTPMOCK_URL=https://api.otpmock.com in your test environment, point the Telesign client at it, and use your otpmock API key as the Telesign credential. Your application code doesn't change, and production keeps sending real SMS through Telesign.
Setup
The SDK takes the REST endpoint as its third constructor argument.
import TeleSignSDK from "telesignsdk";
export const telesign = new TeleSignSDK(
process.env.TELESIGN_CUSTOMER_ID, // otpmock API key in tests
process.env.TELESIGN_API_KEY,
process.env.OTPMOCK_URL ?? "https://rest-api.telesign.com",
);Credentials. In the test environment, use your otpmock API key as the Telesign customer ID. The API key can be any base64 value: the SDK signs requests with HMAC, and otpmock reads the customer ID without checking the signature. Basic auth also works.
What otpmock emulates
| Endpoint | What it does |
|---|---|
POST /v1/messaging | Send an SMS (phone_number, message, message_type); status.code 290 on success |
Responses and errors follow Telesign's own format, so the SDK parses them as usual. Authentication failures and an exhausted monthly allowance also come back in Telesign's error shape.
Phone numbers
Telesign uses digits with country code (15550142). otpmock stores +15550142.
Read the code in your tests
const phone = otp.randomPhone();
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Send code" }).click(); // your app calls Telesign
const { code } = await otp.waitForCode(phone, { since });The otp helper is a single file: get it from the docs. Full walkthroughs: Playwright, Cypress.
Good to know
- Clients should check
status.code(290 = in progress), as with the real API. - Telesign's Verify API lives on a second host and isn't emulated yet; SMS-based OTP that your app generates works today.
FAQ
Does otpmock send real SMS through Telesign?
No. In the test environment your app's Telesign requests go to otpmock, which stores the message for 10 minutes and never contacts Telesign or any carrier. Production keeps using Telesign because otpmock is only enabled when OTPMOCK_URL is set.
Is the official telesignsdk SDK supported?
Yes. otpmock's Telesign endpoints are tested end to end with the official telesignsdk package for Node.js. Other languages work too if their Telesign client lets you change the API host.
Which Telesign APIs does otpmock support?
POST /v1/messaging (Send an SMS (phone_number, message, message_type); status.code 290 on success).
The free plan includes 100 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.
Get a free API key