Tutorials

Verification

In this tutorial we will show you in 2 steps how you can integrate our verification API into your website to enable 2FA.

When somebody creates a user for your website, you ask in most cases for his name and email. For integrating our verification service you will need to ask for his mobile number as well. Now when the user logs in to your website, you ask for his username and password. If the entered credentials are correct our verification service will start to kick in.

With the following code you will send a verification token to the users' mobile and you will show a simple form where he can enter the received token.

That's it! Now you have verified the user and the user can continue to your website. You can find these sample files on GitHub.

Bio Voice Verification

In this tutorial we will explain how the Bio Voice verification of Twizo works.

Bio voice verification is a verification based on your voice. In order to be able to do such verification, you first have to register a user for it. This is done via a phone call where the user needs to say a sentence 3 times. Based on this a voice print of the user is created.

So first start a registration, once the registration is completed, a subscription is created. The sentence the user has to say is by default 'Verify me with my voicepin'. If you want a different sentence, please contact our support.

The flow is like this:

Start a Bio voice registration

The Twizo API will start a call to the user and asks to say a sentence 3 times

While the status is 'no_status' the bio voice registration is still in progress. When the status is 'success' the registration is successful and when it is 'failed' the registration failed. When it failed you can start a new registration.

The registration is now completed. The registration is now turned into a subscription. Check the status of the subscription:

Did you know that with our widget, you don't have to implement this? Our widget will handle the registration for you. Read more about it in our widget guide.

Phone number structure

When you want to send a verification, SMS or Number Lookup, you have to specify a phone number. The phone number must be in E.164 number format but without leading +. This format is the internationally-standardised format for all phone numbers.

So when you are located in Singapore and you want to send a verification to a Singaporean number, you will have to include the country prefix to the number. Example: when the Singaporean number is 081234567, you will have to prepend the country prefix of Singapore, +65, to the mobile number, but without the leading +. So 6581234567. For a good reference on the country prefixes, check Wiki here .

Unicode

For normal SMS messages the body is in GSM-7 alphabet and can contain the characters as specified in the GSM 0.038 specification . If you want to send other characters you will need to send the SMS as Unicode. You will need to set the DCS to 8. For normal messages the DCS is 0. The maximum length for Unicode messages is not 160 characters as for normal messages but 70 characters. If you want to send longer Unicode messages you will need to use the concatenated SMS functionality. See Concatenated/long messages for more details. For our Advanced SMS API you will need to consider the maximum body length and set the DCS to 8 for Unicode messages. However our Simple SMS API can do that for you. It will automatically detect if the message is Unicode, set the DCS to 8 and split up into maximum 9 concatenated parts.

Concatenated/long messages

The maximum length for normal SMS messages is 160 characters and for Unicode 70 characters. If you want to send longer messages, you will need to split up the body of the message by sending each body part of the message separately and adding a UDH (See also GSM specification for more information). The maximum length for normal messages will then be 154 characters per body part and for Unicode 67 characters per body part. You can set all these settings in our Advanced SMS API. However our Simple SMS API can do that for you. It will automatically detect if the message is Unicode and split up into maximum 9 concatenated parts. Example of a long message using our Simple SMS API:

$data = array(
'recipients' => array(
'1234567890',
),
'body' => 'This is a long message, This is a long message, This is a long message, This is a long message, This is a long message, This is a long message, This is a long message.',
'sender' => '1234567890',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-asia-01.twizo.com/v1/sms/submitsimple");
curl_setopt($ch, CURLOPT_USERPWD, 'twizo' . ':' . '<api-key>');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($data)))
);
$response = curl_exec($ch);
curl_close($ch);
//show the output in a pretty format
$json = json_decode($response);
echo json_encode($json, JSON_PRETTY_PRINT);

$data = array(
'recipients' => array(
'1234567890',
),
'body' => 'This is a long message, This is a long message, This is a long message, This is a long message, This is a long message, This is a long message, This is a long message.',
'sender' => '1234567890',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-eu-01.twizo.com/v1/sms/submitsimple");
curl_setopt($ch, CURLOPT_USERPWD, 'twizo' . ':' . '<api-key>');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($data)))
);
$response = curl_exec($ch);
curl_close($ch);
//show the output in a pretty format
$json = json_decode($response);
echo json_encode($json, JSON_PRETTY_PRINT);

Sender

With the sender ID you can set where the SMS comes from. So you can set for example your mobile number or your company name as the sender. There are two types of sender IDs:

Numeric

Alphanumeric

Our API can automatically detect the type of sender ID and sets the parameters senderTon and senderNpi automatically. However if you want you can set them yourselves as that is possible as well. When you do not set the senderTon and senderNpi, or set it to 'null', the API will automatically detect the sender. The auto detection rules are:

For both types of sender IDs there can be requirements from the operator or country to pre-register it. Please contact us for pre-registration should that be a requirement of yours. If the sender ID is not pre-registered the message might not get delivered or can be overwritten with a default one.

Numeric sender

The maximum length of a numeric sender ID is 17. Only the digits 0-9 are allowed. The two most important options for numeric senders are:

International (senderTon = 1, senderNpi = 1)

National (senderTon 2, senderNpi = 1)

Only with international sender IDs can the receiver reply to the message. However you would need to use our SMS MO service to achieve a full reply path. Through our MO service we will provide you with a number where the receiver can reply to and you will then receive the message from us. Please contact us for our MO services should that be a requirement of yours.

Alphanumeric sender

The maximum length of an alphanumeric sender ID is 11. The characters A-Z and digits 0-9 are supported. Uppercase, lowercase characters and whitespaces are allowed.

For alphanumeric sender IDs the senderTon should be 5 and the senderNpi should be 0. If you leave the senderTon and senderNPI empty our API will automatically set it as described above. Or you can set it yourself to be sure it is marked as an alphanumeric sender.

With an alphanumeric sender ID the receiver will not be able to reply to the message. If you want the receiver to be able to reply to messages you have to use our service SMS MO. Please contact us for our MO services should that be a requirement of yours.