简体   繁体   English

无法进行简单的 twilio 调用

[英]Not able to do simple twilio call

I am not able to do simple 2 way audio call between 2 numbers using twilio.我无法使用 twilio 在 2 个号码之间进行简单的 2 路音频通话。 I have attached my python (Django) code.我附上了我的 python (Django) 代码。 when I run the code, call Get connected and but after accepting call it get's disconnected immediately.当我运行代码时,调用获取连接,但在接受调用后立即断开连接。 also, I am not able listen to anything on Laptop.另外,我无法在笔记本电脑上听任何东西。

I have joined the code and twiml from twilio.我已经从 twilio 加入了代码和 twiml。

def call_m(request):
  account_sid = os.environ['TWILIO_ACCOUNT_SID']
  auth_token = os.environ['TWILIO_AUTH_TOKEN'] 
  client = Client(account_sid, auth_token)
  call = client.calls.create(
                        url='twiml_url',
                        to='+91985XXXXXXX',
                        from_='+132YYYYyYYY',
                    )
  print("sid ",call.sid)

return render(request, 'calls/incall.html')

Here's my twiml.这是我的 twiml。

<?xml version="1.0" encoding="UTF-8"?>
<Response> 
</Response>

if i changed My twiml to this如果我把我的 twiml 改成这个

<Response>
   <Dial>+9198xxxxxxxx</Dial>
</Response>

then after accepting call from "To" number, It say's number is busy please call later.然后在接听“To”号码的电话后,它说该号码正忙,请稍后再拨。

I think you may have some misconceptions about how Twilio works when making calls.我想您可能对 Twilio 在拨打电话时的工作方式有一些误解。

When you generate a call with Twilio using the REST API that creates a call leg between the to number and Twilio (not between your laptop and the phone). When you generate a call with Twilio using the REST API that creates a call leg between the to number and Twilio (not between your laptop and the phone).

When that call is answered on the end of the to number, Twilio then makes an HTTP request to the url that you passed to the API. When that call is answered on the end of the to number, Twilio then makes an HTTP request to the url that you passed to the API. That URL should respond with TwiML to tell Twilio what to do with the call next. URL 应该用TwiML响应,告诉 Twilio 接下来如何处理调用。

Now, when your application responded with an empty TwiML response ( <Response></Response> ) that tells Twilio that there is nothing left to do in this call, so Twilio hangs up.现在,当您的应用程序以一个空的 TwiML 响应 ( <Response></Response> ) 进行响应时,该响应告诉 Twilio 在此调用中没有什么可做的,因此 Twilio 挂断了。

When your application responded with a <Dial> , like this:当您的应用程序以<Dial>响应时,如下所示:

<Response>
   <Dial>+9198xxxxxxxx</Dial>
</Response>

my guess is that the number in the dial was the same number that you used in the to parameter to make the call.我的猜测是拨号中的号码与您在to参数中用于拨打电话的号码相同。 In this case, Twilio placed a call to your number in response to the REST API request and then placed another call to your number as directed by the TwiML <Dial> and that second call found that your number was busy because you are already on the line with Twilio.在这种情况下,Twilio 为响应 REST API 请求向您的号码拨打了电话,然后按照<Dial>的指示再次拨打了您的号码,并且您的号码已占线,因为您已在第二次呼叫符合 Twilio。

If you used a different number in the <Dial> then Twilio would place a call to that number and when they answered the phone you would be connected to them.如果您在<Dial>中使用了不同的号码,则 Twilio 将拨打该号码,当他们接听电话时,您将连接到他们。

If you want to connect two callers with their own phones, then using <Dial> like this is the way forward.如果您想用自己的电话连接两个呼叫者,那么像这样使用<Dial>是前进的方向。

If you want to place a call from your laptop to another device, then you will need a bit more than just the REST API.如果您想从笔记本电脑向另一台设备拨打电话,那么您需要的不仅仅是 REST API。 In this instance you need to build an application using the Twilio Voice SDK which allows you to make calls from a web browser or iOS or Android application. In this instance you need to build an application using the Twilio Voice SDK which allows you to make calls from a web browser or iOS or Android application. If this is of interest to you then I recommend you check out the getting started guide for the JavaScript voice SDK .如果您对此感兴趣,那么我建议您查看JavaScript 语音 SDK 的入门指南

The call needs TWiML to stay active, so that explains why it ends the call when you are returning an empty TwiML reponse.调用需要 TWiML 保持活动状态,这解释了为什么当您返回空的 TwiML 响应时它会结束调用。 You must keep feeding it TwiML to keep the call up.您必须继续喂它 TwiML 以保持调用。

Specific to calling the number, there could be an issue dialing that number that Twilio support could investigate, if geographic permissions allow international calls to that destination.具体到拨打该号码时,如果地理权限允许拨打该目的地的国际电话,则拨打 Twilio 支持可以调查的号码可能会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM