Building a USSD menu with Django
Am building a USSD web app with Django and am using the API https://documenter.getpostman.com/view/7705958/UyrEhaLQ#intro I am having a problem sending response and getting the menu displaying on upon dialing the USSD code.
@csrf_exempt
def ussd(request):
if request.method == 'GET':
html = "<html><body>Nothing here baby!</body></html>"
return HttpResponse(html)
elif request.method == 'POST':
url = "https://99c9-102-176-94-213.ngrok.io/ussd"
code_id = request.POST.get("USERID")
serviceCode = request.POST.get("MSISDN")
type = request.POST.get("MSGTYPE")
session_id = request.POST.get("SESSIONID")
text = request.POST.get("USERDATA")
MSG = ""
if text == "":
MSG = "Welcome To Votedigital"
elif text == "1":
MSG = "Test Two"
payload ={
"USERID": code_id,
"MSISDN": serviceCode,
"MSGTYPE": type,
"USERDATA": text,
"SESSIONID": session_id,
"MSG": MSG,
}
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
print(code_id)
print(response.text)
return HttpResponse(response)
When i check my post summary, the elements are empty
{
"USERID": null,
"MSISDN": null,
"MSGTYPE": null,
"USERDATA": null,
"SESSIONID": null,
"MSG": ""
}