twilio / voice-quickstart-ios

Twilio Voice Quickstart for iOS with Swift
MIT License
183 stars 97 forks source link

Tracking the pickup of call on the receiver side is not working with answerOnBridge enabled on a very specific scenario #488

Closed saqibdb closed 1 year ago

saqibdb commented 2 years ago

Description

As I understand from the documentation, To track if the call has been answered by the called party, you can enable the answerOnBridge flag in your verb, that way the caller client will only receive the callDidConnect: callback when the call is accepted. I am using the answerOnBridge in my twiml code to see when the reciever picks up the call, so i can show the call timer based on this function in the ios app "callDidConnect()" This is working for the most part, but in the twiml code, i am also using twiml.say("Hello World"); with a conditional check, the issue is when the twiml.say() text to speech function is executed, then the answerOnBridge fails completely and callDidConnect is called as soon as the twiml.say() speech starts to happen. I made the application in a way so that a text is spoken to caller in a certain scenario, before the call starts to ring. But as soon as text is spoken, the timer that i placed for knowing when the call was picked up by the receiver starts to run because the callDidConnect() gets called. I have checked it with multiple scenarios and so far it is only happening if the twiml.say() is executed before the dial.number(to);

Steps to Reproduce

  1. Call any number with twiml code dial.number(to);
  2. Before the dial.number(to);, use twiml.say("Hello World");
  3. As soon as twiml.say("Hello World"); is executed and you hear the words on caller side, callDidConnect() gets executed on caller side

Code

exports.handler = function(context, event, callback) {
  var to = event.to;
  var comingFrom = event.coming_from;
  const twiml = new Twilio.twiml.VoiceResponse();

  twiml.say('Testing the scenario in which the answer On Bridge is not properly running.');
  const dial = twiml.dial({callerId : comingFrom, answerOnBridge : true, record : 'record-from-answer'});
  var callResult = dial.number(to);
  console.log('On Number '+ twiml.toString());
  callback(null, twiml);
};

Expected Behavior

Even with twiml.say(), answerOnBridge should make sure that callDidConnect is called only when the call is picked up on the other side (receiver side)

Actual Behavior

if twiml.say() is executed then the callDidConnect is called even if the call was not picked from receiver's end while answerOnBridge was enabled

Reproduces How Often

Everytime on this specific scenario

Twilio Call SID(s)

CA9ce70fa679b8e2f7df11746185a1580b Parent Call SID = CA17f83803abaeacbb1f1827abced47cd8

Logs

<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><Say>Testing the scenario in which the answer On Bridge is not properly running..</Say><Dial callerId=\"Hidden\" answerOnBridge=\"true\"><Number>Hidden</Number></Dial></Response>"

Versions

twilio-cli version 2.18.0.

Voice iOS SDK

6.2.0

Xcode

12.5

iOS Version

14.4

iOS Device

6s, 11 pro, 12 pro

bobiechen-twilio commented 2 years ago

Hi @saqibdb

Thanks for reaching out. As you have observed the behavior, the SDK does emit a connected event in this case to indicate that the media connection is established and ready for the audio of the verb to flow.

I'll check with the API documentation team and see if we can add a note to the answerOnBridge flag.

saqibdb commented 2 years ago

@bobiechen-twilio thanks for the very fast reply. So is there any other way to keep track of receiver's call pickup while using twiml.say()? Any way from call object, i can get the information that media connection is from twiml server to caller, or is it from receiver to caller? Otherwise, i can handle the text to speech parts at the mobile application end as well, so twiml server can just be used for calling rather than calling and text to speech

bobiechen-twilio commented 1 year ago

@saqibdb Please reach out to Twilio Support if you still need Programmable Voice help.