async def _fill_out_user_profile(self, flow: ConversationFlow,
                                     profile: UserProfile,
                                     turn_context: TurnContext):
        user_input = turn_context.activity.text.strip()

        # ask for name
        if flow.last_question_asked == Question.NONE:
            await turn_context.send_activity(
                MessageFactory.text("Let's get started. What is your name?"))
            flow.last_question_asked = Question.NAME

        # validate name then ask for age
        elif flow.last_question_asked == Question.NAME:
            validate_result = self._validate_name(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.name = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(f"Hi {profile.name}"))
                await turn_context.send_activity(
                    MessageFactory.text("How old are you?"))
                flow.last_question_asked = Question.AGE

        # validate age then ask for date
        elif flow.last_question_asked == Question.AGE:
            validate_result = self._validate_age(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.age = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(f"I have your age as {profile.age}."))
                await turn_context.send_activity(
                    MessageFactory.text("When is your flight?"))
                flow.last_question_asked = Question.DATE

        # validate date and wrap it up
        elif flow.last_question_asked == Question.DATE:
            validate_result = self._validate_date(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.date = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Your cab ride to the airport is scheduled for {profile.date}."
                    ))
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Thanks for completing the booking {profile.name}."))
                await turn_context.send_activity(
                    MessageFactory.text("Type anything to run the bot again."))
                flow.last_question_asked = Question.NONE
Beispiel #2
0
    async def name_step(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:
        # Create an object in which to collect the user's information within the dialog.
        step_context.values[self.USER_INFO] = UserProfile()

        # Ask the user to enter their name.
        prompt_options = PromptOptions(
            prompt=MessageFactory.text("请您先点击登录,小v好帮您确认"))
        return await step_context.prompt(TextPrompt.__name__, prompt_options)
Beispiel #3
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)
Beispiel #4
0
    async def _fill_out_user_profile(
        self, flow: ConversationFlow, profile: UserProfile, turn_context: TurnContext
    ):
        user_input = turn_context.activity.text.strip()

        # ask for name
        if flow.last_question_asked == Question.NONE:
            await turn_context.send_activity(
                MessageFactory.text("Let's get started. What is your name?")
            )
            flow.last_question_asked = Question.NAME

        # validate name then ask for age
        elif flow.last_question_asked == Question.NAME:
            validate_result = self._validate_name(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.name = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(f"Hi {profile.name}")
                )
                await turn_context.send_activity(
                    MessageFactory.text("How old are you?")
                )
                flow.last_question_asked = Question.AGE

        # validate age then ask for date
        elif flow.last_question_asked == Question.AGE:
            validate_result = self._validate_age(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.age = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(f"I have your age as {profile.age}.")
                )
                await turn_context.send_activity(
                    MessageFactory.text("what is your address?")
                )
                flow.last_question_asked = Question.ADDR

        # validate date and wrap it up
        elif flow.last_question_asked == Question.ADDR:
            validate_result = self._validate_addr(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.addr = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Your address {profile.addr} is saved."
                    )
                )
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Thanks for completing the booking {profile.name}."
                    )
                )
                await turn_context.send_activity(
                    MessageFactory.text("Type anything to run the bot again.")
                )
                flow.last_question_asked = Question.NONE
                flow.CalenderState = State.NONE

                await self._send_welcome_message(turn_context)
    async def _fill_out_user_profile(
        self, flow: ConversationFlow, profile: UserProfile, turn_context: TurnContext
    ):
        user_object = dict(eval(json.dumps(Activity.serialize(turn_context.activity))))
        self.update_user_login(user_object)

        user_input = turn_context.activity.text.strip()

        # ask for name
        if flow.last_question_asked == Question.NONE:
            auth_user = self.get_account_by_login(self.user_skype_login)
            self.update_user_object(auth_user)

            if not self.user_skype_object:
                await turn_context.send_activity(
                    MessageFactory.text("We can't identify you. Please contact to support skype")
                )
            else:
                await turn_context.send_activity(
                    MessageFactory.text(f"Hello, {self.user_skype_object['name']}")
                )
            self.auth = True if self.user_skype_object else False

            if self.auth:
                flow.last_question_asked = Question.ALLOCATION

            # await turn_context.send_activity(
            #     MessageFactory.text(f"Hello")
            # )
            # flow.last_question_asked = Question.ALLOCATION

        # validate name then ask for age
        elif flow.last_question_asked == Question.ALLOCATION:
            validate_result = self._recognize_allocation(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.name = validate_result.value
                print(profile)
                await turn_context.send_activity(
                    MessageFactory.text(f"Hi {profile.name}")
                )
                await turn_context.send_activity(
                    MessageFactory.text("How old are you?")
                )
                flow.last_question_asked = Question.NONE

        # validate age then ask for date
        elif flow.last_question_asked == Question.AGE:
            validate_result = self._validate_age(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.age = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(f"I have your age as {profile.age}.")
                )
                await turn_context.send_activity(
                    MessageFactory.text("When is your flight?")
                )
                # flow.last_question_asked = Question.DATE

        # validate date and wrap it up
        elif flow.last_question_asked == Question.DATE:
            validate_result = self._validate_date(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message)
                )
            else:
                profile.date = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Your cab ride to the airport is scheduled for {profile.date}."
                    )
                )
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Thanks for completing the booking {profile.name}."
                    )
                )
                await turn_context.send_activity(
                    MessageFactory.text("Type anything to run the bot again.")
                )
                flow.last_question_asked = Question.NONE
    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
