예제 #1
0
    async def people_step(
            step_context: WaterfallStepContext) -> DialogTurnResult:
        """Ask the user: how many people to make the reservation?"""

        # Retrieve the booking keywords
        booking_keywords: dict = step_context.options
        step_context.values['booking_keywords'] = booking_keywords

        # If the keyword 'people' exists and is filled, pass the question
        if 'people' in booking_keywords and booking_keywords[
                'people'] is not None:
            return await step_context.next(booking_keywords['people'])

        # Give user suggestions (1 or 2 people).
        # The user can still write a custom number of people [1, 4].
        options = PromptOptions(
            prompt=Activity(type=ActivityTypes.message,
                            text="Would you like a single or a double room?",
                            suggested_actions=SuggestedActions(actions=[
                                CardAction(title="Single",
                                           type=ActionTypes.im_back,
                                           value="Single room (1 people)"),
                                CardAction(title="Double",
                                           type=ActionTypes.im_back,
                                           value="Double room (2 peoples)")
                            ])),
            retry_prompt=MessageFactory.text(
                "Reservations can be made for one to four people only."))

        # NumberPrompt - How many people ?
        return await step_context.prompt("PeoplePrompt", options)
예제 #2
0
    async def _send_suggested_actions(self, turn_context: TurnContext):
        """
        Creates and sends an activity with suggested actions to the user. When the user
        clicks one of the buttons the text value from the "CardAction" will be displayed
        in the channel just as if the user entered the text. There are multiple
        "ActionTypes" that may be used for different situations.
        """

        reply = MessageFactory.text("What is your favorite color?")

        reply.suggested_actions = SuggestedActions(actions=[
            CardAction(
                title="Red",
                type=ActionTypes.im_back,
                value="Red",
                image="https://via.placeholder.com/20/FF0000?text=R",
                image_alt_text="R",
            ),
            CardAction(
                title="Yellow",
                type=ActionTypes.im_back,
                value="Yellow",
                image="https://via.placeholder.com/20/FFFF00?text=Y",
                image_alt_text="Y",
            ),
            CardAction(
                title="Blue",
                type=ActionTypes.im_back,
                value="Blue",
                image="https://via.placeholder.com/20/0000FF?text=B",
                image_alt_text="B",
            ),
        ])

        return await turn_context.send_activity(reply)
예제 #3
0
 async def on_members_added_activity(self, members_added: [ChannelAccount],
                                     turn_context: TurnContext):
     for member in members_added:
         if member.id != turn_context.activity.recipient.id:
             #Welcome message
             await turn_context.send_activity(
                 "Welcome to  GlobeMed Bot, Ask me a question and I will try "
                 "to answer it.")
             """
             Create and sends an activity with suggested actions to the user. When the user
             clicks one of the buttons the text value from the "CardAction" will be displayed
             in the channel just as if the user entered the text. There are multiple
             "ActionTypes" that may be used for different situations.
             """
             reply = MessageFactory.text(
                 '''Alternatively I can help you finding a healthcare provider,
                                         booking an appointment, checking your claim status and I could show you our products and services.'''
             )
             reply.suggested_actions = SuggestedActions(actions=[
                 CardAction(title="Healthcare Providers",
                            type=ActionTypes.im_back,
                            value="[HP]"),
                 CardAction(title="Products and Services",
                            type=ActionTypes.im_back,
                            value="[PS]"),
                 CardAction(title="Book an Appoitment",
                            type=ActionTypes.im_back,
                            value="[BA]"),
                 CardAction(title="Claim Status",
                            type=ActionTypes.im_back,
                            value="[CS]")
             ])
             await turn_context.send_activity(reply)
예제 #4
0
파일: bot.py 프로젝트: zhumakhan/hacknubot
 async def _get_user_prefer_score(self, text : str, turn_context: TurnContext):
     self.on_score = True
     send_text = MessageFactory.text("Choose the score you want to look at?")
     send_text.suggested_actions = SuggestedActions(
         actions=[
             CardAction(
                     title="A",
                     type=ActionTypes.im_back,
                     value="A"
                 ),
                 CardAction(
                     title="B",
                     type=ActionTypes.im_back,
                     value="B"
                 ),
                 CardAction( 
                     title="C",
                     type=ActionTypes.im_back,
                     value="C"
                 ),
                 CardAction(
                     title="D",
                     type=ActionTypes.im_back,
                     value="D"
                 ),
                 CardAction(
                     title="F",
                     type=ActionTypes.im_back,
                     value="F"
                 ),
         ]
     )
     return await turn_context.send_activity(send_text)
