def confirm_fundsTransfer(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(
        lambda: requestBody['queryResult']['languageCode'])

    parameters = validate.try_ex(
        lambda: requestBody['queryResult']['parameters'])
    confirm = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['confirm'])
    message = event = account = amount = recipient = None

    outputContexts = validate.try_ex(
        lambda: requestBody['queryResult']['outputContexts'])
    currContext = session + "/contexts/confirm_fundstransfercontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            account = validate.try_ex(lambda: context['parameters']['account'])
            amount = validate.try_ex(lambda: context['parameters']['amount'])
            recipient = validate.try_ex(
                lambda: context['parameters']['recipient'])
            if confirm is None:
                confirm = validate.try_ex(
                    lambda: context['parameters']['confirm'])

    parameters['event'] = event
    parameters['confirm'] = confirm
    parameters['account'] = account
    parameters['amount'] = amount
    parameters['recipient'] = recipient

    if confirm is not None and confirm != "":
        if confirm == 'yes':
            #Make call to fulfillment function here
            remainingBalance = helpers.deductAccountBalance(
                helpers.hardcodedAccountBalance, account,
                amount)  #Requires backend API call in actual code
            message = eventsData[event]['languages'][languageCode][0].format(
                amount['amount'], recipient, account, remainingBalance)
            return helpers.createResponseBody(message, None, None)
        else:
            message = eventsData[event]['languages'][languageCode][1]
            return helpers.createResponseBody(message, None, None)
    else:
        parameters['event'] = 'FUNDS_TRANSFER_CONFIRM_TRANSFER'
        followUpEvent = {
            'name': parameters['event'],
            'languageCode': languageCode,
            'parameters': parameters
        }
        contextName = session + "/contexts/confirm_fundstransfercontext"
        outputContexts = [{
            "name": contextName,
            "lifespanCount": 1,
            "parameters": parameters
        }]
        message = eventsData[event]['languages'][languageCode][2].format(
            amount['amount'], recipient, account)
        return helpers.createResponseBody(message, outputContexts,
                                          followUpEvent)
