hoxfon / react-native-twilio-programmable-voice

React Native wrapper for Twilio Programmable Voice SDK
MIT License
180 stars 153 forks source link

Android custom Call parameters are not passed to Twilio #63

Closed cin210 closed 3 years ago

cin210 commented 6 years ago

Using:

Step to reproduce:

Output:

01-18 16:01:59.377 29676-29723/com.myapp D/RNTwilioVoice: connect params: { NativeMap: {"Foo":"Bar","To":"+<my number>"} }
01-18 16:01:59.384 29676-29723/com.myapp D/CallControlManager: CallControlManager created
01-18 16:01:59.418 29676-29898/com.myapp D/UserAgent: Creating UserAgent
01-18 16:01:59.419 29676-29898/com.myapp I/PJSIP: 16:01:59.419 os_core_unix.c !pjlib 2.5.1 for POSIX initialized
01-18 16:01:59.422 29676-29898/com.myapp D/PJSIP: 16:01:59.422 sip_endpoint.c  .Creating endpoint instance...
01-18 16:01:59.423 29676-29898/com.myapp I/PJSIP: 16:01:59.423          pjlib  .select() I/O Queue created (0x78fbcc04)
01-18 16:01:59.423 29676-29898/com.myapp I/PJSIP: 16:01:59.423 sip_endpoint.c  .Module "mod-msg-print" registered
01-18 16:01:59.423 29676-29898/com.myapp D/PJSIP: 16:01:59.423 sip_transport.  .Transport manager created.
01-18 16:01:59.423 29676-29898/com.myapp I/PJSIP: 16:01:59.423   pjsua_core.c  .PJSUA state changed: NULL --> CREATED
01-18 16:01:59.448 29676-29676/com.myapp D/CallControlManager: Ignoring network event, sticky broadcast
01-18 16:01:59.485 1486-29907/? I/AudioFlinger: AudioFlinger's thread 0xa7d93680 tid=29907 ready to run
01-18 16:01:59.492 29676-29898/com.myapp D/AudioTrack: Client defaulted notificationFrames to 258 for frameCount 776
01-18 16:01:59.521 29676-29898/com.myapp W/AudioTrack: Use of stream types is deprecated for operations other than volume control
01-18 16:01:59.524 29676-29898/com.myapp W/AudioTrack: See the documentation of AudioTrack() for what to use instead with android.media.AudioAttributes to qualify your playback use case
01-18 16:01:59.549 1389-4268/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 30388505 , only wrote 30388320
01-18 16:01:59.566 29676-29898/com.myapp D/CallControlManager: Call  CALLING 
01-18 16:01:59.571 29676-29723/com.myapp D/Call: Received CALLING while in CONNECTING state
01-18 16:02:00.564 29676-29901/com.myapp D/CallControlManager: Call  EARLY 
01-18 16:02:00.565 29676-29723/com.myapp D/Call: Received EARLY while in CONNECTING state
01-18 16:02:00.566 29676-29901/com.myapp D/CallControlManager: onTransactionState received CA07f890fc727fee76e2498b49397d269e
01-18 16:02:00.859 29676-29901/com.myapp D/CallControlManager: Call CA07f890fc727fee76e2498b49397d269e EARLY 
01-18 16:02:00.859 29676-29723/com.myapp D/Call: Received EARLY while in CONNECTING state
01-18 16:02:00.860 29676-29901/com.myapp D/CallControlManager: onTransactionState received CA07f890fc727fee76e2498b49397d269e
01-18 16:02:04.888 29676-29901/com.myapp D/CallControlManager: Call CA07f890fc727fee76e2498b49397d269e DISCONNECTED 
01-18 16:02:04.888 29676-29723/com.myapp D/Call: Received DISCONNECTED while in CONNECTING state
01-18 16:02:04.995 29676-29898/com.myapp D/AudioTrack: stop() called with 87040 frames delivered
01-18 16:02:05.001 29676-29898/com.myapp D/UserAgent: Destroyed UserAgent
01-18 16:02:05.002 29676-29723/com.myapp D/InternalCall: Publishing event : disconnected-by-remote
01-18 16:02:05.011 29676-29723/com.myapp D/CallControlManager: CallControlManager destroyed
01-18 16:02:05.011 29676-29898/com.myapp D/CallCommandHandlerImpl: Shutting down thread
01-18 16:06:57.750 29676-29896/com.myapp W/OkHttpClient: A connection to https://ers.twilio.com/ was leaked. Did you forget to close a response body?
01-18 16:06:57.750 29676-29896/com.myapp W/OkHttpClient: A connection to https://eventgw.twilio.com/ was leaked. Did you forget to close a response body?

