Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token Generation for Twilio Voice with Subaccounts #442

Open
ihorMarynichZazmic opened this issue Oct 28, 2024 · 6 comments
Open

Token Generation for Twilio Voice with Subaccounts #442

ihorMarynichZazmic opened this issue Oct 28, 2024 · 6 comments
Labels
needs more info Needs more info from the issue author.

Comments

@ihorMarynichZazmic
Copy link

We are trying to generate a token for Twilio Voice using the following code snippet:

voiceGrant = new VoiceGrant({

outgoingApplicationSid: twilioOutgoingApplicationSid,

incomingAllow: true

});

const token = new AccessToken(

twilioAccountSid,

twilioApiKey,

twilioApiSecret,

{ identity:identity }

);

token.addGrant(voiceGrant);

return token.toJwt();

We are using the official library and subaccounts, but it's not working as expected. Please assist us further.

@mhuynh5757
Copy link
Collaborator

Hi @ihorMarynichZazmic please format your code using the Github code snippet syntax, using triple backticks. It helps with readability for debugging your issue.

Let's specify further what is not working. Are you able to make outgoing calls, receive incoming calls, etc.? Do you see any crashes or strange behavior in your app? Any errors logged to console?

@ihorMarynichZazmic
Copy link
Author

Hi @mhuynh5757,

Thank you for following up. Here’s some additional context to clarify the issue.

Current Problem
The main issue is that the token generated with the provided code snippet does not appear to be working as expected, specifically for making outgoing calls. Here’s what we’re experiencing:

Outgoing Calls: When attempting to place an outgoing call, the app stays in the initialization phase, and no Call SID is generated in the Twilio console.
Incoming Calls: Incoming calls also do not seem to trigger any notifications or updates on the device.
Errors and Logs: We are not seeing any error messages in the console, but there is no evidence of the call setup either in our app or the Twilio console.
Code Context
Here is the code snippet we’re using to generate the token, reformatted for readability:

const voiceGrant = new VoiceGrant({
  outgoingApplicationSid: twilioOutgoingApplicationSid,
  incomingAllow: true
});

const token = new AccessToken(
  twilioAccountSid,
  twilioApiKey,
  twilioApiSecret,
  { identity: identity }
);

token.addGrant(voiceGrant);

return token.toJwt();

We are using the official Twilio library with subaccounts, and the necessary credentials (Account SID, API Key, API Secret) have been double-checked.

Additional Details
Environment: This issue is occurring on our production environment with subaccounts.
Expected Behavior: We expected the token to allow the app to successfully initiate an outgoing call and connect through Twilio.
If there are any suggestions for debugging this setup or if we need to check any specific configurations, we would appreciate the guidance.

Thank you!
Ihor

@mhuynh5757
Copy link
Collaborator

Hi @ihorMarynichZazmic thanks for the further clarification and the reformatting, I really appreciate it. Are you attempting to make calls from a subaccount to a client registered with the parent account? It is my understanding that you can only make calls between clients registered to the same account SID, meaning that the following scenario will not work:

Account A
Subaccount B (parent account A)

Alice uses a token made with Account A
Bob uses a token made with Account B

Alice calls Bob, or Bob calls Alice

Let me verify this with my team, but I'm fairly confident this scenario will not work.

@varfolomejevigorzazmic
Copy link

Hi @ihorMarynichZazmic thanks for the further clarification and the reformatting, I really appreciate it. Are you attempting to make calls from a subaccount to a client registered with the parent account? It is my understanding that you can only make calls between clients registered to the same account SID, meaning that the following scenario will not work:

Account A
Subaccount B (parent account A)

Alice uses a token made with Account A
Bob uses a token made with Account B

Alice calls Bob, or Bob calls Alice

Let me verify this with my team, but I'm fairly confident this scenario will not work.

Hello,

We are not do calls between sub accounts. We are trying to make a call from sub account to our phone number in USA. So we just want make it working to call from our active phone number in sub account using sub account credentials

@mhuynh5757
Copy link
Collaborator

Hi @varfolomejevigorzazmic thanks for the additional info. Could I ask for more details about your dev environment? Are you targeting Android or iOS? Are you using a real device or a virtual one? Do you see any errors in the native logs, Xcode for iOS and Android Studio/logcat for Android?

@ihorMarynichZazmic
Copy link
Author

ihorMarynichZazmic commented Nov 6, 2024

Hi @mhuynh5757
Myself and @varfolomejevigorzazmic are working on the same project and have the same indentical condition
What exactly do you mean by dev environment, maybe give an example? I'm trying targeting on iOS, next step will be on Android. Yes, I used a real device. I'm not using Xcode for iOS and Android Studio/logcat for Android because I'm working on expo with manager flow.

Token Generation and Registration: The token appears to be generated and fetched correctly:

LOG Fetching Twilio token...
LOG Twilio token fetched: eyJhbGciOiJIUzI1NiIs...
LOG Voice client registered with token
Outgoing Call Attempt:

The call parameters include a from number (+12525422504), a recipient type (ios), and a to number (e.g., +17162885949).
Despite setting these parameters, the outgoing call object logs show _from and _to as undefined.
Error Details:

During the call process, the call remains in the "connecting" state and finally ends with a "Decline" error:
ERROR ConnectFailure: [Decline: Decline (31603): Decline]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Needs more info from the issue author.
Projects
None yet
Development

No branches or pull requests

3 participants