Contiguity offers a free OTP API that simplifies phone number verification using OTPs via SMS, which eliminates the need to develop custom logic. Gone are the days of paying for this simple feature.
Contiguity still bills you for the text messages on our Usage tier, includes them in Unlimited, and subtracts them from your quota if you’re on the Free tier.We don’t charge extra for the OTP API.
Installing the SDK
Initialize the Client
import { Contiguity } from "contiguity";
const contiguity = new Contiguity("contiguity_sk_...your_key...");
import { Contiguity } from "contiguity";
// Reads CONTIGUITY_API_KEY or CONTIGUITY_TOKEN
const contiguity = new Contiguity();
Sending and Verifying OTPs
Send an OTP
To verify a user’s phone number, you’ll first need to send them an OTP.const res = await contiguity.otp.new({
to: "+1234567890",
language: "en",
name: "MyApp"
});
The name parameter is optional, but recommended. It customizes the message to say “Your [name] code is…”, e.g. “Your Twilio code is…”
Verify the Code
When your user inputs the code, verify it using the OTP ID from the previous step.const res = await contiguity.otp.verify({
otp_id: "otp_123",
otp: "123456"
});
The verification will return a boolean (true/false). OTPs expire 15 minutes after sending.
Resend if Needed
If needed, you can resend an OTP using the original OTP ID.const res = await contiguity.otp.resend({
otp_id: "otp_123"
});
Resending an OTP does not renew its expiry time.
Parameters
otp.new(params)
The recipient’s phone number in E.164 format (e.g., “+1234567890”).
The language code for the OTP message. See supported languages below.
The name of your application or service. This will be included in the OTP message as “Your [name] code is…“.
otp.verify(params)
The unique OTP identifier returned from the otp.new() call.
The 6-digit verification code entered by the user.
otp.resend(params)
The unique OTP identifier from the original otp.new() call.
Installing the SDK
Initialize the Client
import contiguity
client = contiguity.login("your_token_here")
You can also initialize it with the optional ‘debug’ flag:client = contiguity.login("your_token_here", True)
Sending and Verifying OTPs
Send an OTP
To verify a user’s phone number, you’ll first need to send them an OTP.otp_id = client.otp.send({
'to': "+15555555555",
'language': "en",
'name': "Contiguity"
})
The name parameter is optional, but recommended. It customizes the message to say “Your [name] code is…”, e.g. “Your Twilio code is…”
Verify the Code
When your user inputs the code, verify it using the OTP ID from the previous step.verify = client.otp.verify({
'otp_id': otp_id, # from the previous step
'otp': input # the 6 digits your user inputted
})
The verification will return a boolean (true/false). OTPs expire 15 minutes after sending.
Resend if Needed
If needed, you can resend an OTP using the original OTP ID.resend = client.otp.resend({
'otp_id': otp_id # from the first step
})
Resending an OTP does not renew its expiry time.
Parameters
otp.send(params)
The recipient’s phone number in E.164 format (e.g., “+15555555555”).
The language code for the OTP message. See supported languages below.
The name of your application or service. This will be included in the OTP message as “Your [name] code is…“.
otp.verify(params)
The unique OTP identifier returned from the otp.send() call.
The 6-digit verification code entered by the user.
otp.resend(params)
The unique OTP identifier from the original otp.send() call.
Supported Languages
Contiguity currently supports 33 languages for OTPs, including:
English (en), Afrikaans (af), Arabic (ar), Catalan (ca), Chinese / Mandarin (zh), Cantonese (zh-hk), Croatian (hr), Czech (cs), Danish (da), Dutch (nl), Finnish (fi), French (fr), German (de), Greek (el), Hebrew (he), Hindi (hi), Hungarian (hu), Indonesian (id), Italian (it), Japanese (ja), Korean (ko), Malay (ms), Norwegian (nb), Polish (pl), Portuguese - Brazil (pt-br), Portuguese (pt), Romanian (ro), Russian (ru), Spanish (es), Swedish (sv), Tagalog (tl), Thai (th), Turkish (tr), and Vietnamese (vi)