예제 #5
0
    async def intro_step(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:
        if not self._luis_recognizer.is_configured:
            await step_context.context.send_activity(
                MessageFactory.text(
                    "NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and "
                    "'LuisAPIHostName' to the appsettings.json file.",
                    input_hint=InputHints.ignoring_input,
                ))

            return await step_context.next(None)

        reply = MessageFactory.text("Mời lựa chọn:")

        reply.suggested_actions = SuggestedActions(actions=[
            CardAction(title="Tìm hiểu lễ hội Việt Nam",
                       type=ActionTypes.im_back,
                       value="Tìm hiểu lễ hội Việt Nam"),
            CardAction(title="Tìm kiếm các lễ hội",
                       type=ActionTypes.im_back,
                       value="Tìm kiếm các lễ hội"),
            CardAction(title="Gợi ý du lịch lễ hội",
                       type=ActionTypes.im_back,
                       value="Gợi ý du lịch lễ hội"),
        ])

        # return await step_context.context.send_activity(reply)
        return await step_context.prompt(TextPrompt.__name__,
                                         PromptOptions(prompt=reply))
예제 #6
0
    def suggested_actions(
        actions: List[CardAction],
        text: str = None,
        speak: str = None,
        input_hint: Union[InputHints, str] = InputHints.accepting_input,
    ) -> Activity:
        """
        Returns a message that includes a set of suggested actions and optional text.

        :Example:
        message = MessageFactory.suggested_actions([CardAction(title='a', type=ActionTypes.im_back, value='a'),
                                                    CardAction(title='b', type=ActionTypes.im_back, value='b'),
                                                    CardAction(title='c', type=ActionTypes.im_back, value='c')],
                                                    'Choose a color')
        await context.send_activity(message)

        :param actions:
        :param text:
        :param speak:
        :param input_hint:
        :return:
        """
        actions = SuggestedActions(actions=actions)
        message = Activity(type=ActivityTypes.message,
                           input_hint=input_hint,
                           suggested_actions=actions)
        if text:
            message.text = text
        if speak:
            message.speak = speak
        return message
 def test_should_include_choice_actions_in_suggested_actions(self):
     expected = Activity(
         type=ActivityTypes.message,
         text="select from:",
         input_hint=InputHints.expecting_input,
         suggested_actions=SuggestedActions(actions=[
             CardAction(
                 type=ActionTypes.im_back,
                 value="ImBack Value",
                 title="ImBack Action",
             ),
             CardAction(
                 type=ActionTypes.message_back,
                 value="MessageBack Value",
                 title="MessageBack Action",
             ),
             CardAction(
                 type=ActionTypes.post_back,
                 value="PostBack Value",
                 title="PostBack Action",
             ),
         ]),
     )
     activity = ChoiceFactory.suggested_action(
         ChoiceFactoryTest.choices_with_actions, "select from:")
     self.assertEqual(expected, activity)
예제 #8
0
    async def help_step(self, step_context: WaterfallStepContext):
        actions = SuggestedActions(actions=[
            CardAction(title="Key", type=ActionTypes.im_back, value="key"),
            CardAction(title="ID", type=ActionTypes.im_back, value="id"),
        ])
        response = activity_helper.create_activity_reply(
            step_context.context.activity,
            "To use this bot simply tell me the ID or any keyword and I'll try to find it",
            '', actions)

        return await step_context.prompt(TextPrompt.__name__,
                                         PromptOptions(prompt=response))
    async def _send_suggested_actions(self, turn_context: TurnContext):
        reply = MessageFactory.text(Messages.help)

        reply.suggested_actions = SuggestedActions(actions=[
            CardAction(title="Set Reminder",
                       type=ActionTypes.im_back,
                       value="Set Reminder"),
            CardAction(
                title="Show All Reminders",
                type=ActionTypes.im_back,
                value="Show All Reminders",
            ),
        ])
        return await turn_context.send_activity(reply)
예제 #10
0
    async def test(
            self, flow: ConversationFlow, profile: UserProfile, turn_context: TurnContext
    ):
        reply = MessageFactory.text("What is your favorite color?")

        reply.suggested_actions = SuggestedActions(
            actions=[
                CardAction(title="Red", type=ActionTypes.im_back, value="Red"),
                CardAction(title="Yellow", type=ActionTypes.im_back, value="Yellow"),
                CardAction(title="Blue", type=ActionTypes.im_back, value="Blue"),
            ]
        )

        return await turn_context.send_activity(reply)
예제 #11
0
파일: bot.py 프로젝트: tmnyoni/tamara-bot
    async def services_offered(self, turn_context: TurnContext):
        response = MessageFactory.text(
            "Here we are offering the following Services: ")

        response.suggested_actions = SuggestedActions(actions=[
            CardAction(
                title="1. Space", type=ActionTypes.im_back, value="space"),
            CardAction(title="2. Community",
                       type=ActionTypes.im_back,
                       value="community"),
            CardAction(title="3. Inquiries",
                       type=ActionTypes.im_back,
                       value="inquires")
        ])
        return await turn_context.send_activity(response)
예제 #12
0
    async def on_message_activity(self, turn_context: TurnContext):
        # The actual call to the QnA Maker service.
        response = await self.qna_maker.get_answers(turn_context)
        prompts = response[0].context.prompts

        if response and len(response) > 0:
            reply = MessageFactory.text(response[0].answer)
            if prompts and len(prompts) > 0:
                reply.suggested_actions = SuggestedActions(
                      actions=[
                          CardAction(title = prompts[iter].display_text, type=ActionTypes.im_back, value=prompts[iter].display_text) for iter in range(len(prompts))
                       ]
                      )
            await turn_context.send_activity(reply)
        else:
            await turn_context.send_activity("No QnA Maker answers were found.")
예제 #13
0
    async def _send_suggested_actions(self, turn_context: TurnContext):
        """
            Creates and sends an activity with suggested actions to the user. When the user
            clicks one of the buttons the text value from the "CardAction" will be displayed
            in the channel just as if the user entered the text. There are multiple
            "ActionTypes" that may be used for different situations.
            """

        reply = MessageFactory.text("Confirm the option")

        reply.suggested_actions = SuggestedActions(actions=[
            CardAction(title="YES", type=ActionTypes.im_back, value="YES"),
            CardAction(title="NO", type=ActionTypes.im_back, value="NO"),
        ])

        return await turn_context.send_activity(reply)
예제 #14
0
    async def _show_commands(self, context: TurnContext) -> None:
        reply = MessageFactory.text("Seleziona uno dei seguenti comandi")
        reply.suggested_actions = SuggestedActions(actions=[
            CardAction(title="ID", type=ActionTypes.im_back, value="id"),
            CardAction(title="Aggiungi Persona",
                       type=ActionTypes.im_back,
                       value="Aggiungi Persona"),
            CardAction(title="Cancella Persona",
                       type=ActionTypes.im_back,
                       value="Cancella Persona"),
            CardAction(title="Aiuto", type=ActionTypes.im_back, value="Aiuto"),
            CardAction(title="Test", type=ActionTypes.im_back, value="Test"),
            CardAction(
                title="Logout", type=ActionTypes.im_back, value="Logout")
        ])

        await context.send_activity(reply)
    def test_should_render_choices_as_suggested_actions(self):
        expected = Activity(
            type=ActivityTypes.message,
            text="select from:",
            input_hint=InputHints.expecting_input,
            suggested_actions=SuggestedActions(actions=[
                CardAction(type=ActionTypes.im_back, value="red", title="red"),
                CardAction(
                    type=ActionTypes.im_back, value="green", title="green"),
                CardAction(
                    type=ActionTypes.im_back, value="blue", title="blue"),
            ]),
        )

        activity = ChoiceFactory.suggested_action(
            ChoiceFactoryTest.color_choices, "select from:")

        self.assertEqual(expected, activity)
    def test_should_automatically_choose_render_style_based_on_channel_type(
            self):
        expected = Activity(
            type=ActivityTypes.message,
            text="select from:",
            input_hint=InputHints.expecting_input,
            suggested_actions=SuggestedActions(actions=[
                CardAction(type=ActionTypes.im_back, value="red", title="red"),
                CardAction(
                    type=ActionTypes.im_back, value="green", title="green"),
                CardAction(
                    type=ActionTypes.im_back, value="blue", title="blue"),
            ]),
        )
        activity = ChoiceFactory.for_channel(Channels.emulator,
                                             ChoiceFactoryTest.color_choices,
                                             "select from:")

        self.assertEqual(expected, activity)
예제 #17
0
파일: bot.py 프로젝트: PC-02/lacorrida
	async def _send_suggested_actions(self, turn_context: TurnContext):
		"""
		Creates and sends an activity with suggested actions to the user. When the user
		clicks one of the buttons the text value from the "CardAction" will be displayed
		in the channel just as if the user entered the text. There are multiple
		"ActionTypes" that may be used for different situations.
		"""

		reply = MessageFactory.text("What are you interested in?")

		reply.suggested_actions = SuggestedActions(
			actions=[
				CardAction(
					title="Housing",
					type=ActionTypes.im_back,
					value="Housing",
				),
				CardAction(
					title="Food Joints",
					type=ActionTypes.im_back,
					value="Food Joints",
				),
				CardAction(
					title="Job Listings",
					type=ActionTypes.im_back,
					value="Job Listings",
				),
				CardAction(
					title="Misc Resources",
					type=ActionTypes.im_back,
					value="Misc Resources",
				),
				CardAction(
					title="Community Chat",
					type=ActionTypes.im_back,
					value="Community Chat",
				),
			]
		)

		return await turn_context.send_activity(reply)
예제 #18
0
    async def on_message_activity(self, turn_context: TurnContext):
        if self._is_language_change_requested(turn_context.activity.text):
            # If the user requested a language change through the suggested actions with values "es" or "en",
            # simply change the user's language preference in the user state.
            # The translation middleware will catch this setting and translate both ways to the user's
            # selected language.
            # If Spanish was selected by the user, the reply below will actually be shown in Spanish to the user.
            current_language = turn_context.activity.text.lower()
            if current_language in (TranslationSettings.english_english.value,
                                    TranslationSettings.spanish_english.value):
                lang = TranslationSettings.english_english.value
            else:
                lang = TranslationSettings.english_spanish.value

            await self.language_preference_accessor.set(turn_context, lang)

            await turn_context.send_activity(
                f"Your current language code is: {lang}")

            # Save the user profile updates into the user state.
            await self.user_state.save_changes(turn_context)
        else:
            # Show the user the possible options for language. If the user chooses a different language
            # than the default, then the translation middleware will pick it up from the user state and
            # translate messages both ways, i.e. user to bot and bot to user.
            reply = MessageFactory.text("Choose your language:")
            reply.suggested_actions = SuggestedActions(actions=[
                CardAction(
                    title="Español",
                    type=ActionTypes.post_back,
                    value=TranslationSettings.english_spanish.value,
                ),
                CardAction(
                    title="English",
                    type=ActionTypes.post_back,
                    value=TranslationSettings.english_english.value,
                ),
            ])

            await turn_context.send_activity(reply)
예제 #19
0
파일: bot.py 프로젝트: zhumakhan/hacknubot
    async def _send_suggested_actions(self, turn_context: TurnContext):
        reply = MessageFactory.text("Choose your option.")

        reply.suggested_actions = SuggestedActions(
            actions=[
                CardAction(
                    title="Get average performance per score",
                    type=ActionTypes.im_back,
                    value="option_show"
                ),
                CardAction(
                    title="Predict exam score",
                    type=ActionTypes.im_back,
                    value="option_pred"
                ),
                CardAction(
                    title="Get tips for preparation",
                    type=ActionTypes.im_back,
                    value="option_get_rec"
                ),
            ]
        )

        return await turn_context.send_activity(reply)
예제 #20
0
    async def _fill_out_personal_preference(
            self, flow: ConversationFlow, profile: UserProfile, turn_context: TurnContext
    ):
        # await turn_context.send_activity("_fill_out_personal_preference")
        user_input = turn_context.activity.text.strip()

        # ask for meeting slot
        if flow.last_question_asked2 == Question2.NONE:
            # await turn_context.send_activity(
            #     MessageFactory.text("Let's get started. Which time slot during meetings do your prefer?")
            # )
            reply = MessageFactory.text("Let's get started. Which time slot during meetings do your prefer?")
            reply.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(title="HALF HOUR", type=ActionTypes.im_back, value="half hour"),
                    CardAction(title="ONE HOUR", type=ActionTypes.im_back, value="one hour"),
                    CardAction(title="TWO HOURS", type=ActionTypes.im_back, value="two hours"),
                    CardAction(title="NONE", type=ActionTypes.im_back, value="none"),
                ]
            )
            flow.last_question_asked2 = Question2.MEETINGSOLT

            return await turn_context.send_activity(reply)

        # validate name then ask for age
        elif flow.last_question_asked2 == Question2.MEETINGSOLT:
            profile.meetingSlot = turn_context.activity.text
            await turn_context.send_activity(
                MessageFactory.text(f"You have selected {profile.meetingSlot} for meeting slot")
            )
            flow.last_question_asked2 = Question2.NOMEETPERIOD
            reply = MessageFactory.text("Next. Which time period you don't want meeting?")
            reply.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(title="before 8am", type=ActionTypes.im_back, value="before 8am"),
                    CardAction(title="during lunch time", type=ActionTypes.im_back, value="during lunch time"),
                    CardAction(title="after 5pm", type=ActionTypes.im_back, value="after 5pm"),
                    CardAction(title="NONE", type=ActionTypes.im_back, value="NONE"),
                ]
            )
            return await turn_context.send_activity(reply)

        # validate age then ask for date
        elif flow.last_question_asked2 == Question2.NOMEETPERIOD:
            profile.nomeetPeriod = turn_context.activity.text
            flow.last_question_asked2 = Question2.TRANSPORTATION
            await turn_context.send_activity(
                MessageFactory.text(f"You have selected {profile.nomeetPeriod} for no meeting period.")
            )
            reply = MessageFactory.text("Next. Which transportation you want to attend meetings?")
            reply.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(title="car", type=ActionTypes.im_back, value="car"),
                    CardAction(title="bus", type=ActionTypes.im_back, value="bus"),
                    CardAction(title="bicycle", type=ActionTypes.im_back, value="bicycle"),
                    CardAction(title="foot", type=ActionTypes.im_back, value="foot"),
                ]
            )
            return await turn_context.send_activity(reply)

        # validate date and wrap it up
        elif flow.last_question_asked2 == Question2.TRANSPORTATION:
            profile.transportation = turn_context.activity.text
            flow.last_question_asked2 = Question2.NONE
            await turn_context.send_activity(
                MessageFactory.text(f"You have selected {profile.transportation} for meeting transportation.")
            )

            flow.CalenderState = State.NONE
            await self._send_welcome_message(turn_context)
