Send one-time PINs
Learn how to send one-time PINs (OTPs) using Voice messages API.
Prerequisites
- You need an Infobip account. Log in (opens in a new tab) or if you do not have an account, sign up.
- API key
- Base URL
For the next steps and details, refer to Get Started with Infobip API.
Implementation steps
Once you have set up your account, you can start using the Voice API. The Infobip platform provides API requests for sending voice messages, such as Advanced Voice messages - POST /tts/3/advanced. Refer to Voice API documentation (opens in a new tab) for more details.
You can send an OTP to your end user using a voice message. That means the PIN is read out loud to your end user when they pick up the phone.
Request:
{
"bulkId": "Example Voice Message",
"messages": [
{
"text": "Hello, your code is 5 8 4 2.",
"language": "en",
"voice": {
"name": "Joanna",
"gender": "female"
},
"from": "38761222333",
"destinations": [
{
"to": "38762555888"
}
]
}
]
}
Moreover, the Voice messages API provides more options on how you want your messages to be delivered.
Tips and tricks
Spaces between digits
When sending your voice message, write the OTP digits with spaces between digits. For example, 5 8 4 2. This way each digit will be read separately in the audio file as five, eight, four, two. Type in text and it converts into an audio file which is then played to the end user when they answer the call.
What happens if you omit those spaces in between? Then if you write 5842, it will be read as five thousand eight hundred and forty-two.
Speech rate
For a better user experience, you can expand the voice message request with some additional features. For example, adjusting the speech rate. For such cases, use advanced voice messages.
To slow down the speech rate, add the speechRate parameter. Use this to allow your end users to have enough time to write down the code they hear.
The default value of this field is 1, but the range goes from 0.5 to 2. The lower the number, the slower the speech will be. Test different speech rates and choose which suits your end users best.
{
"bulkId": "Example Voice Message",
"messages": [
{
"text": "Hello, your code is 5 8 4 2.",
"language": "en",
"voice": {
"name": "Joanna",
"gender": "female"
},
"speechRate": 0.7,
"from": "38761222333",
"destinations": [
{
"to": "38762555888"
}
]
}
]
}
Repeat digits
To allow the end user to repeat their voice message, use response codes (the DTMF feature). If you add this option, the end user can tap the keypad on their phone to repeat the message. Just be sure to define the trigger. Then you probably don't need to slow down the speech rate.
Infobip Voice API has three different request parameters for repeat digits functionality:
- repeatDtmf – The trigger. Indicates which digit the end user should press for the message to be repeated.
- maxDtmf – Defines the maximum number of digits the end user can enter. If you set it to 1, Infobip only registers one digit, the first one the end user taps.
- dtmfTimeout – Defines the number of minutes that Infobip waits for the end user to tap a digit. In our code example, we have set it to 5 seconds. This means the end user has 5 seconds to respond by entering a digit or digits.
Again, test and see what works best for your use case.
{
"bulkId": "Example Voice Message",
"messages": [
{
"text": "Hello, your code is 5 8 4 2. Please press 5 to repeat.",
"language": "en",
"voice": {
"name": "Joanna",
"gender": "female"
},
"repeatDtmf": "5",
"maxDtmf": 1,
"dtmfTimeout": 5,
"from": "38761222333",
"destinations": [
{
"to": "38762555888"
}
]
}
]
}
Insert Double Commas (,,)
Insert double commas between the digits to create a better user experience. This actually means double commas introduce a pause changing the speech pattern to a more natural one. No additional parameters are needed.
When sending OTPs, you can add a double comma after each digit, even before the first digit. This will give the end user more time to prepare and save/write down the PIN.
Now, if one pause is not enough, you can add more double commas as needed. Again, it is important to test different cases and based on that use the best possible solution for you.
{
"bulkId": "Example Voice Message",
"messages": [
{
"text": "Hello, your code is,, 5,, 8,, 4,, 2.",
"language": "en",
"voice": {
"name": "Joanna",
"gender": "female"
},
"from": "38761709300",
"destinations": [
{
"to": "38762021106"
}
]
}
]