In Twilio:

Request:
URL: https://www.<mybackendserver>.com/call/route
Parameters:

ApplicationSid | APxxxxxxxxx
-- | --
ApiVersion | 2010-04-01
Called |  
Caller | client:user
CallStatus | ringing
From | client:user
To | +<my number>
CallSid | CAxxxxxxxxxx
Direction | inbound
AccountSid | ACxxxxxxxxx

Extra parameters are logged in Android when the call begins, and the call is connected successfully, but when inspecting the call in Twilio, the extra parameters are not present and they are never passed along to my server that handles the Twiml.

Some params I am trying to pass along are additional user and device meta data (example: version and model of the android device, as well as some app-specific account identifiers). Some of these params are required for determining how to handle the call at the server level, all while using the same dedicated Twiml App route.

It looks like the _callParams hash is serialized in the connect method, but it is not surviving the journey from client to Twiml to my server. Anything I am doing wrong here? Previously I was using the same Twiml App with the same params and https://www.npmjs.com/package/react-native-twilio but I waned to migrate because that library is not really maintained.

ApplicationSid and AccountSid are correct, the To field is correct, I can lookup the call by CallSID, but normally I am able to pass additional parameters through Twiml when making outbound calls, but not with this library.

Any advice (twilio-related or otherwise) would be appreciated.

MarcoCatalan commented 6 years ago

I also experienced this issue. This library only propagates to Twilio certain params (don't remember which atm). The issue here is how 'correct' is for twilio the use of custom parameters. If twilio says it's okay, this library should propagate all the custom parameters to the twilio android sdk (Don't know how this issue affects iOS)

I'd happily open a PR in that case :D

cin210 commented 6 years ago

This older article flatly states the mobile client cannot pass custom params, but this twilio API doc instructs you how to do so on android.

I believe it is correct behavior in the sense that Twilio has guides encouraging it and supports it in their other APIs like the Web javascript client

idelgado commented 6 years ago

I work on the Programmable Voice SDKs and can provide some guidance on this issue.

Passing custom parameters from the Android or iOS SDK to the server application is supported. However, propagating these custom parameters into the Twilio helper library to another client from your server code is not (this is a feature that has been requested and is in our backlog). If your server application requires additional context you are welcome to add custom parameters.

I would recommend either removing the validation and passing the params "as-is" in this method or using a flag to opt-out of this validation when needed. https://github.com/hoxfon/react-native-twilio-programmable-voice/blob/master/android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java#L621-L650

fabriziomoscon commented 6 years ago

Thanks @idelgado to jump in! Can you confirm that my understanding of your explanation is correct:

Considering the following SDK method call:

Voice.call(getReactApplicationContext(), accessToken, twiMLParams, callListener);

Could twiMLParams be a Map containing any arbitrary number of strings? If so we could iterate over the Javascript object passed and convert it into a Java Map - which is strongly typed - omitting any key containing non string values.

gongdao123 commented 6 years ago

I also experienced this issue. And made an pull request based on @idelgado 's suggestion.

https://github.com/hoxfon/react-native-twilio-programmable-voice/pull/94

jdegger commented 3 years ago

This has been resolved in #94, closing this issue