예제 #21
0
파일: bot.py 프로젝트: Team-Asesor/Asesor
    async def on_message_activity(self, turn_context: TurnContext):
        #await turn_context.send_activity(f"You said 3 '{ turn_context.activity.text }'")

        #print("previous: "+str(self.prev_q_id))
        res = await self.recognizer.recognize(turn_context)
        intent, parsed_result = self.parse_json(res)
        client = self.authenticate_client()
        response = self.sentiment_analysis_example(
            client,
            str(turn_context.activity.text).lower())
        prefix = ""
        if response == "positive":
            prefix = "Good to hear it! "
        elif response == "negative":
            prefix = "Sorry to hear it! "
        else:
            prefix = ""
        if self.prev_q_id == -1:
            self.cur_q_id = 1

        elif self.prev_q_id == 1:
            if "new" in str(turn_context.activity.text).lower():
                self.cur_q_id = 2
            else:
                self.cur_q_id = 4

        elif self.prev_q_id == 3:
            self.cur_q_id = 8

        elif self.prev_q_id == 8:
            if "yes" in str(turn_context.activity.text).lower():
                self.cur_q_id = 9
            else:
                self.cur_q_id = 10

        elif self.prev_q_id == 10:
            if "yes" in str(turn_context.activity.text).lower():
                self.cur_q_id = 11
            else:
                self.cur_q_id = 16

        elif self.prev_q_id == 11:
            self.cur_q_id = 16

        elif self.prev_q_id == 17:
            self.cur_q_id = 0
            self.prev_q_id = -1

        else:
            self.cur_q_id = self.prev_q_id + 1
        #print("current: "+str(self.cur_q_id))

        if self.cur_q_id >= 0:
            ques = self.ques_list[self.cur_q_id]
        else:
            ques = None

        if self.cur_q_id == 4:
            ques = MessageFactory.text(ques)
            ques.suggested_actions = SuggestedActions(actions=[
                CardAction(title="1. Asthma Treatment Jan 15",
                           type=ActionTypes.im_back,
                           value="1. Asthma Treatment Jan 15"),
                CardAction(title="2. Skin Infection Feb 12",
                           type=ActionTypes.im_back,
                           value="2. Skin Infection Feb 12"),
                CardAction(title="3. Bipolar Syndrome March 21",
                           type=ActionTypes.im_back,
                           value="3. Bipolar Syndrome March 21"),
            ])

        if self.cur_q_id != 4:
            await turn_context.send_activity("Your Intention is this: " +
                                             str(intent))
            await turn_context.send_activity(
                "I also got the following info: " + str(parsed_result))
            await turn_context.send_activity(prefix + ques)
        else:
            await turn_context.send_activity(ques)

        self.prev_q_id = self.cur_q_id
