Esempio n. 1
0
def kra():
    logging.info("inside KRA")

    dbconnect = db.connect_to_cloudsql()

    if request.method == 'POST':

        logging.info("inside POST")
        req = request.get_json(silent=True, force=True)

        logging.info(type(req))
        logging.info(req)

        parameters = req['result']['parameters']
        action = req['result']['action']

        webhook_res = actions.actions_handler[action](parameters, dbconnect)

        dbconnect.close()

        req = {
            "speech": webhook_res["speech"],
            "displayText": webhook_res["speech"],
            "data": {
                "speech": webhook_res["speech"]
            },
            "contextOut": webhook_res["contextOut"]
        }

        req = json.dumps(req, indent=4)
        r = make_response(req)
        r.headers['Content-Type'] = 'application/json'
        return r
Esempio n. 2
0
def main_app():

    logging.info("attempt to connect!!")

    connection = db.connect_to_cloudsql()

    logging.info("connection successful")

    db.checkUser("Mayur", "Jain", '005892', connection)
    return "hello"
Esempio n. 3
0
def main_page():

    logging.info("inside POST")
    req = request.get_json(silent=True, force=True)

    logging.info(type(req))
    logging.info(req)

    parameters = req['result']['parameters']
    action = req['result']['action']

    # Reading the access token now
    access_token = req['originalRequest']['data']['user']['access_token']
    logging.info(access_token)

    #database connection
    dbconnection = db.connect_to_cloudsql()

    profile = requests.get(
        "https://graph.facebook.com/me?fields=id,name,email,work,gender,about,birthday,education,hometown,likes,location,relationship_status,family&access_token="
        + access_token)
    logging.info(profile.json())

    profile = profile.json()

    fbid = profile["id"]

    #fbid = persona.updateProfile(access_token,dbconnection)

    logging.info("fbid : " + str(fbid))

    speechTosend = actions.handler[action](parameters, fbid, dbconnection)

    req = {
        "speech": speechTosend["response"],
        "displayText": speechTosend["response"],
        "data": {
            "speech": speechTosend["response"]
        },
        "contextOut": speechTosend["contextOut"]
    }

    #close connection
    dbconnection.close()

    req = json.dumps(req, indent=4)
    r = make_response(req)
    r.headers['Content-Type'] = 'application/json'
    return r
Esempio n. 4
0
def kra():
    logging.info("inside KRA")

    dbconnect = db.connect_to_cloudsql()

    if request.method == 'POST':

        logging.info("inside POST")
        req = request.get_json(silent=True, force=True)

        logging.info(type(req))
        logging.info(req)

        parameters = req['result']['parameters']
        action = req['result']['action']

        if action == 'getname':  #case for authentication

            logging.info("inside getname")
            if kras.checkUser(parameters['firstname'].title(),
                              parameters['lastname'].title(),
                              '{0:06}'.format(int(parameters['employeeId'])),
                              dbconnect):
                logging.info("returning True")
                speech = "Welcome " + parameters[
                    'firstname'] + " " + parameters[
                        'lastname'] + " <br>How may I help you?"
            else:
                logging.info("returning False")

                speech = "The Employee ID does not match with the name entered. <BR><BR> Please enter the correct Employee ID & your full name"

        elif action == 'showkra':  #case to show kra
            logging.info("inside showkra")

            if parameters['whose'].lower(
            ) == 'me' or parameters['whose'].lower(
            ) == 'my' or parameters['whose'].lower() == 'myself':
                speech = kras.getKras(parameters['employeeId'], dbconnect)

            elif parameters['whose'].lower() == 'subordinate' or parameters[
                    'whose'].lower() == 'subordinates':
                speech = kras.getSubordinates(parameters['employeeId'],
                                              dbconnect)
            else:
                speech = "I didnt get that.."
        elif action == 'showkra_of_subordinate':
            speech = kras.getKras(parameters['employeeId'], dbconnect,
                                  parameters['subordinateId'])

        elif action == "get_kra_title":

            speech = kras.getKraDescription(parameters['KRAID'],
                                            parameters['choice'].lower(),
                                            parameters['whose'].lower(),
                                            dbconnect)

        elif action == "update_yes_kra":
            speech = kras.updateKRA(parameters['KRAID'],
                                    parameters['choice'].lower(),
                                    parameters['newValue'], dbconnect)

        elif action == "show_competencies":
            logging.info("inside show_competencies")

            if parameters['whose'].lower(
            ) == 'me' or parameters['whose'].lower(
            ) == 'my' or parameters['whose'].lower() == 'myself':
                speech = com.getCompetencies(parameters['employeeId'],
                                             dbconnect)

            elif parameters['whose'].lower() == 'subordinate' or parameters[
                    'whose'].lower() == 'subordinates':
                speech = com.getSubordinates(parameters['employeeId'],
                                             dbconnect)
            else:
                speech = "I didnt get that.."

        elif action == "show_competencies_of_subordinate":

            speech = com.getCompetencies(parameters['employeeId'], dbconnect,
                                         parameters['subordinateId'])

        elif action == "get_competencies_details":
            speech = com.getCompetencies_details(parameters['EmpCompetencyID'],
                                                 dbconnect)

        else:
            logging.info("returning default")
            speech = "Hi, how may I help you"

        dbconnect.close()

        req = {
            "speech": speech,
            "displayText": speech,
            "data": {
                "speech": speech
            },
        }
        req = json.dumps(req, indent=4)
        r = make_response(req)
        r.headers['Content-Type'] = 'application/json'
        return r