【发布时间】: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