예제 #1
0
def startJob(intent, session):
    session_attributes = {}
    should_end_session = False
    rawJobName = getRawJobNameFromIntent(intent)
    if rawJobName:
        print("raw job name found")
        jobName = jenkins.searchJobByName(rawJobName)
        if not jobName:
            print("didn't understand the jobname")
            speech_output = "I didn't find the job: " + rawJobName + ". Which job should I start?"
        else:
            print("all good, found the job, starting it now.")
            r = jenkins.startJob(jobName)
            eta = jenkins.getJobStatus(jobName).json()["estimatedDuration"]

            speech_output = "The job is queued for running, and will take approximately " + humantime.format(eta // 1000)
            should_end_session = True
    else:
        print("no job name given")
        return ah.build_response(session_attributes, ah.build_speechlet_directive())

    reprompt_text = "Again: Which job should I start?"

    return ah.build_response(session_attributes, ah.build_speechlet_response(
        "Start job", speech_output, reprompt_text, should_end_session))
def startTrainingHandler(intent, session, confirmed=False):
    user = session['user']['userId']  # get the userId of the current user
    try:
        session_attributes = session["attributes"]
    except:
        session_attributes = {}
    should_end_session = False
    
    dogNameFromIntent = getDogNameFromIntent(intent)
    dogFromDynamoDB = getDogFromDynamoDB(user)

    # If we don't know the dogname at all, ask again
    if not (dogNameFromIntent or dogFromDynamoDB):
        return ah.build_response(session_attributes, ah.build_speechlet_directive())
    # If it it in the DB, but not in the intent, just get it from the DB
    if not dogNameFromIntent:
        dog = dogFromDynamoDB
    # If it is in the intent, use that one and update DB if needed:
    else:
        dog = saveDogNameForUser(dogNameFromIntent, user)


    if dog[NUMBER_OF_TRAININGS] < 2 and not confirmed:
        speech_output = """<speak>Lets get started. 
                            Take your treats, motivate {0} to listen to me, 
                            by giving him a treat when he follows the commands. 
                            Ready to start?</speak>
                            """.format(dog[DOG_NAME]) 
        reprompt_text = "Are you ready to start the training?"
        session_attributes[LAST_QUESTION]=TRAINING_CONFIRMATION
        card_output = "Let's get started. Take your treats, and give {0} one everytime a command is executed correctly.".format(dog[DOG_NAME])

        return ah.build_response(session_attributes, ah.build_speechlet_response(
            "Prepare Training", speech_output, reprompt_text, should_end_session, card_output=card_output, ssml=True))

    else:
        sex="boy"

        speech_output = """<speak>{0}, come here! <break time="2.0s" />
                        <emphasis level="strong"> Good {1}!</emphasis> <break time="1.0s" />
                        {0}, sit! <break time="1.5s" />
                        Good {1}! <break time="1.0s" />
                        {0}, down! <break time="1.5s" />
                        <emphasis level="strong">Good dog! <break time="0.2s" /> Good {1}.</emphasis> <break time="0.3s" /> 
                        That concludes the training session. Should we train again?</speak>""".format(dog[DOG_NAME], sex)

        reprompt_text = "Do you want me to train your dog again?"
        
        dog[NUMBER_OF_TRAININGS] += 1
        saveDogToDynamoDB(dog, user)
        session_attributes[LAST_QUESTION]=SHOULD_START_TRAINING

        return ah.build_response(session_attributes, ah.build_speechlet_response(
            "Start training", speech_output, reprompt_text, should_end_session, card_output="We trained: Come, Sit, Down!", ssml=True))
def setDogNameHandler(intent, session):
    user = session['user']['userId']  # get the userId of the current user
    session_attributes = {LAST_QUESTION:SHOULD_START_TRAINING}
    should_end_session = False
    
    dogNameFromIntent = getDogNameFromIntent(intent)

    if not dogNameFromIntent:
        return ah.build_response(session_attributes, ah.build_speechlet_directive())
    else:
        saveDogNameForUser(dogNameFromIntent, user)

    reprompt_text = "What's your dog's name?"
    speech_output = "I'll remember that your dog is called {0}. Hi, {0}! Should I start training now?".format(dogNameFromIntent)

    return ah.build_response(session_attributes, ah.build_speechlet_response(
        "Dog name updated", speech_output, reprompt_text, should_end_session))
예제 #4
0
def getWelcomeResponse():
    session_attributes = {}
    card_title = "Welcome"
    speech_output = "Jenkins is listening. " \
                    "You can ask me to start a job, get status info or abort a job."
    
    reprompt_text = "Do you want to start a job, get status info or abort a job?"
    should_end_session = False
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))
def getDetailedHelp():
    session_attributes = {LAST_QUESTION:SHOULD_START_TRAINING}
    card_title = "Help for Dog trainer"
    speech_output = "I can make your dog do tricks, but I need your help the first few times. " \
                    "Go get some treats for the dog, and ask me to start training. "
    # If the user either does not reply to the welcome message or says something
    # that is not understood, they will be prompted again with this text.
    reprompt_text = "Do you want to start training now?"
    should_end_session = False
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))
def getWelcomeResponse():
    session_attributes = {LAST_QUESTION:SHOULD_START_TRAINING}
    card_title = "Welcome"
    speech_output = "This is your dog trainer. " \
                    "Ask me to start the training, or ask for more info."
    # If the user either does not reply to the welcome message or says something
    # that is not understood, they will be prompted again with this text.
    reprompt_text = "Can I start the training?"
    should_end_session = False
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))
예제 #7
0
def getWelcomeResponse():
    session_attributes = {}
    card_title = "Welcome"
    speech_output = "Jenkins is listening. " \
                    "You can ask me to start a job, get status info or abort a job."
    # If the user either does not reply to the welcome message or says something
    # that is not understood, they will be prompted again with this text.
    reprompt_text = "Do you want to start a job, get status info or abort a job?"
    should_end_session = False
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        card_title, speech_output, reprompt_text, should_end_session))
예제 #8
0
def getJobStatus(intent, session):
    session_attributes = {}
    should_end_session = False
    rawJobName = getRawJobNameFromIntent(intent)
    if rawJobName:
        print("raw job name found")
        jobName = jenkins.searchJobByName(rawJobName)
        if not jobName:
            print("didn't understand the jobname")
            speech_output = "I didn't find the job: " + rawJobName + ". Which job should I get the status for?"
        else:
            print("all good, found the job, getting status now.")
            r = jenkins.getJobStatus(jobName)
            speech_output = getSpeechOutputForStatus(r)
            should_end_session = True
    else:
        print("no job name given")
        return ah.build_response(session_attributes, ah.build_speechlet_directive())

    reprompt_text = "Again, which job should I get the status for?"
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        "Get status", speech_output, reprompt_text, should_end_session))
예제 #9
0
def abortJob(intent, session):
    session_attributes = {}
    should_end_session = False
    rawJobName = getRawJobNameFromIntent(intent)
    if rawJobName and intent['confirmationStatus'] != 'NONE':
        print("raw job name found")
        jobName = jenkins.searchJobByName(rawJobName)
        if not jobName:
            print("didn't understand the jobname")
            speech_output = "I didn't find the job: " + rawJobName + ". Which job should I abort?"
        else:
            print("all good, found the job, aborting it now.")
            r = jenkins.abortJob(jobName)
            speech_output = "I requested for " + jobName + " to be aborted."
            should_end_session = True
    else:
        print("no job name given")
        return ah.build_response(session_attributes, ah.build_speechlet_directive())

    reprompt_text = "Again, which job should I abort?"
    return ah.build_response(session_attributes, ah.build_speechlet_response(
        "Abort job", speech_output, reprompt_text, should_end_session))
def endSession(session):
    user = session['user']['userId'] 
    dog = getDogFromDynamoDB(user)
    if dog:
        name = dog[DOG_NAME]
    else:
        name = "you"
        
    card_title = "Session Ended"
    speech_output = """<speak>
                    Dog trainer <break time="0.1s" /> out, have a nice day!
                    </speak>"""
    card_output = "Thanks for using Dog Trainer, I hope {0} had fun!".format(name)
    should_end_session = True

    return ah.build_response({}, ah.build_speechlet_response(
        card_title, speech_output, None, should_end_session, card_output=card_output, ssml=True))
예제 #11
0
def endSession():
    card_title = "Session Ended"
    speech_output = "Jenkins out, have a nice day! "
    should_end_session = True
    return ah.build_response({}, ah.build_speechlet_response(
        card_title, speech_output, None, should_end_session))