我在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
这是调用事件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调用事件url 5次,但字典始终为空。