【问题标题】:voice call ends right away, nexmo hangs up within a second语音通话立即结束,nexmo 在一秒钟内挂断
【发布时间】:2019-06-16 06:05:40
【问题描述】:

我在 Nexmo 仪表板中创建了一个应用程序,其中包含事件 url 和答案 url。我运行从Nexmo´s GitHub 获得的以下代码:

client = nexmo.Client(key=api_key, secret=api_secret, application_id=application_key, private_key=private_key)

response = client.create_call({
  'to': [{'type': 'phone', 'number': 'call_to_number'}],
  'from': {'type': 'phone', 'number': 'call_from_number'},
  'answer_url': ['http://my_event_url']
})

电话号码被拨打,但 nexmo 立即挂断(在一秒钟内没有说话)。

在我的服务器上,我看到 Nexmo 调用了答案 url(带有 ncco)

当回答 url 被调用时我会做什么:

import nexmo
import json
from django.http import JsonResponse

@csrf_exempt
def answer(request):

    ncco = [{
      "action": "talk",
      "voiceName": "Amy",
      "text": "Thank you for calling Nexmo. Please leave your message after the tone."
    }]

    d = json.dumps(ncco)
    j = is_json(d)
    if j:
        MyObject.objects.create(message="valid")
    else:
        MyObject.objects.create(message=user_ip + "json error")

    return JsonResponse(d, status=200, safe=False)


def is_json(myjson):
    try:
        json_object = json.loads(myjson)
    except ValueError:
        return False
    return True

这就是我调用 event_url 时所做的:

@csrf_exempt
def event(request):

    d = json.dumps(request.POST)
    DataReceived.objects.create(answer=d)

    data = {"ok": True}

    return JsonResponse(data, status=200)

Nexmo 调用了 5 次事件 URL,但字典始终为空。

【问题讨论】:

    标签: json django python-3.x nexmo


    【解决方案1】:

    `我认为您可能正在“双重 JSON 转储”您的 NCCO,

    您将ncco 创建为python dict,然后将其转换为带有d = json.dumps(ncco) 的json 字符串,然后您在其上调用JsonResponse,尝试将ncco 对象传递给JsonResponse

    return JsonResponse(ncco, status=200, safe=False)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多