json - 语音通话立即结束,nexmo 在一秒钟内挂断
问题描述
我在 Nexmo 仪表板中创建了一个带有事件 url 和答案 url 的应用程序。我运行从Nexmo 的 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)
调用答案网址时我会做什么:
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 倾销”您的 NCCO,
您将其创建ncco
为python dict,然后将其转换为json字符串, d = json.dumps(ncco)
然后调用JsonResponse
它,尝试将ncco
对象传递给JsonResponse
return JsonResponse(ncco, status=200, safe=False)
推荐阅读
- c# - 如何使用 ItextSharp 在图像周围绘制圆圈
- shell - 在 shell 中设置一个名称以休眠进程
- sitecore - Sitecore 9 发布项目错误发布对话框未找到错误
- php - ajax评论未重新提交
- javascript - Selenium-Webdriver, driver.findElement(...).getLocation 不是函数,为什么?
- reactjs - 对反应中的循环感到困惑
- java - Axon 服务器命令不包含路由键
- ibm-integration-bus - Node 中的默认集成服务器未显示 IIB 10?
- android - 如何在方法void中初始化最终变量布尔数组
- javascript - 从 html 创建的图像未正确放置在画布上