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))
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))
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))