예제 #22
0
    async def _send_suggested_actions(self,
                                      turn_context: TurnContext,
                                      first_time=True,
                                      after_feedback=False,
                                      custom_text=None):
        """
        Creates and sends an activity with suggested actions to the user. When the user
        clicks one of the buttons the text value from the "CardAction" will be displayed
        in the channel just as if the user entered the text. There are multiple
        "ActionTypes" that may be used for different situations.
        """

        if self.tableau:  # Tableau multiturn
            if after_feedback:
                reply = MessageFactory.text(
                    "Thank you for your feedback, and sorry I couldn't help. Would you like to look this up on the tableau site?"
                )
            else:
                reply = MessageFactory.text(
                    f"I didn't find any answers in the {CLIENT_NAME} knowledge base. Is this question about Tableau?"
                )
            reply.suggested_actions = SuggestedActions(actions=[
                CardAction(
                    title="Yes",
                    type=ActionTypes.im_back,
                    value="yes",
                    # image="https://via.placeholder.com/20/FF0000?text=R",
                    # image_alt_text="R",
                ),
                CardAction(
                    title="No",
                    type=ActionTypes.im_back,
                    value="no",
                    # image="https://via.placeholder.com/20/FFFF00?text=Y",
                    # image_alt_text="Y",
                ),
            ])

        elif self.multiturn_state.startswith('rate'):
            reply = MessageFactory.text("Did that help with your question?")
            reply.suggested_actions = SuggestedActions(actions=[
                CardAction(
                    title="Yes",
                    type=ActionTypes.im_back,
                    value="yes",
                ),
                CardAction(
                    title="No",
                    type=ActionTypes.im_back,
                    value="no",
                ),
            ])

        else:
            if custom_text is not None:
                msg = custom_text
            elif first_time:
                msg = "Do you need info on the following? If not, please let me know what I can help you with today?"
            else:
                msg = "Can I help you with anything else today?"
            reply = MessageFactory.text(msg)

            reply.suggested_actions = SuggestedActions(actions=[
                CardAction(
                    title="Check Tableau/Cognos status",
                    type=ActionTypes.im_back,
                    value="server_status",
                    # image="https://via.placeholder.com/20/FF0000?text=R",
                    # image_alt_text="R",
                ),
                CardAction(
                    title=f"{CLIENT_NAME} Access forms",
                    type=ActionTypes.im_back,
                    value="access_form",
                    # image="https://via.placeholder.com/20/FFFF00?text=Y",
                    # image_alt_text="Y",
                ),
                CardAction(
                    title="VPN Instructions",
                    type=ActionTypes.im_back,
                    value="vpn",
                    # image="https://via.placeholder.com/20/FFFF00?text=Y",
                    # image_alt_text="Y",
                ),
            ])

        return await turn_context.send_activity(reply)