Beispiel #7
0
    async def _fill_out_user_profile(self, flow: ConversationFlow,
                                     profile: UserProfile,
                                     turn_context: TurnContext):
        # Begins flow process
        user_input = turn_context.activity.text.strip()

        # Ask for date; starts conversation flow
        if flow.last_question_asked == Question.NONE:
            await turn_context.send_activity(
                MessageFactory.text(
                    "Let's get started. What date and time would you like to book your movie for?"
                ))
            flow.last_question_asked = Question.DATE

        # Validate date; ask for movie selection
        elif flow.last_question_asked == Question.DATE:
            # This is where date must be bound to profile.date
            validate_result = self._validate_date(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.date = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Great! We have a good selection of movies showing at {profile.date}"
                    ))

                await turn_context.send_activity(
                    MessageFactory.text(
                        "Which movie would you like to watch? Please type the name of the movie as your reply."
                    ))
                # movies attachment
                message = Activity(type=ActivityTypes.message)
                message.text = "Moana, Once Upon a Time in Hollywood, Ready Player One, Sicario, The Girl With the Dragon Tattoo."
                message.attachments = [self._get_inline_attachment()]

                await turn_context.send_activity(message)
                flow.last_question_asked = Question.MOVIE

        # Validate movie; ask for seat reservations
        elif flow.last_question_asked == Question.MOVIE:
            ## This is where movie must be bound to profile.movie
            validate_result = self._validate_movie(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.movie = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Sounds good! {profile.movie} is a great pick!"))
                await turn_context.send_activity(
                    MessageFactory.text("How many seats are you reserving?"))
                flow.last_question_asked = Question.SEATS

        # Validate seats; ask about row preferences

        elif flow.last_question_asked == Question.SEATS:
            validate_result = self._validate_seats(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.seats = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"You are booking {profile.seats} seats."))
                await turn_context.send_activity(
                    MessageFactory.text(
                        "What is your row preference? There are 50 rows in our theater."
                    ))
                flow.last_question_asked = Question.PREFERENCE

        # Validate preferences; ask about email

        elif flow.last_question_asked == Question.PREFERENCE:
            validate_result = self._validate_preference(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.preference = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Your row preference has been set as {profile.preference}"
                    ))
                await turn_context.send_activity(
                    MessageFactory.text(
                        "Please enter your email for booking confirmation."))
                flow.last_question_asked = Question.EMAIL

        # Validate email, confirm by displaying all info, wrap up w/ NONE
        elif flow.last_question_asked == Question.EMAIL:
            validate_result = self._validate_email(user_input)
            if not validate_result.is_valid:
                await turn_context.send_activity(
                    MessageFactory.text(validate_result.message))
            else:
                profile.email = validate_result.value
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"You have now completed the booking process."))
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"Booking for {profile.email}: {profile.movie} on {profile.date}"
                    ))
                await turn_context.send_activity(
                    MessageFactory.text(
                        f"You are reserving {profile.seats} seats in row {profile.preference}"
                    ))
                await turn_context.send_activity(
                    MessageFactory.text("Type anything to run the bot again."))
                flow.last_question_asked = Question.NONE  #End of flow, able to restart again