def __init__(self, conversation_state: ConversationState, skills_config: SkillConfiguration): super(SetupDialog, self).__init__(SetupDialog.__name__) self._delivery_mode_property = conversation_state.create_property( DELIVERY_MODE_PROPERTY_NAME) self._active_skill_property = conversation_state.create_property( ACTIVE_SKILL_PROPERTY_NAME) self._delivery_mode = "" self._skills_config = skills_config # Define the setup dialog and its related components. # Add ChoicePrompt to render available skills. self.add_dialog(ChoicePrompt(self.select_delivery_mode_step.__name__)) self.add_dialog(ChoicePrompt(self.select_skill_step.__name__)) self.add_dialog(TextPrompt(self.final_step.__name__)) # Add main waterfall dialog for this bot. self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.select_delivery_mode_step, self.select_skill_step, self.final_step, ], )) self.initial_dialog_id = WaterfallDialog.__name__
async def test_should_not_recognize_if_choices_are_not_passed_in(self): async def exec_test(turn_context: TurnContext): dc = await dialogs.create_context(turn_context) results: DialogTurnResult = await dc.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text='Please choose a color.'), choices=None ) await dc.prompt('prompt', options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property('dialogState') dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt('prompt') choice_prompt.style = ListStyle.none dialogs.add(choice_prompt) step1 = await adapter.send('Hello') step2 = await step1.assert_reply('Please choose a color.')
async def test_should_create_prompt_with_list_choices_when_specified(self): async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) results: DialogTurnResult = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text="Please choose a color."), choices=_color_choices, ) await dialog_context.prompt("prompt", options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property("dialogState") dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt("prompt") choice_prompt.style = ListStyle.list_style dialogs.add(choice_prompt) step1 = await adapter.send("Hello") step2 = await step1.assert_reply( "Please choose a color.\n\n 1. red\n 2. green\n 3. blue") step3 = await step2.send(_answer_message) await step3.assert_reply("red")
async def test_should_create_prompt_with_inline_choices_when_specified(self): async def exec_test(turn_context: TurnContext): dc = await dialogs.create_context(turn_context) results: DialogTurnResult = await dc.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text='Please choose a color.'), choices=_color_choices ) await dc.prompt('prompt', options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property('dialogState') dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt('prompt') choice_prompt.style = ListStyle.in_line dialogs.add(choice_prompt) step1 = await adapter.send('Hello') step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, or (3) blue') step3 = await step2.send(_answer_message) await step3.assert_reply('red')
def __init__(self, dialog_id: str = None): super(SymptomsSelectionDialog, self).__init__( dialog_id or SymptomsSelectionDialog.__name__ ) self.SYMPTOMS_SELECTED = "value-symptomsSelected" self.SYMPTOMS_DATES = "value-symptomsDates" self.DONE_OPTION = "Keins" self.symptom_options = [ "Husten", "Fieber", "Schnupfen", "Kopfschmerzen", "Lungenentzündung", ] choice = ChoicePrompt(ChoicePrompt.__name__) choice.recognizer_options = FindChoicesOptions(allow_partial_matches=True) self.add_dialog(choice) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [self.selection_step, self.loop_step, self.save_step] ) ) self.add_dialog(DateTimePrompt(DateTimePrompt.__name__)) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, client: GraphClient, dialog_id: str = None): """inits a PersonDialog instance Args: client (GraphClient): MS Graph client instance associated with this dialog. Used to perform all calls to the Graph API dialog_id (str): a unique name identifying specific dialog. """ super().__init__(dialog_id or PersonDialog.__name__) self.DONE_OPTION = "завершить" self.EXCEL_LINK = "" self.SITE_ID = "tikkurila.sharepoint.com,a6aa1089-0ccd-4edc-be69-03d4dc4aabc2,a5a516d4-962c-4663-89e8-424aabecfcf8" self.DRIVE_ID = "b!iRCqps0M3E6-aQPU3EqrwtQWpaUslmNGiehCSqvs_PjR9APmWaAIRJ2s7cN4zjqu" self.selected_keys = [] self.client = client self.json_path = None self.options_list = ["ФАО", "Бухгалтерия", self.DONE_OPTION] self.add_dialog(ChoicePrompt('level1')) self.add_dialog(ChoicePrompt('level2')) self.add_dialog(ChoicePrompt('level3')) self.add_dialog(ChoicePrompt('level4')) self.add_dialog( WaterfallDialog("WFDiag", [ self.dep_step, self.type_step, self.subtype_step, self.lvl4_step, self.final_step, ])) self.initial_dialog_id = "WFDiag"
def __init__(self, dialog_id: str = None): super(RiskCountrySelectionDialog, self).__init__(dialog_id or RiskCountrySelectionDialog.__name__) self.RISK_COUNTRIES_SELECTED = "value-symptomsSelected" self.RISK_COUNTRIES_DATES = "value-symptomsDates" self.DONE_OPTION = "**Keine**" self.riskcountry_options = [ "Ägypten", "Hubei (China)", "Region Grand Est (Frankreich)", "Iran", "Italien", "Tirol (Österreich)", "Madrid (Spanien)", "Gyeongsangbuk-do (Südkorea)", "Kalifornien, Washington oder New York (USA)", ] choice = ChoicePrompt(ChoicePrompt.__name__) choice.recognizer_options = FindChoicesOptions( allow_partial_matches=True) self.add_dialog(choice) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [self.selection_step, self.loop_step, self.save_step])) self.add_dialog(DateTimePrompt(DateTimePrompt.__name__)) self.initial_dialog_id = WaterfallDialog.__name__
async def test_should_display_choices_on_hero_card_with_additional_attachment(self): size_choices = ["large", "medium", "small"] card = CardFactory.adaptive_card( { "type": "AdaptiveCard", "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.2", "body": [], } ) card_activity = Activity(attachments=[card]) async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) results: DialogTurnResult = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions(prompt=card_activity, choices=size_choices) await dialog_context.prompt("prompt", options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) def assert_expected_activity( activity: Activity, description ): # pylint: disable=unused-argument assert len(activity.attachments) == 2 assert ( activity.attachments[0].content_type == CardFactory.content_types.adaptive_card ) assert ( activity.attachments[1].content_type == CardFactory.content_types.hero_card ) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property("dialogState") dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt("prompt") # Change the ListStyle of the prompt to ListStyle.none. choice_prompt.style = ListStyle.hero_card dialogs.add(choice_prompt) step1 = await adapter.send("Hello") await step1.assert_reply(assert_expected_activity)
async def test_should_display_choices_on_hero_card(self): size_choices = ["large", "medium", "small"] async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) results: DialogTurnResult = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity( type=ActivityTypes.message, text="Please choose a size." ), choices=size_choices, ) await dialog_context.prompt("prompt", options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) def assert_expected_activity( activity: Activity, description ): # pylint: disable=unused-argument assert len(activity.attachments) == 1 assert ( activity.attachments[0].content_type == CardFactory.content_types.hero_card ) assert activity.attachments[0].content.text == "Please choose a size." adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property("dialogState") dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt("prompt") # Change the ListStyle of the prompt to ListStyle.none. choice_prompt.style = ListStyle.hero_card dialogs.add(choice_prompt) step1 = await adapter.send("Hello") step2 = await step1.assert_reply(assert_expected_activity) step3 = await step2.send("1") await step3.assert_reply(size_choices[0])
def __init__(self, client: GraphClient, dialog_id: str): """inits a HKDialog instance Args: client (GraphClient): MS Graph client instance associated with this dialog. Used to perform all calls to the Graph API dialog_id (str): a unique name identifying specific dialog. """ super().__init__(dialog_id or HKDialog.__name__) self.DONE_OPTION = 'завершить' self.LAST_OPTION = 'свежий' self.SELECTED_CHANNEL = 'value-selectedChannel' self.DRIVE_ID = "b!iRCqps0M3E6-aQPU3EqrwtQWpaUslmNGiehCSqvs_PgkFFzTCYK_Sa7Y0KpehzLj" self.SITE_ID = "tikkurila.sharepoint.com,a6aa1089-0ccd-4edc-be69-03d4dc4aabc2,a5a516d4-962c-4663-89e8-424aabecfcf8" self.client = client self._query = "" self._max_period = "" self.options_list = { "Деко": "Deco", "Индастри": "Industry", self.DONE_OPTION: self.DONE_OPTION, } self.add_dialog(ChoicePrompt('channels')) self.add_dialog(TextPrompt('dates', HKDialog.query_validator)) self.add_dialog( WaterfallDialog("WFDiag", [ self.channel_step, self.dates_step, self.final_step, ])) self.initial_dialog_id = "WFDiag"
def __init__(self, user_state: UserState, storage: object): super(CreateDeliveryDialog, self).__init__(CreateDeliveryDialog.__name__) self.user_state = user_state self.did_show_entry_msg = False self.storage = storage self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog(TextPrompt(TextPrompt.__name__)) self.add_dialog(DateTimePrompt(DateTimePrompt.__name__)) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.add_dialog( WaterfallDialog( Keys.WATER_FALL_DIALOG_ID.value, [ self.item_step, self.destination_step, self.time_step, self.confirm_step, self.acknowledgement_step ], ) ) self.initial_dialog_id = Keys.WATER_FALL_DIALOG_ID.value
def __init__(self, user_state: UserState, luis_recognizer: InsuranceQueryRecognizer, insurance_renewal_dialog: InsuranceRenewalDialog, reservation_booking_dialog: ReservationBookingDialog): super(MainDialog, self).__init__(MainDialog.__name__) self.qna_maker = QnAMaker( QnAMakerEndpoint(knowledge_base_id=config.QNA_KNOWLEDGEBASE_ID, endpoint_key=config.QNA_ENDPOINT_KEY, host=config.QNA_ENDPOINT_HOST)) self.user_profile_accessor = user_state.create_property("UserData") self.insurance_renewal_dialog_id = insurance_renewal_dialog.id self.reservation_booking_dialog_id = reservation_booking_dialog.id self._luis_recognizer = luis_recognizer self.user_state = user_state self.add_dialog(TextPrompt(TextPrompt.__name__)) self.add_dialog(ChoicePrompt(INS_PROMPT_OPTIONS)) self.add_dialog(insurance_renewal_dialog) self.add_dialog(reservation_booking_dialog) self.add_dialog( WaterfallDialog("WFDialog", [ self.intro_step, self.name_process_step, self.luis_query_step, self.closing_step ])) self.initial_dialog_id = "WFDialog"
def __init__(self, user_state: UserState): super(WaterfallMain, self).__init__(WaterfallMain.__name__) self.user_profile_accessor = user_state.create_property("UserProfile") luisRecognizer = CalcoloImportoRecognizer(configuration=DefaultConfig) calcoloDialog = CalcoloDialog() cancellaDialogo = CancellaDialogo() self.add_dialog( WaterfallQuery(luis_recognizer=luisRecognizer, calcolo_dialog=calcoloDialog, cancella_dialogo=cancellaDialogo)) self.add_dialog(WaterfallPhoto(WaterfallPhoto.__name__)) self.add_dialog(WaterfallText(WaterfallText.__name__)) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.what_step, self.summary_step, self.replace_step, ], )) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, dialog_id: str = None): super(ContactsSelectionDialog, self).__init__( dialog_id or ContactsSelectionDialog.__name__ ) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.confirm_confirmedcasecontact_step, self.date_confirmedcasecontact_step, self.confirm_suspectedcasecontact_step, self.date_suspectedcasecontact_step, self.contacts_dates_step] ) ) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog( NumberPrompt(NumberPrompt.__name__) ) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.add_dialog(DateTimePrompt(DateTimePrompt.__name__)) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, user_state: UserState): super(UserProfileDialog, self).__init__(UserProfileDialog.__name__) self.user_profile_accessor = user_state.create_property("UserProfile") self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.transport_step, self.name_step, self.name_confirm_step, self.age_step, self.picture_step, self.confirm_step, self.summary_step, ], )) self.add_dialog(TextPrompt(TextPrompt.__name__)) self.add_dialog( NumberPrompt(NumberPrompt.__name__, UserProfileDialog.age_prompt_validator)) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.add_dialog( AttachmentPrompt(AttachmentPrompt.__name__, UserProfileDialog.picture_prompt_validator)) self.initial_dialog_id = WaterfallDialog.__name__
async def test_should_recognize_valid_number_choice(self): async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) results: DialogTurnResult = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text="Please choose a color."), choices=_color_choices, ) await dialog_context.prompt("prompt", options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property("dialogState") dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt("prompt") dialogs.add(choice_prompt) step1 = await adapter.send("Hello") step2 = await step1.assert_reply( "Please choose a color. (1) red, (2) green, or (3) blue") step3 = await step2.send("1") await step3.assert_reply("red")
def __init__(self, luis_recognizer: CalcoloImportoRecognizer, calcolo_dialog: CalcoloDialog, cancella_dialogo: CancellaDialogo): super(WaterfallQuery, self).__init__(WaterfallQuery.__name__) #self.user_profile_accessor = user_state.create_property("UserProfile") self._luis_recognizer = luis_recognizer self._calcolo_dialog_id = calcolo_dialog.id self._cancella_dialogo_id = cancella_dialogo.id self.add_dialog(cancella_dialogo) self.add_dialog(calcolo_dialog) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.domanda_step, self.summary_step, ], )) self.add_dialog(TextPrompt(TextPrompt.__name__)) #self.add_dialog(TextPrompt(TextPrompt.__name__, WaterfallQuery.insertCorrectdate)) self.add_dialog(NumberPrompt(NumberPrompt.__name__)) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) """self.add_dialog( AttachmentPrompt( AttachmentPrompt.__name__, WaterfallQuery.picture_prompt_validator ) )""" self.initial_dialog_id = WaterfallDialog.__name__
async def test_should_call_ChoicePrompt_using_dc_prompt(self): async def exec_test(turn_context: TurnContext): dc = await dialogs.create_context(turn_context) results: DialogTurnResult = await dc.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text='Please choose a color.'), choices=_color_choices ) await dc.prompt('ChoicePrompt', options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) # Initialize TestAdapter. adapter = TestAdapter(exec_test) # Create new ConversationState with MemoryStorage and register the state as middleware. convo_state = ConversationState(MemoryStorage()) # Create a DialogState property, DialogSet, and ChoicePrompt. dialog_state = convo_state.create_property('dialogState') dialogs = DialogSet(dialog_state) choice_prompt = ChoicePrompt('ChoicePrompt') dialogs.add(choice_prompt) step1 = await adapter.send('hello') step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, or (3) blue') step3 = await step2.send(_answer_message) await step3.assert_reply('red')
def __init__(self, user_state: UserState): super(UserProfileDialog, self).__init__(UserProfileDialog.__name__) self.user_profile_accessor = user_state.create_property("UserProfile") self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.first_step, self.second_step, self.third_step, self.fourth_step, self.fifth_step, self.sixth_step, self.seventh_step, self.eighth_step, ], )) self.add_dialog(TextPrompt(TextPrompt.__name__)) self.add_dialog( NumberPrompt(NumberPrompt.__name__, UserProfileDialog.age_prompt_validator)) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.add_dialog( AttachmentPrompt(AttachmentPrompt.__name__, UserProfileDialog.picture_prompt_validator)) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, conversation: ConversationState): self.con_statea = conversation self.state_prop = self.con_statea.create_property("dialog_set") self.dialog_set = DialogSet(self.state_prop) self.dialog_set.add(ChoicePrompt(ChoicePrompt.__name__)) self.dialog_set.add( WaterfallDialog("main_dialog", [self.DisplayChoiceList, self.ReadResult]))
def __init__(self): super().__init__("MainDialog") # Define the main dialog and its related components. self.add_dialog(ChoicePrompt(CARD_PROMPT)) self.add_dialog( WaterfallDialog(MAIN_WATERFALL_DIALOG, [self.choice_card_step, self.show_card_step])) # The initial child Dialog to run. self.initial_dialog_id = MAIN_WATERFALL_DIALOG
def __init__(self, user_state: UserState, dialog_id: str): """inits the TopLevelDialog instance. Args: user_state (UserState): user state storage object. Each user bot communicates with will have its own isolated storage object that can be used to persist information about the user across the entire conversation(s) with that user. dialog_id (str): a unique name identifying specific dialog. """ super(TopLevelDialog, self).__init__(dialog_id or TopLevelDialog.__name__) self.SELECTED_WAY = "value-selectedWay" self.DONE_OPTION = "Завершить" self.client = GraphClient() self.user_state = user_state self.options_dict = { 'bdg': ("Текущее состояние бюджета (WIP)", "", None), 'hk': ("Отчеты Химкурьер", HKDialog.__name__, None), 'links': ("Полезные ссылки", LinksDialog.__name__, None), 'stocks': ("Котировки акций Tikkurila", StocksDialog.__name__, None), 'person': ("Не знаю, к кому обратиться с вопросом", PersonDialog.__name__, None), 'autoreply': ('Хочу поставить красивый автоответ', AutoreplyDialog.__name__, "UserProfile"), } self.ways_options = [ self.options_dict[key][0] for key in self.options_dict ] + [self.DONE_OPTION] self.add_dialog(ChoicePrompt("top_level_choice")) self.add_dialog(LinksDialog(LinksDialog.__name__)) self.add_dialog(StocksDialog(StocksDialog.__name__)) self.add_dialog(HKDialog(self.client, HKDialog.__name__)) self.add_dialog(PersonDialog(self.client, PersonDialog.__name__)) self.add_dialog( AutoreplyDialog(self.user_state, self.client, AutoreplyDialog.__name__)) self.add_dialog( WaterfallDialog( "top_level_WFDialog", [ self.selection_step, self.branching_step, self.end_step, ], )) self.initial_dialog_id = "top_level_WFDialog"
def __init__(self, dialog_id: str = None, menu_str: str = None): super(CardDialog, self).__init__(dialog_id or CardDialog.__name__) self.prompt = menu_str self.options = menu_str.split() self.DONE_OPTION = 0 self.sub_action_options = [int(i[1:4]) for i in self.options[:-1]] self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog( WaterfallDialog(WaterfallDialog.__name__, [self.selection_step, self.loop_step])) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, dialog_id: str = None, new_country=True): super(HealthSelectionDialog, self).__init__(dialog_id or HealthSelectionDialog.__name__) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog( WaterfallDialog(WaterfallDialog.__name__, [self.selection_step, self.loop_step])) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, dialog_id: str = None): super(ServiceSelectionDialog, self).__init__(dialog_id or ServiceSelectionDialog.__name__) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog( WaterfallDialog(WaterfallDialog.__name__, [self.selection_step, self.loop_step])) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, conversation: ConversationState): self.con_statea = conversation self.state_prop = self.con_statea.create_property("dialog_set") self.dialog_set = DialogSet(self.state_prop) self.dialog_set.add(TextPrompt("text_prompt")) self.dialog_set.add(NumberPrompt("number_prompt")) self.dialog_set.add(ChoicePrompt(ChoicePrompt.__name__)) self.dialog_set.add( WaterfallDialog("main_dialog", [ self.GetUserName, self.DisplayChoiceList, self.GetProblem, self.waitAgent, self.Completed ]))
def __init__(self, user_state: UserState): super(OrderDialog, self).__init__(OrderDialog.__name__) self.current_order: Order = None self.order_list: List[Order] = list() self.user_profile_accesor = user_state.create_property("UserProfile") self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [ self.options_step, self.interpret_user_intention, self.goodbye_step, ], )) self.add_dialog(ChoicePrompt("options_step")) self.add_dialog(TextPrompt("interpret_user_intention")) self.add_dialog(ChoicePrompt(ChoicePrompt.__name__)) self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.initial_dialog_id = WaterfallDialog.__name__ self.add_dialog(TextPrompt(TextPrompt.__name__))
def __init__(self, configuration: DefaultConfig): super().__init__(CardDialog.__name__) self.configuration = configuration self.add_dialog( ChoicePrompt(ChoicePrompt.__name__, self.card_prompt_validator)) self.add_dialog( WaterfallDialog( WaterfallDialog.__name__, [self.select_card_step, self.display_card_step], )) self.initial_dialog_id = WaterfallDialog.__name__
async def test_should_send_ignore_retry_prompt_if_validator_replies(self): async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) results: DialogTurnResult = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity( type=ActivityTypes.message, text="Please choose a color." ), retry_prompt=Activity( type=ActivityTypes.message, text="Please choose red, blue, or green.", ), choices=_color_choices, ) await dialog_context.prompt("prompt", options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property("dialogState") dialogs = DialogSet(dialog_state) async def validator(prompt: PromptValidatorContext) -> bool: assert prompt if not prompt.recognized.succeeded: await prompt.context.send_activity("Bad input.") return prompt.recognized.succeeded choice_prompt = ChoicePrompt("prompt", validator) dialogs.add(choice_prompt) step1 = await adapter.send("Hello") step2 = await step1.assert_reply( "Please choose a color. (1) red, (2) green, or (3) blue" ) step3 = await step2.send(_invalid_message) step4 = await step3.assert_reply("Bad input.") step5 = await step4.send(_answer_message) await step5.assert_reply("red")
async def test_should_use_default_locale_when_rendering_choices(self): async def exec_test(turn_context: TurnContext): dc = await dialogs.create_context(turn_context) results: DialogTurnResult = await dc.continue_dialog() if results.status == DialogTurnStatus.Empty: options = PromptOptions( prompt=Activity(type=ActivityTypes.message, text='Please choose a color.'), choices=_color_choices ) await dc.prompt('prompt', options) elif results.status == DialogTurnStatus.Complete: selected_choice = results.result await turn_context.send_activity(selected_choice.value) await convo_state.save_changes(turn_context) adapter = TestAdapter(exec_test) convo_state = ConversationState(MemoryStorage()) dialog_state = convo_state.create_property('dialogState') dialogs = DialogSet(dialog_state) async def validator(prompt: PromptValidatorContext) -> bool: assert prompt if not prompt.recognized.succeeded: await prompt.context.send_activity('Bad input.') return prompt.recognized.succeeded choice_prompt = ChoicePrompt( 'prompt', validator, default_locale=Culture.Spanish ) dialogs.add(choice_prompt) step1 = await adapter.send(Activity(type=ActivityTypes.message, text='Hello')) # TODO ChoiceFactory.inline() is broken, where it only uses hard-coded English locale. # commented out the CORRECT assertion below, until .inline() is fixed to use proper locale # step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, o (3) blue') step2 = await step1.assert_reply('Please choose a color. (1) red, (2) green, or (3) blue') step3 = await step2.send(_invalid_message) step4 = await step3.assert_reply('Bad input.') step5 = await step4.send(Activity(type=ActivityTypes.message, text='red')) await step5.assert_reply('red')