Twilio客户端识别应用到应用的Voip呼叫



我正在使用Twilio VoIP实现应用程序到应用程序的语音呼叫。通过文档,我能够使用Twilio在电话号码之间拨打电话。

为了在两个设备之间进行呼叫而不使用电话号码,Twilio文档建议使用客户端标识符。

如何创建客户端标识符?Twilio是否存储客户端标识符?

我试着通过Twiliio拨打两个电话号码。接下来,我尝试使用Twilio进行应用程序到应用程序调用,但我不清楚Twilio如何识别两个设备/客户端

要创建客户端标识符,您需要一个访问令牌。例如,要在Python中为Voice SDK创建一个访问令牌:

import os
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import VoiceGrant
# required for all twilio access tokens
# To set up environmental variables, see http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
api_key = os.environ['TWILIO_API_KEY']
api_secret = os.environ['TWILIO_API_KEY_SECRET']
# required for Voice grant
outgoing_application_sid = 'APxxxxxxxxxxxxx'
identity = 'user'
# Create access token with credentials
token = AccessToken(account_sid, api_key, api_secret, identity=identity)
# Create a Voice grant and add to token
voice_grant = VoiceGrant(
outgoing_application_sid=outgoing_application_sid,
incoming_allow=True, # Optional: add to allow incoming calls
)
token.add_grant(voice_grant)
# Return token info as JSON
print(token.to_jwt())

在本例中,identity将与访问令牌相关联。然后,当您进行语音呼叫时,To or From参数的格式应为client:name_of_identity.

最新更新