def handle(self, handler_input):
     slots = handler_input.request_envelope.request.intent.slots
     #User-given answer
     Answer = slots["Answer"].value
     attr = handler_input.attributes_manager.persistent_attributes
     #Correct answer
     data.GLOBAL_ANSWER = attr['global_answer']
     #want to add in:
         #hints
         #limited number of attempts
     #add missing phrasing response?
     
     response_builder = handler_input.response_builder
     #if the user-given answer contains the correct answer, give the correct answer response
     if Answer.find(data.GLOBAL_ANSWER) == 0:
         response_builder.set_card(
             ui.StandardCard(
                 title = "Correct!",
                 text= data.CORRECT_ANSWER_RESPONSE + " The answer is " + data.GLOBAL_ANSWER + ".",
                 image = ui.Image(
                     small_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download",
                     large_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download"
                 )))
         return response_builder.speak(data.CORRECT_ANSWER_RESPONSE).response
     #if the user-given answer contains the incorrect answer, give the incorrect answer response
     elif Answer.find(data.GLOBAL_ANSWER) != 0:
         response_builder.set_card(
             ui.StandardCard(
                 title = "Incorrect Answer",
                 text= data.WRONG_ANSWER_RESPONSE,
                 image = ui.Image(
                     small_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download",
                     large_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download"
                 )))
         return response_builder.speak(data.WRONG_ANSWER_RESPONSE).response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In QuizAnswerHandler")
        attr = handler_input.attributes_manager.session_attributes
        response_builder = handler_input.response_builder

        item = attr["quiz_item"]
        item_attr = attr["quiz_item"]['species']
        is_ans_correct, option = util.compare_token_or_slots(
            handler_input=handler_input, value=item_attr)

        if is_ans_correct:
            speech = util.get_speechcon(correct_answer=True)
            speech += util.get_answer(item_attr, item)

            handler_input.attributes_manager.session_attributes = attr

            if option == 'miss':
                speech += data.SPEECH_PROUN.format(item_attr)
            speech += util.get_speech_description(item)
            speech += util.get_final_score(attr["quiz_score"], attr["counter"])
            speech += data.EXIT_SKILL_MESSAGE

            #response_builder.set_should_end_session(True)

            if data.USE_CARDS_FLAG:
                #speech_card=speech.replace("<say-as interpret-as='interjection'>", "")
                #speech_card=speech_card.replace("</say-as><break strength='strong'/>, ")
                response_builder.set_card(
                    ui.StandardCard(title="Final Score {}".format(
                        str(attr["quiz_score"])),
                                    text=speech))

        else:
            speech = util.get_speechcon(correct_answer=False)
            if attr['counter'] < data.MAX_QUESTIONS:

                attr["quiz_score"] -= 20
                # Update item and item_attr for next question
                item = attr["quiz_item"]
                item_attr = attr["quiz_attr"]

                attr['ready'].append(item_attr)
                speech = util.get_hint(handler_input, attr['ready'], item)
                attr['counter'] += 1
                if data.USE_CARDS_FLAG:
                    response_builder.set_card(
                        ui.StandardCard(title="Question #{}".format(
                            str(attr["counter"])),
                                        text=speech))

            else:
                speech = util.get_speechcon(correct_answer=False)
                speech += util.no_answer(item_attr)
                speech += util.get_speech_description(item)
                speech += data.EXIT_SKILL_MESSAGE

        return response_builder.speak(speech).ask(speech).response
     def handle(self, handler_input):
         # type: (HandlerInput) -> Response
         session_attr = handler_input.attributes_manager.session_attributes

         session_attr['moduleDialogEnd'] = 0
         speech_text = ""
         moduleName = session_attr['moduleName']
         moduleCode = None

         #depending on the current dialog turn value, outputs the information the user asked to hear about
         #then following this asks a question about the next piece of realted module information
         if (session_attr['moduleDialogTurn'] == 1):
             speech_text = ("Would you like to know what semester " + session_attr['moduleName'] + " is taught in?")
         elif (session_attr['moduleDialogTurn'] == 2):
             speech_text = ("It is taught in the " + ModuleInfo("Session", moduleCode, moduleName) + " session." + " Would you like to know how many credits " + session_attr['moduleName'] + " is worth?")
         elif (session_attr['moduleDialogTurn'] == 3):
            speech_text = ("It is worth " + ModuleInfo("Credits", moduleCode, moduleName) + " credits." + " Would you like to know how " + session_attr['moduleName'] + " is assessed?")
         elif (session_attr['moduleDialogTurn'] == 4):
             speech_text = (ModuleInfo("Assessment", moduleCode, moduleName) + " Would you like to know who teaches " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 5):
             speech_text = (ModuleInfo("Lecturers", moduleCode, moduleName) + " Would you like to know the aims of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 6):
             speech_text = (ModuleInfo("Aims", moduleCode, moduleName) + " Would you like to know the objectives of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 7):
             speech_text = (ModuleInfo("Objectives", moduleCode, moduleName) + " Would you like to know about the content of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 8):
             speech_text = (ModuleInfo("Content", moduleCode, moduleName) + " Would you like to know how " + session_attr['moduleName'] + " is taught?")
         elif (session_attr['moduleDialogTurn'] == 9):
             speech_text = (ModuleInfo("Teaching", moduleCode, moduleName) + " Would you like to know about the feedback of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 10):
             speech_text = (ModuleInfo("Feedback", moduleCode, moduleName) + " That is everything to know about " + session_attr['moduleName'] + ".")
             session_attr['moduleDialogTurn'] = 0
             session_attr['lastSpeech'] = speech_text
             #finally when the dialog flow reaches 10 the dialog turn session attribute is reset
             handler_input.response_builder.speak(speech_text).set_card(
                 ui.StandardCard(
                     title=("Sheffield DCS Skill"),
                     text=speech_text)).set_should_end_session(False)
             return handler_input.response_builder.response

        #increments the dialog turn value
         session_attr['moduleDialogTurn'] = (session_attr['moduleDialogTurn'] +1)
         session_attr['lastSpeech'] = speech_text

         reprompt = "Would you like to hear more?"

         handler_input.response_builder.speak(speech_text).set_card(
             ui.StandardCard(
                 title=("Sheffield DCS Skill"),
                 text=speech_text)).set_should_end_session(False).ask(reprompt)
         return handler_input.response_builder.response
Beispiel #4
0
    def handle(self, handler_input):
        speech_text = """
        勇者「倉庫ですね!どんな手がかりがあるんだろう...?
        すごく良い品質の剣がたくさん並んでいる。これなんか特に一級品だ。手入れも行き届いている。良い学校だ。
        ん?倉庫の床に小さな穴が開いている。こんなに手入れも行き届いている学校なのになぜ?
        」
        <audio src="soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_intro_01"/>
        勇者「うーん、他に手がかりがありそうなのはどこだろう、、、?」
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['scene'] = 'explore.colosseum'
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['re_ask'] = '勇者「他に手がかりがありそうなのはどこだろう、、、?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「他に手がかりがありそうなのはどこだろう、、、?」',
                            text='・客席\r\n'
                            '・倉庫\r\n'
                            '・控室\r\n'
                            '・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
Beispiel #5
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        request = handler_input.request_envelope.request.intent.slots[
            "Search"].value

        #eliminate occurences of ' as they can cause the sql string to break and crash
        request = request.replace("'", "")

        #use the search engine to search the askus webpages for freqeuntly asked questions
        #matching the user's question
        results = conduct_search(request)

        if (results[0] is None):
            speech_text = "No answer could be found for your question, try asking something else."
        else:

            #set the speech output as the answer that most closely matches the user's question
            #replace any & occurences with and to avoid invalid ssml output speech
            speech_text = results[0][1].replace("&", "and")

        session_attr['lastSpeech'] = speech_text
        reprompt = "Try asking me something else."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        moduleName = handler_input.request_envelope.request.intent.slots[
            "ModuleName"].value

        with conn.cursor() as cur:

            sql = "SELECT Summary FROM Modules WHERE ModuleName=%s"
            cur.execute(sql, moduleName)
            speech_text = cur.fetchone()
            cur.close

        speech_text = speech_text[0] + " Would you like to hear more?"
        #sets the moduleDialogTurn sesion attribute to 1 as the dialog flow has been initiated
        if (session_attr['moduleDialogTurn'] == 0):
            session_attr['moduleDialogTurn'] += 1

        #sets the moduleDialogEnd session attribute to true in order to initialise the
        #module dialog flow
        session_attr['moduleDialogEnd'] = True
        session_attr['moduleName'] = moduleName
        #resets the turn session attribute
        session_attr['lecturersModulesDialogTurn'] = 0

        session_attr['lastSpeech'] = speech_text

        reprompt = "Would you like to hear more about " + moduleName + "?"

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes

        #Chekck if it is the first help message, if not gets a random help message from the database
        if (session_attr['HelpDialogRandomised'] == False):
            speech_text = "You can ask me about modules, courses, lecturers, timetabling information as well as general questions regarding applications. If your question cannot be answered try saying search followed by your question to query the university related webpages for an answer."
            session_attr['HelpDialogRandomised'] = True
        else:
            with conn.cursor() as cur:
                #gets the maximum id value of the last help record in the Help database table
                sql = "SELECT HelpID FROM Help ORDER BY HelpID DESC LIMIT 1;"
                cur.execute(sql)
                maxID = cur.fetchone()
                maxID = maxID[0]

                #generates a ranom number between 1 and the highest ID value of the last help message in the database
                x = randint(1, maxID)

                #used the random generated id to get a random help message
                sql = "SELECT Message FROM Help WHERE HelpID=%s"
                cur.execute(sql, (x))
                speech_text = cur.fetchone()
                #sets the speech output as the random help message
                speech_text = speech_text[0]
                cur.close

        session_attr['lastSpeech'] = speech_text
        reprompt = "Try asking me something else."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response

        #set the initial session attributes in the attributes manager when the skill begins
        session_attr = handler_input.attributes_manager.session_attributes
        session_attr['moduleDialogEnd'] = 0
        session_attr['moduleDialogTurn'] = 0
        session_attr['coursesDialogTurn'] = 0
        session_attr['coursesHearMoreDialogTurn'] = 0
        session_attr['lecturersDialogTurn'] = 0
        session_attr['lecturersModulesDialogTurn'] = 0
        session_attr['HelpDialogRandomised'] = False

        #sets the speech output
        speech_text = "Welcome to the Sheffield Department of Computer Science Alexa Skill!"

        #this session attribute is used to remember the last piece of spoken speech
        session_attr['lastSpeech'] = speech_text

        reprompt = "Say help if you need assistance getting started."

        #This handler handles the reponse of the given intent, by setting the output speech
        #and the visual component of the skill using the card property
        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        session_attr = handler_input.attributes_manager.session_attributes
        #get values from slots
        moduleCode = handler_input.request_envelope.request.intent.slots["ModuleCode"].value
        moduleName = handler_input.request_envelope.request.intent.slots["ModuleName"].value

        #sets the moduleDialogTurn sesion attribute to 1 as the dialog flow has been initiated
        if (session_attr['moduleDialogTurn'] == 0):
            session_attr['moduleDialogTurn'] +=1

        session_attr['moduleDialogEnd'] = 1

        #sets a session attribute regarding the module that the user has asked about
        #if the user has asked via the module code then the corresponding module name is
        #obtained and hence used as the session attribute
        if (moduleCode is None):
            session_attr['moduleName'] = moduleName
        else:
            session_attr['moduleName'] = ModuleInfo("ModuleName", moduleCode, moduleName)

        #builds the speech response by obtaining the necessary information via the moduleinfo method
        speech_text = ModuleInfo("Summary", moduleCode, moduleName) + " Would you like to hear more?"
        session_attr['lastSpeech'] = speech_text

        reprompt= "Would you like to hear more?"

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        speech_text = """
        勇者「屋上ですね!かしこまりました!」
        <audio src="soundbank://soundlibrary/human/amzn_sfx_person_running_03"/>
        <audio src="soundbank://soundlibrary/doors/doors_wood/wood_06"/>
        盲目の生徒「すまない。耳をすましているが、何も聞こえない。。。」
        勇者「そうか。何かあったら教えてくれ。
        <break time="1s"/> 
        神よ、次はどうすればよろしいでしょうか?
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['scene'] = 'explore.rooftop'
        session['re_ask'] = '勇者「神よ、次はどうすればよろしいでしょうか?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「神よ、次はどうすればよろしいでしょうか?」',
                            text='・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
Beispiel #11
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        #get value from slot
        courseName = handler_input.request_envelope.request.intent.slots[
            "CourseName"].value

        #builds the response using the courseInfo method to obtain the information from the
        #database related to the course the user wants to know the entry requirements of
        speech_text = "The entry requirements for " + courseName + " are " + CourseInfo(
            "EntryReq", courseName)
        speech_text = speech_text + " would you like to hear more about " + courseName + "?"

        session_attr['courseName'] = courseName
        session_attr['lastSpeech'] = speech_text
        session_attr['coursesHearMoreDialogTurn'] = 1
        session_attr['coursesDialogTurn'] = 0

        reprompt = "Would you like to hear more about " + courseName + "?"

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        speech_text = """
        勇者「闘技場ですね!かしこまりました!」
        <audio src="soundbank://soundlibrary/human/amzn_sfx_person_running_03"/>
        勇者「闘技場に到着いたしました、、、手がかりはどこにあるだろう、、、?」
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['scene'] = 'explore.colosseum'
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['re_ask'] = '勇者「手がかりはどこにあるだろう、、、?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「手がかりはどこにあるだろう、、、?」',
                            text='・客席\r\n'
                            '・倉庫\r\n'
                            '・控室\r\n'
                            '・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     slots = handler_input.request_envelope.request.intent.slots
     QType = slots["QType"].value
     GLevel = slots["GLevel"].value
     
     questionanswer_attributes = {
         "global_answer": data.GLOBAL_NULL,
         "global_question": data.GLOBAL_NULL,
         "last_question_asked": data.GLOBAL_NULL,
         "global_GLevel": data.GLOBAL_NULL,
         "global_QType": data.GLOBAL_NULL
     }
     
     #Calls askQuestion method, which pulls question and answer pair based on topic & grade
     #Result returned is split at the colon into a question and an answer
     #The split question and answer strings are stored in an array, qa_array
     qa_array = askQuestion(QType, GLevel).split(':')
     #Question and Answer are at spots 0 & 1, respectively, in the qa_array
     question_string = qa_array[0]
     question_answer = qa_array[1]
     #constants from data.py are overwritten by the new strings
     data.GLOBAL_ANSWER = question_answer
     data.GLOBAL_QUESTION = question_string
     data.LAST_QUESTION_ASKED = question_string + ":" + question_answer
     data.GLOBAL_GLEVEL = GLevel
     data.GLOBAL_QTYPE = QType
     attributes_manager = handler_input.attributes_manager
     
     #makes a persistent copy of important data
     #Testing for user re-asking questions - Dalton
     questionanswer_attributes = {
         "global_answer": data.GLOBAL_ANSWER,
         "global_question": data.GLOBAL_QUESTION,
         "last_question_asked": data.LAST_QUESTION_ASKED,
         "global_GLevel": data.GLOBAL_GLEVEL,
         "global_QType": data.GLOBAL_QTYPE
     }
     attributes_manager.persistent_attributes = questionanswer_attributes
     attributes_manager.save_persistent_attributes()
     #speaks the question
     #listens for the answer- if it's invalid and can't go on to the next method (e.g. doesn't include "what is")
     #the ANSWER_CLARIFICATION_REQUEST is asked
     
     questiontypedisplay = "placeholder string"
     if (data.GLOBAL_QTYPE) == "math":
         questiontypedisplay = "Math"
     else:
         questiontypedisplay = "Coding"
     
     response_builder = handler_input.response_builder
     response_builder.set_card(
             ui.StandardCard(
                 title = questiontypedisplay + " Question for " + data.GLOBAL_GLEVEL + " Grade",
                 text= data.GLOBAL_QUESTION,
                 image = ui.Image(
                     small_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download",
                     large_image_url="https://upload.wikimedia.org/wikipedia/en/1/17/Stetson_Hatters_logo_%282018%29.png?download"
                 )))
     return handler_input.response_builder.speak(question_string).ask(data.ANSWER_CLARIFICATION_REQUEST).response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        fof_sfn_input = {
            'alexa_user_id': handler_input.request_envelope.context.system.user.user_id,
            'IsPreResponse': True,
            'intent': 'CancelOrStopIntent',
            'env_type': util.get_env_type(handler_input)
        }
        response = sfn_ctl.execute(fof_sfn_input)
        handler_input.response_builder.speak(response["response_text"])

        image_url = response.get('image_url')
        if image_url:
            handler_input.response_builder.set_card(
                ui.StandardCard(
                    title='',
                    text='',
                    image=ui.Image(
                        small_image_url=image_url,
                        large_image_url=image_url
                    )
                )
            )

        handler_input.response_builder.set_should_end_session(True)

        return handler_input.response_builder.response
    def handle(self, handler_input):
        speech_text = """
        勇者「図書館ですね!かしこまりました!」
        <audio src="soundbank://soundlibrary/human/amzn_sfx_person_running_03"/>
        <audio src="soundbank://soundlibrary/doors/doors_wood/wood_06"/>
        勇者「ここが図書館かぁ。うーん、役に立ちそうな本はどれだろう、、、?」
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['scene'] = 'explore.library'
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['re_ask'] = '勇者「役に立ちそうな本はどれだろう、、、?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「役に立ちそうな本はどれだろう、、、?」',
                            text='・妖精のかくれんぼ\r\n'
                            '・スキル「シノビアシ」\r\n'
                            '・魔法の猫「プレシャ」\r\n'
                            '・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
Beispiel #16
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        speak_output = "Okay. I've put 60 seconds on the clock. Let's begin!"
        gameSession.start()

        handler_input.response_builder.set_card(
            ui.StandardCard(
                title="Card Match Game",
                text="Welcome to Card Match Game!",
                image=ui.Image(
                    small_image_url=
                    "https://d2o906d8ln7ui1.cloudfront.net/images/BT7_Background.png",
                    large_image_url=
                    "https://d2o906d8ln7ui1.cloudfront.net/images/BT2_Background.png"
                )))
        ##### comment codes below for online simulation
        handler_input.response_builder.add_directive(
            LaunchDirective(
                VideoItem(
                    source=
                    "https://cardmatchgamevideo.s3.amazonaws.com/clock1.mp4",
                    metadata=Metadata(title="Card Match Game",
                                      subtitle="Clock"))))
        ### end of your comment
        return (handler_input.response_builder.speak(speak_output).ask(
            "You can ask the color of center left symbol").set_card(
                SimpleCard(
                    "Card Match Game",
                    "You can ask, 'the color of center left symbol'")).response
                )
Beispiel #17
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        #get's the user's unique userID from their Alexa enabled device
        userID = handler_input.request_envelope.context.system.user.user_id

        #using the user's unqiue userID their previosly added favourite modules are obtained
        with conn.cursor() as cur:
            sql= "SELECT ModuleName FROM Modules, FavouriteModules where Modules.ModuleCode=FavouriteModules.ModuleCode AND FavouriteModules.UserID = %s"
            cur.execute(sql, userID)
            result = cur.fetchall()
            cur.close

        #if the result of the SQL search is an empty list then an appropriate message is output
        if result == ():
            speech_text = "Your current list of favourite modules is empty."
        #if the result is not empty then the list is recursed over each element to form the output speech
        else:
            speech_text = "Your current list of favourite modules includes: "

            for x in result:
                print(x[0])
                speech_text += x[0] + ", "

        session_attr['lastSpeech'] = speech_text
        reprompt = "Try asking me something else."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
Beispiel #18
0
    def handle(self, handler_input):
        attr = handler_input.attributes_manager.persistent_attributes
        height = attr.get('height', 0)

        speech = Speech()
        speech.add_text('次は水を上げて欲しいな。楽しみに待っています。')
        speech_text = speech.speak()

        cactus_image = utils.ImageGetter().get_image(utils.get_level(height),
                                                     utils.select_scene())

        ret_img = Image(sources=[ImageInstance(url=cactus_image)])
        title = data.SKILL_NAME
        primary_text = get_plain_text_content(primary_text="")

        if utils.supports_apl(handler_input):
            handler_input.response_builder.add_directive(
                RenderTemplateDirective(
                    BodyTemplate2(
                        back_button=BackButtonBehavior.VISIBLE,
                        image=ret_img,
                        title=title,
                        text_content=primary_text))).set_should_end_session(
                            True)

        handler_input.response_builder.set_card(
            ui.StandardCard(title=data.get_standard_card_title(height),
                            text=data.get_standard_card_text(height),
                            image=ui.Image(small_image_url=cactus_image,
                                           large_image_url=cactus_image)))

        return handler_input.response_builder.speak(speech_text).response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        #get values from slots
        moduleCode = handler_input.request_envelope.request.intent.slots[
            "TimetableUnitCode"].value
        moduleName = handler_input.request_envelope.request.intent.slots[
            "TimetableUnitTitle"].value

        #calls the TimetableInfo method to query the database for the timetable information
        #relating to the user's request
        timetableResults = TimetableInfo(moduleCode, moduleName)

        #builds the speech output by looping over the timetableResults object and
        #selecting the columns of information from the database response that are
        #relevant to form the response.
        speech_text = ""
        for x in timetableResults:
            moduleName = x[1]
            speech_text = speech_text + x[4] + " on " + x[5] + " at " + x[
                6] + " until " + x[7] + " in weeks " + x[8] + " of the " + x[
                    9] + ". "

        session_attr['lastSpeech'] = speech_text
        reprompt = "Try asking me something else."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        speech_text = """
        勇者「客席ですね!どんな手がかりがあるんだろう...?」
        読書している人「やぁ。どうかした?」
        勇者「実は訳あって、キャリネズミというモンスターをさがしているんだ。君はみていない?」
        読書している人「ごめん、読書に夢中で。あ!でもキャリネズミって、確かものすごく隠れるのが得意なモンスターだよね?」
        勇者「そうなんだよ!そのせいでさがし辛くて困っているんだ」
        読書している人「確か図書館でそんな感じの本を読んだ事がある気がするなぁ。うちの図書館はいろんな本があって、情報ならたいてい揃うよ」
        勇者「そっか!ありがとう!」
        読書している人「うん、がんばってねー!」
        <audio src="soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_intro_01"/>
        勇者「うーん、他に手がかりがありそうなのはどこだろう、、、?」
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['scene'] = 'explore.colosseum'
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['re_ask'] = '勇者「他に手がかりがありそうなのはどこだろう、、、?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「他に手がかりがありそうなのはどこだろう、、、?」',
                            text='・客席\r\n'
                            '・倉庫\r\n'
                            '・控室\r\n'
                            '・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
Beispiel #21
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In NewGameHandler")
        attr = handler_input.attributes_manager.session_attributes

        attr["board"] = util.clear_board()
        attr["state"] = STATE_SETTING_UP_BOARD
        attr["setup_board_ship_code"] = data.PIECES["patrol_boat"]["code"]
        attr["setup_board_ship_count"] = 0
        
        user_id = handler_input.request_envelope.session.user.user_id
        response_builder = handler_input.response_builder
        
        rsp = random.choice(data.PLACE_PIECE_RESPONSE) + data.SHIPS[0] + ", " + random.choice(data.PLACE_PIECE_SIZE) + str(data.PIECES[util.get_ship_id(data.SHIPS[0])]["size"]) + "?"

        r = drawboard.draw_board_with_ships(user_id, attr["board"], "user")
        print(r)
        
        user_board_image = dbcontroller.get_board_img(user_id, "user")
        response_builder.set_card(ui.StandardCard(
                                                  title = data.SHIPS[0].title(),
                                                  text = rsp,
                                                  image = ui.Image(small_image_url = user_board_image, large_image_url = user_board_image)))
    
        response_builder.speak(rsp).ask(rsp)

        return response_builder.response
Beispiel #22
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        #gets the slot value of the course type specified by the user
        courseType = handler_input.request_envelope.request.intent.slots[
            "CourseType"].value

        #outputs the appropriate answer based on whether the user specifics undergraduate or
        #postgraduate courses
        if (courseType == "under graduate" or courseType == "undergraduate"):
            speech_text = "The Department of Computer Science offers undergraduate degrees in Computer Science, Software Engineering and Computer Science and Artificial Intelligence; all of which have an option for a Year in Industry or an Integrated Masters. Would you like more information about any of these courses?"
        else:
            speech_text = "The Department of Computer Science offers masters degrees in Advanced Computer Science, Advanced Software Engineering, Data Analytics, Software Systems and Internet Technology, Cybersecurity and Artificial Intelligence and Computer Science with Speech and Language Processing. Would you like more information about any of these courses?"

        session_attr['lastSpeech'] = speech_text
        #sets the turn of the dialogue flow to two
        session_attr['coursesDialogTurn'] = 2

        reprompt = "Would you like more information about any of the courses?"

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
Beispiel #23
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        session_attr = handler_input.attributes_manager.session_attributes
        courseName = handler_input.request_envelope.request.intent.slots[
            "CourseName"].value

        #builds the response using the courseInfo method to obtain the information from the
        #database related to the course the user wants to hear more about
        speech_text = CourseInfo(
            "Description", courseName
        ) + " The UCAS code for " + courseName + " is " + CourseInfo(
            "UcasCode",
            courseName) + " and the entry rquirements are " + CourseInfo(
                "EntryReq", courseName)
        session_attr['lastSpeech'] = speech_text

        #the dialog flow is complete and so the coursesDialogTurn sesion attribute is reset
        session_attr['coursesDialogTurn'] = 0

        reprompt = "Try asking me something else."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(
                title=("Sheffield DCS Skill"),
                text=speech_text)).set_should_end_session(False).ask(reprompt)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        speech_text = """
        勇者「控室ですね!どんな手がかりがあるんだろう...?」
        筋肉質なおじさん「ふんっ!ふんっ!今日も剣術の稽古は気持ちがいいなぁ!」
        勇者「すみません、この辺りで「キャリネズミ」というモンスターを見ませんでしたか?」
        筋肉質なおじさん「すまない、稽古にむちゅうで、何も見ていない。」
        勇者「そうですか、、、」
        筋肉質なおじさん「そんなことより、稽古に付き合ってくれないか?久々に実力者と手合わせ願いたい!」
        勇者「すみません、急いでいて。また今度お願いします!」
        筋肉質なおじさん「そうか、ではまた今度頼む。」
        <audio src="soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_intro_01"/>
        勇者「うーん、他に手がかりがありそうなのはどこだろう、、、?」
        """
        handler_input.response_builder.speak(
            speech_text).set_should_end_session(False)

        session = handler_input.attributes_manager.session_attributes
        session['scene'] = 'explore.colosseum'
        session['oracle_limit'] = session['oracle_limit'] - 1
        session['re_ask'] = '勇者「他に手がかりがありそうなのはどこだろう、、、?」'

        image_url = assets.get_image('humans/hero/hero_stand_512')
        handler_input.response_builder.set_card(
            ui.StandardCard(title='勇者「他に手がかりがありそうなのはどこだろう、、、?」',
                            text='・客席\r\n'
                            '・倉庫\r\n'
                            '・控室\r\n'
                            '・図書館へ行く\r\n'
                            '・闘技場へ行く\r\n'
                            '・屋上へ行く',
                            image=ui.Image(small_image_url=image_url,
                                           large_image_url=image_url)))

        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        # Get configurayion informatoin
        
        result = getConfig()
        VERSION      = result["release_info"]["version"]
        SMALL_IMAGE  = result["Welcome_small_image"]
        LARGE_IMAGE  = result["Welcome_large_image"]
        
        # Retrieve the API version
        api_version=info(1,"","api-version","")
        
        # Retrieve users's locale......
        locale=get_locale(handler_input)
        
        # ..... and  get their language index......
        langindex=0
        lang=0
        
        for language in result['i8n']['languages']:
            if language['language'] == locale:
                lang=langindex
            langindex = langindex+1    
        
        # ..... to get their welcome settings.
        speak_output = result['i8n']['languages'][lang]['settings']['Welcome_speech']
        
        card_text    = result['i8n']['languages'][lang]['settings']['Welcome_card_text'] + "\nSkill Version: " + VERSION + "\nAPI Version: " + api_version
        card_title   = result["release_info"]["skill_name"]

        # MAYBE STORE THE JSON AND THE INDEX FOR THE VERSION STUFF IN A CUSTOM SLOT SO WE DONT HAVE TO GO BACK TO THE WEB EVERY TIME - EFFICIENCY-ISE.....?
        
        #LandingZoneList slot population (using dynamic entities)
        
        results = landingpads(1,"","getLandingPadsList","None")
        
        R=[]
        for pad in results:
            R.append(Entity(id=pad["id"].replace("-",""), name=EntityValueAndSynonyms(value=pad["full_name"], synonyms=["X","Y"])))

        lzlist_entity_directive = DynamicEntitiesDirective(
            update_behavior=UpdateBehavior.REPLACE,
            types=[EntityListItem(name="LandingZoneList", values=R)],
        )        
        
        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .add_directive(lzlist_entity_directive)
                .set_card(
                    ui.StandardCard(
                        title = card_title,
                        text  = card_text,
                        image = ui.Image(SMALL_IMAGE,LARGE_IMAGE)
                        )
                    )
        .response
        )
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        speech_text = "Thanks for using the Sheffield Department of Computer Science Alexa Skill."

        handler_input.response_builder.speak(speech_text).set_card(
            ui.StandardCard(title=("Sheffield DCS Skill"),
                            text=speech_text)).set_should_end_session(True)
        return handler_input.response_builder.response
     def handle(self, handler_input):
         # type: (HandlerInput) -> Response
         session_attr = handler_input.attributes_manager.session_attributes

         speech_text = ""

         #depending on the current dialog turn value, outputs a speech response asking the user if
         #they would like to hear information regarding the next module attribute
         if (session_attr['moduleDialogTurn'] == 2):
             speech_text = ("Would you like to know how many credits " + session_attr['moduleName'] + " is worth?")
         elif (session_attr == 3):
            session_attr['moduleDialogTurn'] = ("Would you like to know how " + session_attr['moduleName'] + " is assessed?")
         elif (session_attr['moduleDialogTurn'] == 4):
             speech_text = ("Would you like to know who teaches " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 5):
             speech_text = ("Would you like to know the aims of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 6):
             speech_text = ("Would you like to know the objectives of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 7):
             speech_text = ("Would you like to know about the content of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 8):
             speech_text = ("Would you like to know how " + session_attr['moduleName'] + " is taught?")
         elif (session_attr['moduleDialogTurn'] == 9):
             speech_text = ("Would you like to know about the feedback of " + session_attr['moduleName'] + "?")
         elif (session_attr['moduleDialogTurn'] == 10):
             #finally when the dialog flow reaches 10 the dialog turn session attribute is reset
             speech_text = ("That is everything to know about " + session_attr['moduleName'] + ".")
             session_attr['moduleDialogTurn'] = 0
             session_attr['lastSpeech'] = speech_text
             handler_input.response_builder.speak(speech_text).set_card(
                 ui.StandardCard(
                     title=("Sheffield DCS Skill"),
                     text=speech_text)).set_should_end_session(False)
             return handler_input.response_builder.response

         #increments the dialog turn value
         session_attr['moduleDialogTurn'] += 1
         session_attr['lastSpeech'] = speech_text

         reprompt = speech_text

         handler_input.response_builder.speak(speech_text).set_card(
             ui.StandardCard(
                 title=("Sheffield DCS Skill"),
                 text=speech_text)).set_should_end_session(False).ask(reprompt)
         return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        destinations_choice = handler_input.attributes_manager.session_attributes.get(
            'destinations_choice')
        fof_sfn_input = {
            'alexa_user_id': handler_input.request_envelope.context.system.user.user_id,
            'IsPreResponse': False,
            'state': 'Launch',
            'destinations_choice': destinations_choice,
            'env_type': util.get_env_type(handler_input)
        }
        response = sfn_ctl.execute(fof_sfn_input)
        if response.get('destinations_choice'):
            handler_input.attributes_manager.session_attributes[
                'destinations_choice'] = response['destinations_choice']
        handler_input.attributes_manager.session_attributes['state'] = \
            response['state']

        if response.get('node'):
            handler_input.attributes_manager.session_attributes['node'] = \
                response['node']

        print(f'response: {response}, type: {type(response)}')
        speech_text = response["response_text"]

        image_url = response.get('image_url')
        bg_image_url = response.get('bg_image_url')
        image_title = response.get('image_title')
        image_text = response.get('image_text')
        if image_url:
            img_obj = Image(sources=[ImageInstance(url=image_url)])
            bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)])
            if util.is_support_display(handler_input):
                handler_input.response_builder.add_directive(
                    RenderTemplateDirective(
                        BodyTemplate7(
                            back_button=BackButtonBehavior.VISIBLE,
                            image=img_obj,
                            background_image=bg_img_obj,
                            title='')
                    )
                )
            else:
                handler_input.response_builder.set_card(
                    ui.StandardCard(
                        title='',
                        text='',
                        image=ui.Image(
                            small_image_url=image_url,
                            large_image_url=image_url
                        )
                    )
                )

        handler_input.response_builder.speak(speech_text).ask(
            speech_text).set_should_end_session(
            response.get('set_should_end_session', True))
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response

        card = ui.StandardCard(title="Route to Bar", text="link")

        speak_output = "Click on the card to navigate to the bar."

        return (handler_input.response_builder.set_card(card).speak(
            speak_output).set_should_end_session(False).response)
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In QuizHandler")
        attr = handler_input.attributes_manager.session_attributes
        attr["state"] = "QUIZ"
        attr["counter"] = 0
        attr["quiz_score"] = 0
        attr["score"] = 0

        question = util.ask_question(handler_input)
        response_builder = handler_input.response_builder
        response_builder.speak(data.START_QUIZ_MESSAGE + (
            "Here is your {} question. "
        ).format(util.get_ordinal_indicator(attr["counter"])) + question)
        response_builder.ask(question)
        logger.info("after question asked")

        if data.USE_CARDS_FLAG:
            item = attr["quiz_item"]
            response_builder.set_card(
                ui.StandardCard(
                    title="Question #1",
                    text=data.START_QUIZ_MESSAGE + question,
                    image=ui.Image(
                        small_image_url=util.get_small_image(item),
                        large_image_url=util.get_large_image(item))))

        logger.info("after USE_CARDS_FLAG")

        if util.supports_display(handler_input):
            item = attr["quiz_item"]
            item_attr = attr["quiz_attr"]
            title = "Question #{}".format(str(attr["counter"]))
            background_img = Image(sources=[
                ImageInstance(url=util.get_image(
                    ht=1024, wd=600, label=item["abbreviation"]))
            ])
            item_list = []
            for ans in util.get_multiple_choice_answers(
                    item, item_attr, data.STATES_LIST):
                item_list.append(
                    ListItem(
                        token=ans,
                        text_content=get_plain_text_content(primary_text=ans)))

            response_builder.add_directive(
                RenderTemplateDirective(
                    ListTemplate1(token="Question",
                                  back_button=BackButtonBehavior.HIDDEN,
                                  background_image=background_img,
                                  title=title,
                                  list_items=item_list)))

        logger.info("about to return")

        return response_builder.response