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",
);import os
from telesign.messaging import MessagingClient
telesign = MessagingClient(
os.environ["TELESIGN_CUSTOMER_ID"], # otpmock API key in tests
os.environ["TELESIGN_API_KEY"],
rest_endpoint=os.environ.get("OTPMOCK_URL", "https://rest-api.telesign.com"),
)import com.telesign.MessagingClient;
MessagingClient telesign = new MessagingClient(
System.getenv("TELESIGN_CUSTOMER_ID"), // otpmock API key in tests
System.getenv("TELESIGN_API_KEY"),
System.getenv().getOrDefault("OTPMOCK_URL", "https://rest-api.telesign.com"));using Telesign;
var messaging = new MessagingClient(
Environment.GetEnvironmentVariable("TELESIGN_CUSTOMER_ID"), // otpmock API key in tests
Environment.GetEnvironmentVariable("TELESIGN_API_KEY"),
Environment.GetEnvironmentVariable("OTPMOCK_URL") ?? "https://rest-api.telesign.com",
"csharp_telesign", null, null);use telesign\sdk\messaging\MessagingClient;
$telesign = new MessagingClient(
getenv('TELESIGN_CUSTOMER_ID'), // otpmock API key in tests
getenv('TELESIGN_API_KEY'),
getenv('OTPMOCK_URL') ?: 'https://rest-api.telesign.com',
);
// SMS Verify (HTTP; the SDK has no verify client): Basic customer ID : API key.
$verifyUrl = getenv('OTPMOCK_URL') ?: 'https://rest-ww.telesign.com';
$auth = [getenv('TELESIGN_CUSTOMER_ID'), getenv('TELESIGN_API_KEY')];
$ref = json_decode((string) (new \GuzzleHttp\Client())->post("$verifyUrl/v1/verify/sms", [
'auth' => $auth, 'form_params' => ['phone_number' => '15550142'],
])->getBody(), true)['reference_id'];
// then GET "$verifyUrl/v1/verify/$ref?verify_code=..." -> verify.code_state "VALID"require "telesign"
messaging = Telesign::MessagingClient.new(
ENV["TELESIGN_CUSTOMER_ID"], # otpmock API key in tests
ENV["TELESIGN_API_KEY"],
rest_endpoint: ENV.fetch("OTPMOCK_URL", "https://rest-api.telesign.com")
)// Telesign has no official Go SDK; call its HTTP API with net/http, only the host changes.
base := os.Getenv("OTPMOCK_URL")
if base == "" {
base = "https://rest-api.telesign.com"
}
form := url.Values{"phone_number": {"15550142"}, "message": {msg}, "message_type": {"OTP"}}
req, _ := http.NewRequest("POST", base+"/v1/messaging", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth(os.Getenv("TELESIGN_CUSTOMER_ID"), os.Getenv("TELESIGN_API_KEY")) // customer ID = otpmock key in tests
res, err := http.DefaultClient.Do(req) // body status.code 290 = in progressEach language is tested in CI against otpmock with the provider's official SDK, or its plain HTTP API where no SDK can be pointed at another host.
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 |
POST /v1/verify/sms | SMS Verify: send a code (verify_code optional, template with $$CODE$$) |
GET /v1/verify/{reference_id}?verify_code= | SMS Verify: check; verify.code_state VALID, INVALID or MAX_ATTEMPTS_EXCEEDED |
POST /verification | Verify API (verify.telesign.com): start an SMS verification, 201 with status 3901 |
PATCH /verification/{reference_id}/state | Verify API: finalize with security_factor (204 on success, 400 on a wrong code) |
GET /verification/{reference_id} | Verify API: status (3900 Verified, 3901 In progress) |
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.
How to tell your app uses Telesign
Look for any of these in your codebase to confirm where the SMS is sent, and therefore where the otpmock option has to be set:
telesignsdkortelesignenterprisesdkin package.jsonclient.sms.message(- requests to
/v1/verify/smsorverify.telesign.com/verification
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. - The Node SDK has no Verify methods. Call SMS Verify with
telesign.rest.execute(callback, "POST", "/v1/verify/sms", params). For the Verify API (normally onverify.telesign.com), point your HTTP client's base URL atOTPMOCK_URLand keep Basic auth with the otpmock key as the customer ID. - Verify API error codes for wrong or exhausted codes follow Telesign's error envelope (
errors[].code,description), but the exact numeric codes may differ from Telesign's; check the HTTP status instead.
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); POST /v1/verify/sms (SMS Verify: send a code (verify_code optional, template with $$CODE$$)); GET /v1/verify/{reference_id}?verify_code= (SMS Verify: check; verify.code_state VALID, INVALID or MAX_ATTEMPTS_EXCEEDED); POST /verification (Verify API (verify.telesign.com): start an SMS verification, 201 with status 3901); PATCH /verification/{reference_id}/state (Verify API: finalize with security_factor (204 on success, 400 on a wrong code)); GET /verification/{reference_id} (Verify API: status (3900 Verified, 3901 In progress)).
The free plan includes 300 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.
Get a free API key