예제 #23
0
파일: bot.py 프로젝트: zhumakhan/hacknubot
    async def _get_user_performance(self, text : str, turn_context: TurnContext):
        if self.on_start:
            self.q_id += 1
        if self.q_id == 1:
            send_text = MessageFactory.text("Time spent on study per week?")
            send_text.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(
                        title="<2 hours",
                        type=ActionTypes.im_back,
                        value="1"
                    ),
                    CardAction(
                        title="2 to 5 hours",
                        type=ActionTypes.im_back,
                        value="2"
                    ),
                    CardAction(
                        title="5 to 10 hours",
                        type=ActionTypes.im_back,
                        value="3"
                    ),
                    CardAction(
                        title=">10 hours",
                        type=ActionTypes.im_back,
                        value="4"
                    ),
                ]
            )
            return await turn_context.send_activity(send_text)
        if self.q_id == 2:
            self.studytime = turn_context.activity.text.lower()
            send_text = MessageFactory.text("Please, evaluate your free time after school (1 - less to 5 - more).")
            send_text.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(
                        title="1",
                        type=ActionTypes.im_back,
                        value="1"
                    ),
                    CardAction(
                        title="2",
                        type=ActionTypes.im_back,
                        value="2"
                    ),
                    CardAction( 
                        title="3",
                        type=ActionTypes.im_back,
                        value="3"
                    ),
                    CardAction(
                        title="4",
                        type=ActionTypes.im_back,
                        value="4"
                    ),
                    CardAction(
                        title="5",
                        type=ActionTypes.im_back,
                        value="5"
                    ),
                ]
            )
            return await turn_context.send_activity(send_text)
        if self.q_id == 3:
            self.freetime = turn_context.activity.text.lower()
            send_text = MessageFactory.text("Are you enrolled in other activities/clubs?")
            send_text.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(
                        title="Yes",
                        type=ActionTypes.im_back,
                        value="1"
                    ),
                    CardAction(
                        title="No",
                        type=ActionTypes.im_back,
                        value="0"
                    )
                ]
            )
            return await turn_context.send_activity(send_text)
        if self.q_id == 4:
            self.activities = turn_context.activity.text.lower()
            send_text = MessageFactory.text("Do you have internet acess?")
            send_text.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(
                        title="Yes",
                        type=ActionTypes.im_back,
                        value="1"
                    ),
                    CardAction(
                        title="No",
                        type=ActionTypes.im_back,
                        value="0"
                    )
                ]
            )
            return await turn_context.send_activity(send_text)
        if self.q_id == 5:
            self.internet = turn_context.activity.text.lower()
            send_text = MessageFactory.text("Please, choose your current health status (1 - unsatisfactory to 5 - good).")
            send_text.suggested_actions = SuggestedActions(
                actions=[
                    CardAction(
                        title="1",
                        type=ActionTypes.im_back,
                        value="1"
                    ),
                    CardAction(
                        title="2",
                        type=ActionTypes.im_back,
                        value="2"
                    ),
                    CardAction( 
                        title="3",
                        type=ActionTypes.im_back,
                        value="3"
                    ),
                    CardAction(
                        title="4",
                        type=ActionTypes.im_back,
                        value="4"
                    ),
                    CardAction(
                        title="5",
                        type=ActionTypes.im_back,
                        value="5"
                    ),
                ]
            )
            return await turn_context.send_activity(send_text)
        if self.q_id == 6:
            self.health = turn_context.activity.text.lower()
            send_text = MessageFactory.text("How many times you were absent (0 to 93)?")
            return await turn_context.send_activity(send_text)
        if self.q_id == 7:
            self.absences = turn_context.activity.text.lower()

        if self.q_id == 7 and self.option == 3:
            self.on_start = False
            if self.on_improve:
                avg,_ = get_avg(turn_context.activity.text)
                studytime,activities,internet,freetime,health,absences = avg

                mydict = {
                    'studytime': studytime,
                    'activities': activities,
                    'internet': internet,
                    'freetime': freetime,
                    'health': health,
                }
                sorted(mydict.items(), key=lambda x: x[1])
                # print(mydict)
                
                send_text = MessageFactory.text(f"We suggest you spend more time on { list(mydict.keys())[0] }")
                return await turn_context.send_activity(send_text)
            self.on_improve = True
            send_text = MessageFactory.text("Choose score you want to look at?")
            send_text.suggested_actions = SuggestedActions(
            actions=[
                CardAction(
                        title="A",
                        type=ActionTypes.im_back,
                        value="A"
                    ),
                    CardAction(
                        title="B",
                        type=ActionTypes.im_back,
                        value="B"
                    ),
                    CardAction( 
                        title="C",
                        type=ActionTypes.im_back,
                        value="C"
                    ),
                    CardAction(
                        title="D",
                        type=ActionTypes.im_back,
                        value="D"
                    ),
                    CardAction(
                        title="F",
                        type=ActionTypes.im_back,
                        value="F"
                    ),
                ]
            )
            return await turn_context.send_activity(send_text)
