Search code examples
javaspring-boottwiliotwilio-twiml

How to make Twilio to tell OTP one by one in call using Spring Boot


I have integrated twilio voice OTP using TwiML Bins.

TwilioRestClient twilioClient = makeTwilioConnection();

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Url", applicationProperties.getTwilioVoiceTemplateURL() + "?otp=" + otp));
params.add(new BasicNameValuePair("To", "+" + requestOtpDto.getMobileNumber()));
params.add(new BasicNameValuePair("From", applicationProperties.getTwilioNumber()));

CallFactory callFactory = twilioClient.getAccount().getCallFactory();
callFactory.create(params);

My TwiML Bin is:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Pause length="1"/>
 <Say>The 6 digit verification code to register in ****** is {{otp}}</Say>
</Response>

So the OTP is 123456. I want to tell it one by one. In call it is telling as "Thousand Twenty Three, Four Hundred and Fifty Six", that too in a very fast way.

Can anyone give solution for this?


Solution

  • Try using SSML

    Text-to-Speech https://www.twilio.com/docs/voice/twiml/say/text-speech#say-as

    Say-As * Interpret as digits

    <say-as interpret-as="digits">[text to be interpreted]</say-as>