manniru
6/29/2017 - 1:34 PM

api-ai-fulfillment.py

def apiai_callback(request):
    """
    api.ai command router, maps actions to desired methods to handle fulfillments.
    :param request:
    :return HTTPResponse from mapped method:
    """
    try:
        body = request.body
        body = json.loads(body)

        # pass the body into a method to parse information from request
        if body['result']['action'] == 'A':
            return methodA(body)
        elif body['result']['action'] == 'B':
            return methodB(body)
        elif body['result']['action'] == 'C':
            return methodC(body)
        else:
            return HttpResponse('<html><body>"Command not supported yet."</body></html>')
    except Exception as e:
        print e
        return e