async def select_third(self, step_context: WaterfallStepContext) -> DialogTurnResult: result = step_context.result selected = step_context.values["selected"] categories = step_context.values["categories"] for i,c in enumerate(categories): if result.lower()==c.name.lower(): selected.append(c) del categories[i] step_context.values["selected"] = selected step_context.values["categories"] = categories break card=self.create_card(step_context) message_text = ("Hai selezionato correttamente la categoria {}".format(result)) message = MessageFactory.text(message_text, message_text, InputHints.ignoring_input) await step_context.context.send_activity(message) return await step_context.prompt( TextPrompt.__name__, PromptOptions( prompt = MessageFactory.attachment(card), retry_prompt= MessageFactory.text("Inserisci una categoria valida.") ) )
async def third_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: step_context.values["get_employee_id"] = False if step_context.values['employee_id'] == 'Required': if step_context.result != True: #step_context.values["name"] = step_context.result # We can send messages to the user at any point in the WaterfallStep. await step_context.context.send_activity( MessageFactory.text( f"You need to get your employee Id created first")) step_context.values["get_employee_id"] = True get_employee_id = step_context.values["get_employee_id"] # WaterfallStep always finishes with the end of the Waterfall or # with another dialog; here it is a Prompt Dialog. return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=MessageFactory.text( "Would you like me to put in a request to HR to get your employee Id created" )), ) else: step_context.values["get_employee_id"] = False return await step_context.prompt( TextPrompt.__name__, PromptOptions(prompt=MessageFactory.text( "Please Provide Your Employee ID.")), ) return await step_context.next(1)
async def Completed(self, waterfall_step: WaterfallStepContext): contacted = waterfall_step.result.value name = waterfall_step.values["name"] problem = waterfall_step.values["problem"] choiceoption = waterfall_step.values["choiceoption"] if (contacted == "Sí"): waterfall_step.values["contacted"] = True else: waterfall_step.values["contacted"] = False contactbool = waterfall_step.values["contacted"] await waterfall_step._turn_context.send_activity( "Gracias por utilizar nuestros servicios") profileinfo = f"Name : {name} , Choice: {choiceoption}, Problem : {problem}, Contactado: {contactbool}" await waterfall_step._turn_context.send_activity(profileinfo) set_list = site.List('list') my_data = data = [{ 'name': name, 'tipo': choiceoption, 'detalle': problem }] set_list.UpdateListItems(data=my_data, kind='New') return await waterfall_step.end_dialog()
async def login_step(self, step_context: WaterfallStepContext): # Get the token from the previous step. token_response = step_context.result if token_response: # Workaround, step_context.result value using DirectLine returns a 'dict' instead of TokenResponse if isinstance(token_response, dict): step_context.values["token"] = token_response.get("token") else: step_context.values["token"] = token_response.token # Show the token logged_in_message = "You are now logged in." await step_context.context.send_activity( MessageFactory.text(logged_in_message, logged_in_message, InputHints.ignoring_input)) options = PromptOptions(prompt=MessageFactory.text( "Would you like to view your token?")) return await step_context.prompt(ConfirmPrompt.__name__, options) try_again_message = "Login was not successful please try again." await step_context.context.send_activity( MessageFactory.text(try_again_message, try_again_message, InputHints.ignoring_input)) return await step_context.replace_dialog(self.initial_dialog_id)
async def _final_step(self, step_context: WaterfallStepContext): """ The SkillDialog has ended, render the results (if any) and restart MainDialog. """ active_skill = await self.active_skill_property.get( step_context.context) # Check if the skill returned any results and display them. if step_context.result: message = f'Skill "{active_skill.id}" invocation complete.' message += f" Result: {json.dumps(step_context.result)}" await step_context.context.send_activity( MessageFactory.text(message, message, InputHints.ignoring_input)) # Clear the delivery mode selected by the user. step_context.values[DELIVERY_MODE_NAME] = None # Clear the skill selected by the user. step_context.values[SELECTED_SKILL_KEY_NAME] = None # Clear active skill in state. await self.active_skill_property.delete(step_context.context) # Restart the main dialog with a different message the second time around. return await step_context.replace_dialog( self.initial_dialog_id, f'Done with "{active_skill.id}". \n\n What delivery mode would you ' f"like to use?", )
async def select_first(self, step_context: WaterfallStepContext) -> DialogTurnResult: step_context.values["categories"] = CATEGORIES step_context.values["selected"] = [] card=self.create_card(step_context) return await step_context.prompt( TextPrompt.__name__, PromptOptions( prompt = MessageFactory.attachment(card), retry_prompt= MessageFactory.text("Inserisci una categoria valida.") ) )
async def prompt_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: message_text = "Quale libro vuoi cercare?" step_context.values["books"] = [] step_context.values["amazonLink"] = None prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) return await step_context.prompt( "TextPromptLibro", PromptOptions( prompt=prompt_message, retry_prompt=MessageFactory.text( '''Quale libro vuoi cercare? Il nome del libro deve avere lunghezza compresa tra 3 e 50''' )))
async def final_step(self, step_context: WaterfallStepContext) -> DialogTurnResult: try: skip = step_context.values["skip"] except KeyError: skip = False step_context.values["skip"] =False if not skip: message_text = "Posso fare qualcos'altro per te?" prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=prompt_message) ) else: step_context.values["skip"] = False return await step_context.next(True)
async def GetProblem(self, waterfall_step: WaterfallStepContext): choiceoption = waterfall_step.result.value if (choiceoption == "A"): waterfall_step.values["choiceoption"] = "No puedo iniciar sesión" elif (choiceoption == "B"): waterfall_step.values[ "choiceoption"] = "Tengo problemas con un sistema" elif (choiceoption == "C"): waterfall_step.values[ "choiceoption"] = "Tengo problemas con mi computadora" return await waterfall_step.prompt( "text_prompt", PromptOptions( prompt=MessageFactory.text("Describa el problema brevemente")))
async def GetMobileNumber(self, waterfall_step: WaterfallStepContext): name = waterfall_step._turn_context.activity.text waterfall_step.values["name"] = name return await waterfall_step.prompt( "number_prompt", PromptOptions( prompt=MessageFactory.text("Please enter the mobile no")))
async def GetReporterId(self, waterfall_step: WaterfallStepContext): name = waterfall_step._turn_context.activity.text waterfall_step.values["name"] = name return await waterfall_step.prompt( "text_prompt", PromptOptions( prompt=MessageFactory.text("Please enter the reporter ID")))
async def confirm_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: if step_context.result: image = step_context.result[0] res: Response = requests.get(image.content_url) await step_context.context.send_activity("Sto analizzando...") dati_scontrino = FormRecognizer.runAnalysis( input_file=BytesIO(res.content), file_type=image.content_type) if dati_scontrino is None: await step_context.context.send_activity("C'è stato un problema") return await step_context.end_dialog() step_context.values["dati_scontrino"] = dati_scontrino data = dati_scontrino['data'] tempData = str(data).replace("-", "") data = datetime.strptime(tempData, '%Y%m%d').strftime('%d-%m-%Y') # WaterfallStep always finishes with the end of the Waterfall or # with another dialog; here it is a Prompt Dialog. return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=MessageFactory.text( f"Dalla foto ho rilevato l'importo {dati_scontrino['totale']}€ in data {data} è corretto?" )), )
async def _choose_person( self, step_context: WaterfallStepContext) -> DialogTurnResult: user_profile: UserProfile = await self.user_profile_accessor.get( step_context.context, UserProfile) user = user_dao.get_user_by_id(user_profile.id) if not user: await step_context.context.send_activity( "Devi aggiungere almeno una persona nel Database per inizializzare il tuo account." ) return await step_context.end_dialog() step_context.values['person_group_id'] = user.person_group_id people = people_dao.retrive_people(user.person_group_id) if not people: await step_context.context.send_activity( "Non è presente alcuna persona nel Database.") return await step_context.end_dialog() people_list = [ Choice(f'{person.id}) {person.name} {person.surname}') for person in people ] return await step_context.prompt( ChoicePrompt.__name__, PromptOptions(prompt=MessageFactory.text( 'Seleziona il profilo della persona da eliminare. '), retry_prompt=MessageFactory.text( "Per favore seleziona un'opzione dalla lista."), style=ListStyle.hero_card, choices=people_list))
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)
async def summary_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: # Save if the user take the breakfast (bool) step_context.values["breakfast"] = step_context.result # If the user said "Yes": if step_context.result: # Confirm breakfast hour await step_context.context.send_activity( MessageFactory.text(f"Perfect, breakfast is from 6am to 10am")) # Save information to Reservation object room_reservation = await self.room_reservation_accessor.get( step_context.context, RoomReservation) room_reservation.people = step_context.values["people"] room_reservation.duration = step_context.values["duration"] room_reservation.breakfast = step_context.values["breakfast"] # End the dialog await step_context.context.send_activity( MessageFactory.text("Your booking has been made !")) return await step_context.end_dialog()
async def confirmation_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: """ Once a recommendation has been given, take action based on the user's feedback :param step_context: :return DialogTurnResult: """ print("Executing confirmation step") recommendation_details = step_context.options feedback = step_context.result # If the user liked the recommendation, recommend another song from the same genre if feedback: message_text = "Glad you enjoyed it!" prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) await step_context.context.send_activity(prompt_message) return await step_context.replace_dialog( RecommendationDialog.__name__, step_context.options) else: message_text = "Sorry to hear that." prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) await step_context.context.send_activity(prompt_message) step_context.options["genre"] = "" return await step_context.replace_dialog( RecommendationDialog.__name__, step_context.options)
async def GetEmailId(self, waterfall_step: WaterfallStepContext): mobile = waterfall_step._turn_context.activity.text waterfall_step.values["mobile"] = mobile return await waterfall_step.prompt( "text_prompt", PromptOptions( prompt=MessageFactory.text("PLease enter the email id")))
async def picture_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: age = step_context.result step_context.values["age"] = age msg = ("No age given." if step_context.result == -1 else f"I have your age as {age}.") # We can send messages to the user at any point in the WaterfallStep. await step_context.context.send_activity(MessageFactory.text(msg)) if step_context.context.activity.channel_id == "msteams": # This attachment prompt example is not designed to work for Teams attachments, so skip it in this case await step_context.context.send_activity( "Skipping attachment prompt in Teams channel...") return await step_context.next(None) # WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt # Dialog. prompt_options = PromptOptions( prompt=MessageFactory.text( "Please attach a profile picture (or type any message to skip)." ), retry_prompt=MessageFactory.text( "The attachment must be a jpeg/png image file."), ) return await step_context.prompt(AttachmentPrompt.__name__, prompt_options)
async def _select_picture( self, step_context: WaterfallStepContext) -> DialogTurnResult: if step_context.result: if 'image' not in step_context.result[ 0].content_type: # check if there is an image await step_context.context.send_activity( "Tipo di file non valido. Cancello tutte le operazioni in corso." ) return await step_context.cancel_all_dialogs() step_context.values['image_url'] = step_context.result[ 0].content_url return await step_context.prompt( ChoicePrompt.__name__, PromptOptions(prompt=MessageFactory.text( "Vuoi aggiungere un nuovo utente, o aggiornarne uno già presente?" ), retry_prompt=MessageFactory.text( "Per favore seleziona un'opzione dalla lista." ), choices=[Choice('Nuovo'), Choice('Esistente')])) await step_context.context.send_activity('Operazione annullata.') return await step_context.cancel_all_dialogs()
async def showBooks_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: iduser = step_context.context.activity.from_property.id genres_user = [] user_with_info = DatabaseManager.find_user_info(iduser) genres_user = user_with_info.categories index = random.randint(0, len(genres_user) - 1) category = genres_user[index] code = cat_and_code[category.name] books = SuggestBooksDialog.call_amazon(code) card = SuggestBooksDialog.create_card(books, category.name) step_context.values["books"] = books dic[iduser] = books await step_context.context.send_activity(card) message_text = "Vuoi aggiungere un libro alla tua wishlist?" prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=prompt_message, retry_prompt=MessageFactory.text( '''Vuoi aggiungere un libro alla tua wishlist? Scrivi yes o no''')))
async def check_query_time( self, step_context: WaterfallStepContext) -> DialogTurnResult: if (step_context.result != None): step_context.values["Date"] = step_context.result if (step_context.options.time != None): step_context.values["Time"] = step_context.options.time return await step_context.next(None) return await step_context.prompt( time, PromptOptions( prompt=MessageFactory.text("Please provide preferable time."), retry_prompt=MessageFactory.text("Enter a valid time."), ), ) '''message_text = "Please provide preferable Time"
async def _select_skill_group_step(self, step_context: WaterfallStepContext): """ Render a prompt to select the group of skills to use. """ # Remember the delivery mode selected by the user. step_context.values[DELIVERY_MODE_NAME] = step_context.result.value # Create the PromptOptions with the types of supported skills. message_text = "What group of skills would you like to use?" retry_message_text = ( "That was not a valid choice, please select a valid skill group.") choices = [] groups = [] for skill in self._skills_config.SKILLS.values(): if skill.group not in groups: groups.append(skill.group) choices.append(Choice(skill.group)) options = PromptOptions( prompt=MessageFactory.text(message_text, message_text, InputHints.expecting_input), retry_prompt=MessageFactory.text(retry_message_text, retry_message_text, InputHints.expecting_input), choices=choices, ) # Prompt the user to select a type of skill. return await step_context.prompt(SKILL_GROUP_PROMPT, options)
async def confirm_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: result = step_context.result user = step_context.values["user"] book_to_remove = None for book in user.wishlist: if book.name.replace(",", "").lower() == result.replace(",", "").lower(): book_to_remove = book break step_context.values["book_to_remove"] = book_to_remove if book_to_remove is not None: message_text = "Sei sicuro di voler cancellare {}?".format( book_to_remove.name) prompt_message = MessageFactory.text(message_text, message_text, InputHints.expecting_input) return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions( prompt=prompt_message, retry_prompt=MessageFactory.text( '''Sei sicuro di voler cancellare? Scrivi yes o no''')) ) return await step_context.end_dialog()
async def name_step(self, step_context: WaterfallStepContext) -> DialogTurnResult: step_context.values["transport"] = step_context.result.value return await step_context.prompt( TextPrompt.__name__, PromptOptions(prompt=MessageFactory.text("Please enter your name.")), )
async def domanda_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: return await step_context.prompt( TextPrompt.__name__, PromptOptions(prompt=MessageFactory.text("Cosa vuoi sapere?")), ) return step_context.next(0)
async def subscription_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: if step_context.result: vm_details = step_context.options vm_details.name = step_context.result if vm_details.subscription is None: # Ask for the Subscription list_of_choices = [ Choice(value=v) for v in AzureConfig.AZURE_SUBSCRIPTION_ID_MAP.keys() ] # If there's only one subscription, no need to ask if len(list_of_choices) == 1: subscription_id = AzureConfig.AZURE_SUBSCRIPTION_ID_MAP.values( )[0] vm_details.subscription = subscription_id return step_context.next(vm_details.subscription) choice_message_text = "In which subscription?" prompt_message = MessageFactory.text(choice_message_text, choice_message_text, InputHints.expecting_input) return await step_context.prompt( ChoicePrompt.__name__, PromptOptions(prompt=prompt_message, choices=list_of_choices, style=ListStyle.auto)) return await step_context.next(vm_details.subscription)
async def confirm_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: step_context.values["context"] = step_context.result return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=MessageFactory.text("Is this ok?")), )
async def fatturatestuale_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: return await step_context.prompt( NumberPrompt.__name__, PromptOptions( prompt=MessageFactory.text("Per favore inserisci l'importo")), ) return step_context.next(0)
async def complated(self, waterfall_step: WaterfallStepContext): email = waterfall_step._turn_context.activity.text waterfall_step.values["email"] = email name = waterfall_step.values["name"] mobile = waterfall_step.values["mobile"] profile_info = f"name: {name}, email: {email}, mobile: {mobile}" await waterfall_step._turn_context.send_activity(profile_info) return await waterfall_step.end_dialog()
async def second_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: if step_context.result: # step_context.values["transport"] = step_context.result.value # employee=step_context.result.value step_context.values['employee_id'] = 'Required' return await step_context.prompt( ConfirmPrompt.__name__, PromptOptions(prompt=MessageFactory.text( "Do you have an employee Id?.")), ) else: step_context.values["employee_id"] = 'Approved' return await step_context.prompt( TextPrompt.__name__, PromptOptions( prompt=MessageFactory.text("What is your employee id?.")), )