예제 #24
0
    async def _fill_out_user_profile(self, flow: ConversationFlow,
                                     profile: UserProfile,
                                     turn_context: TurnContext):
        user_input = turn_context.activity.text.strip().lower()

        #begin a conversation and ask for a significant word
        if flow.last_question_asked == Question.NONE:
            await turn_context.send_activity(
                MessageFactory.text(
                    "Let's get started. Please type a significant word !"))
            flow.last_question_asked = Question.WORD

        #validate word and ask for the response
        elif flow.last_question_asked == Question.WORD:
            validate_result = self._validate_word(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.word = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"You choose: {turn_context.activity.text.strip()} \n\nPlease Wait."
                    ))
                await turn_context.send_activities([
                    Activity(type=ActivityTypes.typing),
                    Activity(type="delay", value=2000)
                ])
                global intrus
                global liste
                #liste=closest_words(profile.word)
                most = model.most_similar(profile.word)
                liste = []
                for i in range(5):
                    liste.append(most[:5][i][0])
                sim = 1
                while sim > 0.5:
                    intrus = vocab[random.randint(1, len(vocab) - 1)]
                    if intrus in liste:
                        continue
                    meaning = dic.meaning(intrus)
                    if not meaning:
                        #wordnik api
                        continue
                    #sim=distance(profile.word,intrus)
                    sim = model.similarity(profile.word, intrus)
                liste.insert(random.randrange(len(liste)), intrus)
                card = HeroCard(
                    text=
                    "Here is the list of the words.\n\nPlease choose the intruder one!",
                    buttons=[
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[0],
                                   value=liste[0]),
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[1],
                                   value=liste[1]),
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[2],
                                   value=liste[2]),
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[3],
                                   value=liste[3]),
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[4],
                                   value=liste[4]),
                        CardAction(type=ActionTypes.im_back,
                                   title=liste[5],
                                   value=liste[5]),
                    ],
                )
                reply = MessageFactory.attachment(CardFactory.hero_card(card))
                await turn_context.send_activity(reply)
                flow.last_question_asked = Question.RESPONSE

        # validate response and wrap it up
        elif flow.last_question_asked == Question.RESPONSE:
            if user_input == "exit":
                await turn_context.send_activity(
                    MessageFactory.text(
                        "Type anything to run the Intruder Bot again."))
                flow.last_question_asked = Question.NONE
            else:
                validate_result = self._validate_result(user_input)
                if not validate_result.is_valid:
                    card = HeroCard(
                        text=validate_result.message,
                        buttons=[
                            CardAction(type=ActionTypes.im_back,
                                       title="exit",
                                       value="exit"),
                        ],
                    )
                    reply = MessageFactory.attachment(
                        CardFactory.hero_card(card))
                    await turn_context.send_activity(reply)
                    profile.score -= 1
                    await turn_context.send_activity(
                        MessageFactory.text(f"Your Score is: {profile.score}"))
                    suggested = MessageFactory.text("Chase the Intruder!")
                    suggested.suggested_actions = SuggestedActions(actions=[
                        CardAction(title=liste[0],
                                   type=ActionTypes.im_back,
                                   value=liste[0]),
                        CardAction(title=liste[1],
                                   type=ActionTypes.im_back,
                                   value=liste[1]),
                        CardAction(title=liste[2],
                                   type=ActionTypes.im_back,
                                   value=liste[2]),
                        CardAction(title=liste[3],
                                   type=ActionTypes.im_back,
                                   value=liste[3]),
                        CardAction(title=liste[4],
                                   type=ActionTypes.im_back,
                                   value=liste[4]),
                        CardAction(title=liste[5],
                                   type=ActionTypes.im_back,
                                   value=liste[5]),
                    ])
                    await turn_context.send_activity(suggested)
                else:
                    profile.response = validate_result.value
                    profile.score += 1
                    await turn_context.send_activity(
                        MessageFactory.text(
                            f"You have responded correctly.\n\nYour score is: {profile.score}\n\nThanks for completing the test."
                        ))
                    await turn_context.send_activity(
                        MessageFactory.text(
                            "Type anything to run the Intruder Bot again."))
                    flow.last_question_asked = Question.NONE