def getBalance(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    account = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['account'])
    languageCode = validate.try_ex(
        lambda: requestBody['queryResult']['languageCode'])
    parameters = {'account': account}
    outputContexts = message = followUpEvent = event = error = None

    # Check if getBalance has previously been called, with user supplying an invalid account
    outputContexts = validate.try_ex(
        lambda: requestBody['queryResult']['outputContexts'])
    if outputContexts is not None:
        currContext = session + "/contexts/getbalancecontext"
        for context in outputContexts:
            if context['name'] == currContext:
                error = validate.try_ex(lambda: context['parameters']['error'])

    if account is not None and account != "":
        if validate.isvalidAccount(account):
            remainingBalance = validate.try_ex(
                lambda: helpers.hardcodedAccountBalance[account])
            message = eventsData['GET_BALANCE']['languages'][languageCode][
                0].format(account, remainingBalance)
            return helpers.createResponseBody(message, outputContexts,
                                              followUpEvent)
        else:  #Store error flag in parameters so that when getBalance is called again the error message is shown
            parameters['error'] = True
            parameters['event'] = 'GET_BALANCE'
            contextName = session + '/contexts/getbalancecontext'
    else:
        contextName = session + '/contexts/getbalancecontext'
        parameters['event'] = 'GET_BALANCE'
        if error == True:  #Show the error message if error has previously been set
            message = eventsData['GET_BALANCE']['languages'][languageCode][1]
        else:  # Else simply ask user for account type with no error msg
            message = eventsData['GET_BALANCE']['languages'][languageCode][2]

    outputContexts = [{
        "name": contextName,
        "lifespanCount": 1,
        "parameters": parameters
    }]
    followUpEvent = {
        'name': parameters['event'],
        'languageCode': languageCode,
        'parameters': parameters
    }
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 3
0
def Confirm_booking(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(lambda: requestBody['queryResult']['parameters'])
    confirm = validate.try_ex(lambda: requestBody['queryResult']['parameters']['confirm'])
    message = event = arrival = departure = adult = child = None
    
    outputContexts = validate.try_ex(lambda: requestBody['queryResult']['outputContexts'])
    currContext = session+"/contexts/Confirm_bookingcontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            arrival = validate.try_ex(lambda: context['parameters']['arrival'])
            departure = validate.try_ex(lambda: context['parameters']['departure'])
            adult = validate.try_ex(lambda: context['parameters']['adult'])
            child = validate.try_ex(lambda: context['parameters']['child'])
            if confirm is None:
                confirm = validate.try_ex(lambda: context['parameters']['confirm'])

    parameters['event'] = event
    parameters['confirm'] = confirm
    parameters['arrival'] = arrival
    parameters['departure'] = departure
    parameters['adult'] = adult
    parameters['child'] = child

    if confirm is not None and confirm != "":
        if confirm == 'yes':
            #remainingBalance = helpers.deductAccountBalance(helpers.hardcodedAccountBalance, account, amount) #Requires backend API call in actual code
            message = eventsData[event]['languages'][languageCode][0].format(arrival, departure, adult, child)
            return helpers.createResponseBody(message, None, None)
        else:#Either user has said no, or possibly some error in their response. TODO: Split up messages for both cases
            message = eventsData[event]['languages'][languageCode][1]
            return helpers.createResponseBody(message, None, None)
    else:#Ask for confirmation again
        parameters['event'] = 'BOOKING_CONFIRM'
        followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
        contextName = session+"/contexts/Confirm_bookingcontext"
        outputContexts = [
                {
                    "name": contextName,
                    "lifespanCount": 1,
                    "parameters": parameters
                }]
        message = eventsData[event]['languages'][languageCode][2].format(arrival, departure, adult, child)
        return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 4
0
def confirm_billPayment(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(lambda: requestBody['queryResult']['parameters'])
    confirm = validate.try_ex(lambda: requestBody['queryResult']['parameters']['confirm'])
    message = event = account = amount = biller = None
    
    outputContexts = validate.try_ex(lambda: requestBody['queryResult']['outputContexts'])
    currContext = session+"/contexts/confirm_billpaymentcontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            account = validate.try_ex(lambda: context['parameters']['account'])
            amount = validate.try_ex(lambda: context['parameters']['amount'])
            biller = validate.try_ex(lambda: context['parameters']['biller'])
            if confirm is None:
                confirm = validate.try_ex(lambda: context['parameters']['confirm'])

    parameters['event'] = event
    parameters['confirm'] = confirm
    parameters['account'] = account
    parameters['amount'] = amount
    parameters['biller'] = biller

    if confirm is not None and confirm != "":
        if confirm == 'yes':
            remainingBalance = helpers.deductAccountBalance(helpers.hardcodedAccountBalance, account, amount) #Requires backend API call in actual code
            message = eventsData[event]['languages'][languageCode][0].format(amount['amount'], biller, account, remainingBalance)
            return helpers.createResponseBody(message, None, None)
        else:#Either user has said no, or possibly some error in their response. TODO: Split up messages for both cases
            message = eventsData[event]['languages'][languageCode][1]
            return helpers.createResponseBody(message, None, None)
    else:#Ask for confirmation again
        parameters['event'] = 'BILL_PAYMENT_CONFIRM_TRANSFER'
        followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
        contextName = session+"/contexts/confirm_billpaymentcontext"
        outputContexts = [
                {
                    "name": contextName,
                    "lifespanCount": 1,
                    "parameters": parameters
                }]
        message = eventsData[event]['languages'][languageCode][2].format(amount['amount'], biller, account)
        return helpers.createResponseBody(message, outputContexts, followUpEvent)
def getAmount_fundsTransfer(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(
        lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(
        lambda: requestBody['queryResult']['parameters'])
    amount = validate.try_ex(lambda: parameters['amount'])
    event = error = account = recipient = message = followUpEvent = None

    outputContexts = validate.try_ex(
        lambda: requestBody['queryResult']['outputContexts'])
    currContext = session + "/contexts/getamount_fundstransfercontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            error = validate.try_ex(lambda: context['parameters']['error'])
            recipient = validate.try_ex(
                lambda: context['parameters']['recipient'])
            account = validate.try_ex(lambda: context['parameters']['account'])
    parameters['event'] = event
    parameters['recipient'] = recipient
    parameters['account'] = account

    if amount is not None and amount != "" and account is not None and account != "":
        if validate.isvalidAmount(helpers.hardcodedAccountBalance, amount,
                                  account):
            parameters['event'] = eventsData[event]['nextEvent']
            contextName = session + "/contexts/" + eventsData[event][
                'nextContext']
        else:
            parameters['error'] = True
            contextName = session + "/contexts/getamount_fundstransfercontext"
    else:  #Unfilled
        contextName = session + "/contexts/getamount_fundstransfercontext"
        if (error == True):
            message = eventsData[event]['languages'][languageCode][0].format(
                parameters['account'])
        else:
            message = eventsData[event]['languages'][languageCode][1]

    followUpEvent = {
        'name': parameters['event'],
        'languageCode': languageCode,
        'parameters': parameters
    }
    outputContexts = [{
        "name": contextName,
        "lifespanCount": 1,
        "parameters": parameters
    }]
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
def getRecipient_fundsTransfer(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(
        lambda: requestBody['queryResult']['languageCode'])
    recipient = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['recipient'])
    error = event = message = followUpEvent = None

    # Read from the getrecipient_fundstransfercontext that has been passed in as part of the input http request
    outputContexts = validate.try_ex(
        lambda: requestBody['queryResult']['outputContexts'])
    currContext = session + "/contexts/getrecipient_fundstransfercontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            error = validate.try_ex(lambda: context['parameters']['error'])
    parameters = {'recipient': recipient, 'event': event}

    if recipient is not None and recipient != "":
        if validate.isvalidRecipient(recipient):
            parameters['event'] = eventsData[event]['nextEvent']
            contextName = session + "/contexts/" + eventsData[event][
                'nextContext']
        else:
            parameters[
                'error'] = True  #Error message will be shown when getRecipient_fundsTransfer() is called immediately again
            contextName = session + "/contexts/getrecipient_fundstransfercontext"
    else:  #Unfilled
        contextName = session + "/contexts/getrecipient_fundstransfercontext"
        if (
                error == True
        ):  # Flag indicates that user has previously supplied an invalid recipient. Show error message
            message = eventsData[event]['languages'][languageCode][0]
        else:
            message = eventsData[event]['languages'][languageCode][1]

    outputContexts = [{
        "name": contextName,
        "lifespanCount": 1,
        "parameters": parameters
    }]
    followUpEvent = {
        'name': parameters['event'],
        'languageCode': languageCode,
        'parameters': parameters
    }
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
def transferFunds(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(
        lambda: requestBody['queryResult']['languageCode'])
    account = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['account'])
    amount = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['amount'])
    recipient = validate.try_ex(
        lambda: requestBody['queryResult']['parameters']['recipient'])

    parameters = {'account': account, 'amount': amount, 'recipient': recipient}

    outputContexts = message = followUpEvent = None

    # Checks the validity of each slot sequentially, calling the appropriate event if any slot is invalid/incomplete, or if all slots have been filled
    if recipient is not None and recipient != "" and validate.isvalidRecipient(
            recipient):
        if account is not None and account != "" and validate.isvalidAccount(
                account):
            if amount is not None and amount != "" and validate.isvalidAmount(
                    helpers.hardcodedAccountBalance, amount, account):
                parameters['event'] = 'FUNDS_TRANSFER_CONFIRM_TRANSFER'
                contextName = session + "/contexts/confirm_fundstransfercontext"
            else:
                parameters['event'] = 'FUNDS_TRANSFER_GET_AMOUNT'
                contextName = session + "/contexts/getamount_fundstransfercontext"
        else:
            parameters['event'] = 'FUNDS_TRANSFER_GET_ACCOUNT'
            contextName = session + "/contexts/getaccount_fundstransfercontext"
    else:  #default next intent if no parameters are provided
        parameters['event'] = 'FUNDS_TRANSFER_GET_RECIPIENT'
        contextName = session + "/contexts/getrecipient_fundstransfercontext"

    # Store parameters like account, amount, etc. if supplied and send to the subsequent intent
    outputContexts = [{
        "name": contextName,
        "lifespanCount": 1,
        "parameters": parameters
    }]
    followUpEvent = {
        'name': parameters['event'],
        'languageCode': languageCode,
        'parameters': parameters
    }
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 8
0
def bookingcom(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    arrival = validate.try_ex(lambda: requestBody['queryResult']['parameters']['arrival'])
    departure = validate.try_ex(lambda: requestBody['queryResult']['parameters']['departure'])
    adult = validate.try_ex(lambda: requestBody['queryResult']['parameters']['adult'])
    child = validate.try_ex(lambda: requestBody['queryResult']['parameters']['child'])


    parameters = {'arrival' : arrival, 'departure' : departure, 'adult' : adult, 'child' : child}
    
    outputContexts = message = followUpEvent = None
    
    # Checks the validity of each slot sequentially, calling the appropriate event if any slot is invalid/incomplete, or if all slots have been filled
    if arrival is not None and arrival != "" and validate.isvalidArrival(arrival):
        if departure is not None and departure != "" and validate.isvalidDeparture(departure):
            if adult is not None and adult != "" and validate.isvalidAdult(adult):
                 if child is not None and child != "" and validate.isvalidchild(child):
                     parameters['event'] = 'BOOKING_CONFIRM'
                     contextName = session+"/contexts/Confirm_bookingcontext"
                 else:
                    parameters['event'] = 'BOOKING_GET_CHILD'
                    contextName = session+"/contexts/getchild_bookingcontext"
                    
            else:
                parameters['event'] = 'BOOKING_GET_ADULT'
                contextName = session+"/contexts/getadult_bookingcontext"
        else:
            parameters['event'] = 'BOOKING_GET_DEPARTURE'
            contextName = session+"/contexts/getdeparture_bookingcontext"
    else: #default next intent if no parameters are provided
        parameters['event'] = 'BOOKING_GET_ARRIVAL'
        contextName = session+"/contexts/getarrival_bookingcontext"

    #save entered slots for next intent
    outputContexts = [
        {
            "name": contextName,
            "lifespanCount": 1,
            "parameters": parameters
        }]
    followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 9
0
def getdeparture_booking(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(lambda: requestBody['queryResult']['parameters'])
    departure = validate.try_ex(lambda: parameters['departure'])
    error = event = arrival = message = followUpEvent = None
    
    outputContexts = validate.try_ex(lambda: requestBody['queryResult']['outputContexts'])
    currContext = session+"/contexts/getdeparture_bookingcontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            error = validate.try_ex(lambda: context['parameters']['error'])
            arrival = validate.try_ex(lambda: context['parameters']['arrival'])
    parameters['event'] = event
    parameters['arrival'] = arrival

    if departure is not None and departure != "":
        if validate.isvalidDeparture(departure):
            parameters['event'] = eventsData[event]['nextEvent']
            contextName = session + "/contexts/" + eventsData[event]['nextContext']
        else:
            parameters['error'] = True
            contextName = session + "/contexts/getdeparture_bookingcontext"
    else: #Unfilled
        contextName = session+"/contexts/getdeparture_bookingcontext"
        if(error == True):
            message = eventsData[event]['languages'][languageCode][0]
        else:
            message = eventsData[event]['languages'][languageCode][1]

    outputContexts = [
            {
                "name": contextName,
                "lifespanCount": 1,
                "parameters": parameters
            }]
    followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 10
0
def getAccount_billPayment(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(lambda: requestBody['queryResult']['parameters'])
    account = validate.try_ex(lambda: parameters['account'])
    error = event = biller = message = followUpEvent = None
    
    outputContexts = validate.try_ex(lambda: requestBody['queryResult']['outputContexts'])
    currContext = session+"/contexts/getaccount_billpaymentcontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            error = validate.try_ex(lambda: context['parameters']['error'])
            biller = validate.try_ex(lambda: context['parameters']['biller'])
    parameters['event'] = event
    parameters['biller'] = biller

    if account is not None and account != "":
        if validate.isvalidAccount(account):
            parameters['event'] = eventsData[event]['nextEvent']
            contextName = session + "/contexts/" + eventsData[event]['nextContext']
        else:
            parameters['error'] = True
            contextName = session + "/contexts/getaccount_billpaymentcontext"
    else: #Unfilled
        contextName = session+"/contexts/getaccount_billpaymentcontext"
        if(error == True):
            message = eventsData[event]['languages'][languageCode][0]
        else:
            message = eventsData[event]['languages'][languageCode][1]

    outputContexts = [
            {
                "name": contextName,
                "lifespanCount": 1,
                "parameters": parameters
            }]
    followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 11
0
def payBill(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    account = validate.try_ex(lambda: requestBody['queryResult']['parameters']['account'])
    amount = validate.try_ex(lambda: requestBody['queryResult']['parameters']['amount'])
    biller = validate.try_ex(lambda: requestBody['queryResult']['parameters']['biller'])

    parameters = {'account' : account, 'amount' : amount, 'biller' : biller}
    
    outputContexts = message = followUpEvent = None
    
    # Checks the validity of each slot sequentially, calling the appropriate event if any slot is invalid/incomplete, or if all slots have been filled
    if biller is not None and biller != "" and validate.isvalidBiller(biller):
        if account is not None and account != "" and validate.isvalidAccount(account):
            if amount is not None and amount != "" and validate.isvalidAmount(helpers.hardcodedAccountBalance, amount, account):
                parameters['event'] = 'BILL_PAYMENT_CONFIRM_TRANSFER'
                contextName = session+"/contexts/confirm_billpaymentcontext"
            else:
                parameters['event'] = 'BILL_PAYMENT_GET_AMOUNT'
                contextName = session+"/contexts/getamount_billpaymentcontext"
        else:
            parameters['event'] = 'BILL_PAYMENT_GET_ACCOUNT'
            contextName = session+"/contexts/getaccount_billpaymentcontext"
    else: #default next intent if no parameters are provided
        parameters['event'] = 'BILL_PAYMENT_GET_BILLER'
        contextName = session+"/contexts/getbiller_billpaymentcontext"

    #save entered slots for next intent
    outputContexts = [
        {
            "name": contextName,
            "lifespanCount": 1,
            "parameters": parameters
        }]
    followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
    return helpers.createResponseBody(message, outputContexts, followUpEvent)
Esempio n. 12
0
            contextName = session + "/contexts/getchild_bookingcontext"
    else: #Unfilled
        contextName = session + "/contexts/getchild_bookingcontext"
        if(error == True):
            message = eventsData[event]['languages'][languageCode][0].format(parameters['account'])
        else:
            message = eventsData[event]['languages'][languageCode][1]

    followUpEvent = {'name' : parameters['event'], 'languageCode' : languageCode, 'parameters' : parameters}
    outputContexts = [
            {
                "name": contextName,
                "lifespanCount": 1,
                "parameters": parameters
            }]
    return helpers.createResponseBody(message, outputContexts, followUpEvent)


def getadult_booking(requestBody, eventsData):
    session = validate.try_ex(lambda: requestBody['session'])
    languageCode = validate.try_ex(lambda: requestBody['queryResult']['languageCode'])
    parameters = validate.try_ex(lambda: requestBody['queryResult']['parameters'])
    adult = validate.try_ex(lambda: parameters['adult'])
    event = error = departure = arrival = message = followUpEvent = None
     
    outputContexts = validate.try_ex(lambda: requestBody['queryResult']['outputContexts'])
    currContext = session+"/contexts/getadult_bookingcontext"
    for context in outputContexts:
        if context['name'] == currContext:
            event = validate.try_ex(lambda: context['parameters']['event'])
            error = validate.try_ex(lambda: context['parameters']['error'])