python - 为什么当我通过浏览器调用时 twilio 调用转移不起作用,但在使用完全相同的请求 url 调用 twilio 号码时却工作正常

标签 python django twilio pythonanywhere

我有一个电话号码,其请求网址有效(说出文本,然后转接调用),但随后我有一个应用程序(浏览器出站调用)转到相同的请求网址,并且只有文本转语音有效,并且调用转移出现错误并挂断。为什么它不像号码的请求网址那样转发?我检查了一下,功能 token 渲染得很好...

View .py

def once_connected_view(request):
    response = twiml.Response()
    response.say("Please wait while we connect your call.", voice='alice')
    response.dial("xxx-xx-xxx-xxxx")
    return HttpResponse(str(response))

def home_view(request):
    capability = TwilioCapability(account_sid, auth_token)
    capability.allow_client_outgoing(application_sid)
    token = capability.generate()
    query_set = Model.objects.all()
    return render(request, "base.html", {"query_set":query_set, "token":token})

url.py

urlpatterns = [
url(r'^$', views.home_view, name="home"),
    url(r'^once_connected/', views.once_connected_view, name="once_connected"),
]

号码请求网址

http://xx.xx.com/once_connected/ http 获取

应用程序请求网址

http://xx.xx.com/once_connected/ http 获取

主站点网址

https://xx.xx.com/

base.html

<!doctype html>
<head>
<script type="text/javascript" src="https://static.twilio.com/libs/twiliojs/1.2/twilio.min.js"></script>
<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=320, height=device-height, target-densitydpi=medium-dpi" />
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'cars/responsive.css' %}">
</head>
<body>
<div class="container" id="wrapper">
  <div class="video-background-container">
    <video preload="auto" autoplay="" loop="" muted="" class="video-background hidden-xs hidden-sm">
      <source type="video/mp4" src="omitted">
    </video>
  </div>
  <div class="grid-overlay text-center">
    <nav class="navbar navbar-default navbar-fixed-top" style="background:none;">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" id="logo" href="#">Brand Name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="replace-call"><a href="#" data-toggle="modal" data-target="#myModal">Contact Us</a></li>
          </ul>
        </div>
      </div>
    </nav>

    ...
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript">

    /* Create the Client with a Capability Token */
    Twilio.Device.setup("{{ token }}");

    /* Let us know when the client is ready. */
    Twilio.Device.ready(function (device) {
        $(".replace-call").html("<a href='#' onclick='call()'>Call From Browser</a>");
    });

    /* Report any errors on the screen */
    Twilio.Device.error(function (error) {
        $(".replace-call").html('<a href="#" data-toggle="modal" data-target="#myModal">Contact Us</a>');
    });

    Twilio.Device.connect(function (conn) {
        $(".replace-call").html("<a href='#' onclick='hangup()'>End Call</a>");
    });

    /* Connect to Twilio when we call this function. */
    function call() {
        Twilio.Device.connect();
    }
    function hangup() {
        Twilio.Device.disconnectAll();
        $(".replace-call").html('<a href="#" data-toggle="modal" data-target="#myModal">Contact Us</a>');
    }
</script>
</body>
</html>

我托管在 pythonanywhere 上。

最佳答案

经过轻微的脱发后,我通过向拨号动词添加 callerID 属性使其发挥作用。

def once_connected_view(request):
    response = twiml.Response()
    response.say("Please wait while we connect your call.", voice='alice')
    response.dial("xxx-xx-xxx-xxxx", callerId="+xxxxxxxxxx") #  here
    return HttpResponse(str(response))

关于python - 为什么当我通过浏览器调用时 twilio 调用转移不起作用,但在使用完全相同的请求 url 调用 twilio 号码时却工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34908401/

相关文章:

python - 如何绘制更大的边界框和仅裁剪边界框文本 Python Opencv

python - 无法重新加载位于另一个文件夹中但也在 sys.path 中的模块

java - 成功后如何从 Parse Cloud 将验证码发送回我的应用程序?

ios - 使用 Twilio 无法通过麦克风听到声音

python - API 自动化的并行执行

python - 从 scipy 稀疏矩阵中提取非主对角线?

mysql - django mod_wsgi、nginx MySQL 或 Postgres

python - 使用 django 进行 Selenium 测试给出 'NoneType' 对象没有属性 'path'

python - 如何使用 Hyde 生成新内容?

java - Twilio:如何发送正文消息上的链接