语音通话马上结束,nexmo秒挂断
voice call ends right away, nexmo hangs up within a second
我在 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)
事件 url 被 Nexmo 调用了 5 次,但字典始终为空。
`我想你可能是 "double JSON dumping" 你的 NCCO,
您将 ncco
创建为 python 字典,然后使用 d = json.dumps(ncco)
将其转换为 json 字符串,然后调用 JsonResponse
它,尝试将 ncco
对象传递给 JsonResponse
return JsonResponse(ncco, status=200, safe=False)
我在 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)
事件 url 被 Nexmo 调用了 5 次,但字典始终为空。
`我想你可能是 "double JSON dumping" 你的 NCCO,
您将 ncco
创建为 python 字典,然后使用 d = json.dumps(ncco)
将其转换为 json 字符串,然后调用 JsonResponse
它,尝试将 ncco
对象传递给 JsonResponse
return JsonResponse(ncco, status=200, safe=False)