Skip to main content
Clawise

Receiving OTP

Phone verification works in three steps: list the supported services to find one, create a verification to get a number, then long-poll for the code.

Step 1 — Find a service

Each service entry lists the countries it supports. Use this to pick a service + country_code pair before creating a verification.

import { Clawise } from "clawise";
const clawise = new Clawise({ apiKey: "..." });

const services = await clawise.phone.services.list();
for (const svc of services) {
  console.log(svc.service, svc.countries);
}
// { service: "WhatsApp", countries: ["BR", "GB", "IN", "US"] }
from clawise import Clawise
clawise = Clawise(api_key="...")

for svc in clawise.phone.services.list():
    print(svc.service, svc.countries)
services, _ := client.Phone.Services.List(ctx)
for _, svc := range services {
    fmt.Println(svc.Service, svc.Countries)
}
clawise phone services

Step 2 — Create a verification

Specify the messaging service and destination country_code. Clawise assigns a phone number scoped to the requested region.

const ver = await clawise.phone.verifications.create({
  service: "WhatsApp",
  country_code: "US",
});
console.log("Phone number:", ver.number);
ver = clawise.phone.verifications.create(
    service="WhatsApp",
    country_code="US",
)
print("Phone number:", ver.number)
ver, _ := client.Phone.Verifications.Create(ctx, &clawise.VerificationCreateParams{
    Service:     "WhatsApp",
    CountryCode: "US",
})
fmt.Println("Phone number:", ver.Number)
clawise phone verification create --service WhatsApp --country-code US

The response gives you a phone number and a verification ID:

{
  "id": "ver_01j9x...",
  "service": "WhatsApp",
  "number": "+12025550142",
  "status": "pending",
  "expires_at": "2026-04-04T12:15:00Z"
}

Now drop ver.number into the service's sign-up form so the service sends an OTP to it.

Step 3 — Wait for the OTP

wait_for_otp is a long-poll — it blocks until the code arrives or the timeout elapses.

const result = await clawise.phone.verifications.waitForOTP(ver.id, { timeout: 60 });
if (result.found) {
  console.log("OTP:", result.code);
} else {
  console.log("No OTP within 60s — retry or cancel");
}
result = clawise.phone.verifications.wait_for_otp(ver.id, timeout=60)
if result.found:
    print("OTP:", result.code)
timeout := 60
result, _ := client.Phone.Verifications.WaitForOTP(ctx, ver.ID, &timeout)
if result.Found {
    fmt.Println("OTP:", result.Code)
}

If found is false, the call timed out. Retry by calling wait_for_otp again — the verification stays alive until its 15-minute expiry.

Cancel a verification

If the OTP hasn't arrived yet and you no longer need the number, cancel to release it early:

await clawise.phone.verifications.cancel(ver.id);
clawise.phone.verifications.cancel(ver.id)
client.Phone.Verifications.Cancel(ctx, ver.ID)

Lifecycle

StatusMeaning
pendingSession created, waiting for the OTP to arrive
receivedCode arrived and is ready to retrieve
completedOTP successfully extracted
cancelledManually cancelled
expiredTimed out before any code was received (15-minute limit)

A session stays in pending for up to 15 minutes. Once it reaches completed, cancelled, or expired, no further transitions occur.

Reference

On this page