async def loop_step(self, step_context: WaterfallStepContext): country = step_context.values["country"].capitalize() # If they chose an option execute script if step_context.result.value == 'Covid-19 Twitter': await step_context.context.send_activity( MessageFactory.text( "Obtaining last tweets in your country related to COVID-19 wait a moment..." )) result = [] query = f'{country} AND covid OR covid-19 OR coronavirus OR Covid-19' for tweet in tweepy.Cursor(api.search, q=query).items(5): reply = MessageFactory.list([]) reply.attachments.append(self.create_tweet_card(tweet)) await step_context.context.send_activity(reply) if step_context.result.value == 'Covid-19 Meme': # show covid meme reply = MessageFactory.list([]) reply.attachments.append(self.create_hero_card()) await step_context.context.send_activity(reply) # If they're done, exit and return their list. elif step_context.result.value == 'Done': return await step_context.end_dialog() # Otherwise, repeat this dialog, passing in the selections from this iteration. return await step_context.replace_dialog( SocialMediaSelectionDialog.__name__)
async def loop_step(self, step_context: WaterfallStepContext): # If they chose an option execute script if step_context.result.value == 'Covid-19 Stats': await step_context.context.send_activity( MessageFactory.text(f"Welcome to the Covid-19 Stats Portal")) self.add_dialog(StatsSelectionDialog( StatsSelectionDialog.__name__)) return await step_context.begin_dialog( StatsSelectionDialog.__name__) if step_context.result.value == 'Covid-19 Social': await step_context.context.send_activity( MessageFactory.text( f"Welcome to the Covid-19 Social Media Portal")) self.add_dialog( SocialMediaSelectionDialog( SocialMediaSelectionDialog.__name__)) return await step_context.begin_dialog( SocialMediaSelectionDialog.__name__) if step_context.result.value == 'Covid-19 Health': await step_context.context.send_activity( MessageFactory.text(f"Welcome to the Covid-19 Health Portal")) self.add_dialog( HealthSelectionDialog(HealthSelectionDialog.__name__)) return await step_context.begin_dialog( HealthSelectionDialog.__name__) if step_context.result.value == 'Covid-19 Donation': await step_context.context.send_activity( MessageFactory.text(f"Welcome to the Covid-19 Donation Portal") ) # show covid meme reply = MessageFactory.list([]) reply.attachments.append(self.create_thumbnail_card()) await step_context.context.send_activity(reply) if step_context.result.value == 'Covid-19 Places': await step_context.context.send_activity( MessageFactory.text(f"Welcome to the Covid-19 Places Portal")) # show covid meme reply = MessageFactory.list([]) reply.attachments.append(self.create_poi_card()) await step_context.context.send_activity(reply) # If they're done, exit and return their list. elif step_context.result.value == 'Done': return await step_context.end_dialog() # Otherwise, repeat this dialog, passing in the selections from this iteration. return await step_context.replace_dialog( ServiceSelectionDialog.__name__) return await step_context.begin_dialog(ServiceSelectionDialog.__name__)
def test_should_return_a_list(self): activity = MessageFactory.list( [Attachment(content_type='a'), Attachment(content_type='b')]) assert_message(activity) assert_attachments(activity, 2, ['a', 'b']) assert activity.attachment_layout == AttachmentLayoutTypes.list, 'invalid attachment_layout.'
def test_should_return_a_list(self): activity = MessageFactory.list( [Attachment(content_type="a"), Attachment(content_type="b")]) assert_message(activity) assert_attachments(activity, 2, ["a", "b"]) assert (activity.attachment_layout == AttachmentLayoutTypes.list ), "invalid attachment_layout."
async def _send_list_card(self, turn_context: TurnContext): card_path = os.path.join(os.getcwd(), "cards\\hero_card.json") with open(card_path, "rb") as in_file: card_data = json.load(in_file) attachment = Attachment( content_type=CardFactory.content_types.hero_card, content=card_data) await turn_context.send_activity( MessageFactory.list([attachment, attachment, attachment]))
async def _send_proactive_message(gif_name): for conversation_reference in CONVERSATION_REFERENCES.values(): reply = MessageFactory.list([]) reply.attachments.append(create_animation_card(gif_name)) await ADAPTER.continue_conversation( conversation_reference, lambda turn_context: turn_context.send_activity(reply), APP_ID, )
def test_should_return_list_with_text_speak_and_input_hint(self): activity = MessageFactory.list( [Attachment(content_type='a'), Attachment(content_type='b')], 'test1', 'test2', InputHints.ignoring_input) assert_message(activity) assert_attachments(activity, 2, ['a', 'b']) assert activity.attachment_layout == AttachmentLayoutTypes.list, 'invalid attachment_layout.' assert activity.text == 'test1', 'invalid text field.' assert activity.speak == 'test2', 'invalid speak field.' assert activity.input_hint == InputHints.ignoring_input, 'invalid input_hint field.'
async def on_message_activity(self, turn_context: TurnContext): """ This displays two cards: A HeroCard and an AdaptiveCard. Both have the same options. When any of the options are selected, `on_teams_task_module_fecth` is called. """ reply = MessageFactory.list([ TeamsTaskModuleBot.__get_task_module_hero_card_options(), TeamsTaskModuleBot.__get_task_module_adaptive_card_options(), ]) await turn_context.send_activity(reply)
async def loop_step(self, step_context: WaterfallStepContext): # If they chose an option execute script if step_context.result.value == 'Covid-19 Social Distance': # show covid card reply = MessageFactory.list([]) reply.attachments.append(self.create_distance_animation_card()) await step_context.context.send_activity(reply) if step_context.result.value == 'Covid-19 Mask Instructions': # show covid card reply = MessageFactory.list([]) reply.attachments.append(self.create_mask_animation_card()) await step_context.context.send_activity(reply) if step_context.result.value == 'Done': return await step_context.end_dialog() # Otherwise, repeat this dialog, passing in the selections from this iteration. return await step_context.replace_dialog(HealthSelectionDialog.__name__ )
async def show_card_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: """ Send a Rich Card response to the user based on their choice. self method is only called when a valid prompt response is parsed from the user's response to the ChoicePrompt. """ reply = MessageFactory.list([]) found_choice = step_context.result.value if found_choice == "Adaptive Card": reply.attachments.append(self.create_adaptive_card()) elif found_choice == "Animation Card": reply.attachments.append(self.create_animation_card()) elif found_choice == "Audio Card": reply.attachments.append(self.create_audio_card()) elif found_choice == "Hero Card": reply.attachments.append(self.create_hero_card()) elif found_choice == "OAuth Card": reply.attachments.append(self.create_oauth_card()) elif found_choice == "Receipt Card": reply.attachments.append(self.create_receipt_card()) elif found_choice == "Signin Card": reply.attachments.append(self.create_signin_card()) elif found_choice == "Thumbnail Card": reply.attachments.append(self.create_thumbnail_card()) elif found_choice == "Video Card": reply.attachments.append(self.create_video_card()) else: reply.attachment_layout = AttachmentLayoutTypes.carousel reply.attachments.append(self.create_adaptive_card()) reply.attachments.append(self.create_animation_card()) reply.attachments.append(self.create_audio_card()) reply.attachments.append(self.create_hero_card()) reply.attachments.append(self.create_oauth_card()) reply.attachments.append(self.create_receipt_card()) reply.attachments.append(self.create_signin_card()) reply.attachments.append(self.create_thumbnail_card()) reply.attachments.append(self.create_video_card()) # Send the card(s) to the user as an attachment to the activity await step_context.context.send_activity(reply) # Give the user instructions about what to do next await step_context.context.send_activity( "Type anything to see another card.") return await step_context.end_dialog()
def test_should_return_list_with_text_speak_and_input_hint(self): activity = MessageFactory.list( [Attachment(content_type="a"), Attachment(content_type="b")], "test1", "test2", InputHints.ignoring_input, ) assert_message(activity) assert_attachments(activity, 2, ["a", "b"]) assert (activity.attachment_layout == AttachmentLayoutTypes.list ), "invalid attachment_layout." assert activity.text == "test1", "invalid text field." assert activity.speak == "test2", "invalid speak field." assert (activity.input_hint == InputHints.ignoring_input ), "invalid input_hint field."
async def MoodCarousel(self, waterfall_step: WaterfallStepContext): waterfall_step.values[ "username"] = waterfall_step._turn_context.activity.text reply = MessageFactory.list([]) reply.attachment_layout = AttachmentLayoutTypes.carousel reply.attachments.append(self.create_hero_card1_1()) reply.attachments.append(self.create_hero_card1_2()) reply.attachments.append(self.create_hero_card1_3()) reply.attachments.append(self.create_hero_card1_4()) reply.attachments.append(self.create_hero_card1_5()) reply.attachments.append(self.create_hero_card1_6()) reply.attachments.append(self.create_hero_card1_7()) reply.attachments.append(self.create_hero_card1_8()) reply.attachments.append(self.create_hero_card1_9()) reply.attachments.append(self.create_hero_card1_10()) return await waterfall_step.context.send_activity(reply)
async def start_selection_step(self, step_context: WaterfallStepContext): # Set the user's name to what they entered in response to the name prompt. user_profile = step_context.values[self.USER_INFO] user_profile.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"Nice to e-meet you {step_context.result.capitalize()}") ) # show covid card reply = MessageFactory.list([]) reply.attachments.append(self.create_animation_card()) await step_context.context.send_activity(reply) # start the review selection dialog. return await step_context.begin_dialog(ServiceSelectionDialog.__name__)
async def on_members_added_activity(self, members_added: [ChannelAccount], turn_context: TurnContext): """ Greet when users are added to the conversation. Note that all channels do not send the conversation update activity. If you find that this bot works in the emulator, but does not in another channel the reason is most likely that the channel does not send this activity. """ for member in members_added: if member.id != turn_context.activity.recipient.id: reply = MessageFactory.list([]) member_name = member.name message = Activity( type=ActivityTypes.message, attachments=[self.__send_welcome_card(member_name)], ) await turn_context.send_activity(message)
async def _get_banks(user_preferences: UserPreferences, **kwargs): """Returns all banks names.""" lang = user_preferences.lang choose_bank_text = ResponseMsgs.get('choose_bank_for_rates', lang) card = HeroCard( text=choose_bank_text, buttons=[ CardAction(type=ActionTypes.im_back, title=getattr(bank, f'{lang.value}_name'), value=getattr(bank, f'{lang.value}_name')) for bank in banks.BANKS ], ) card_attachment = CardFactory.hero_card(card) reply = MessageFactory.list([card_attachment]) return reply
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: card = HeroCard( title="Welcome to the COVID-19 Information bot", images=[ CardImage( url="https://i.imgur.com/zm095AG.png" ) ], buttons=[ CardAction( type=ActionTypes.open_url, title="Repository link", value="https://github.com/vykhand/realherobot", ) ], ) repl = MessageFactory.list([]) repl.attachments.append(CardFactory.hero_card(card)) await turn_context.send_activity(repl)
def create_adaptive_card(self) -> Attachment: reply = MessageFactory.list([]) reply.attachments.append( CardFactory.adaptive_card(self.ADAPTIVE_CARD_CONTENT)) return reply
async def display_card_step(self, step_context: WaterfallStepContext): if step_context.context.activity.value is not None: await self.handle_special_activity(step_context) else: # Check to see if the activity is an adaptive card or a bot action response card_type = CardOptions(step_context.result.value) if ChannelSupportedCards.is_card_supported( step_context.context.activity.channel_id, card_type): if card_type == CardOptions.ADAPTIVE_CARD_BOT_ACTION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_bot_action()) ) elif card_type == CardOptions.ADAPTIVE_CARD_TEAMS_TASK_MODULE: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_task_module( ))) elif card_type == CardOptions.ADAPTIVE_CARD_SUBMIT_ACTION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_submit())) elif card_type == CardOptions.HERO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_hero_card())) elif card_type == CardOptions.THUMBNAIL: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_thumbnail_card())) elif card_type == CardOptions.RECEIPT: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_receipt_card())) elif card_type == CardOptions.SIGN_IN: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_signin_card())) elif card_type == CardOptions.CAROUSEL: # NOTE if cards are NOT the same height in a carousel, # Teams will instead display as AttachmentLayoutTypes.List await step_context.context.send_activity( MessageFactory.carousel([ CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), ])) elif card_type == CardOptions.LIST: await step_context.context.send_activity( MessageFactory.list([ CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), ])) elif card_type == CardOptions.O365: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_o365_connector_card())) elif card_type == CardOptions.TEAMS_FILE_CONSENT: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_teams_file_consent_card( TEAMS_LOGO_FILE_NAME))) elif card_type == CardOptions.ANIMATION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_animation_card( MIND_BLOWN_GIF))) elif card_type == CardOptions.AUDIO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_audio_card( f"{self.configuration.SERVER_URL}/{MUSIC_API}") )) elif card_type == CardOptions.VIDEO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_video_card( CORGI_ON_CAROUSEL_VIDEO))) elif card_type == CardOptions.ADAPTIVE_UPDATE: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_update_card())) elif card_type == CardOptions.END: # End the dialog so the host gets an EoC await step_context.context.send_activity( Activity( type=ActivityTypes.end_of_conversation, code=EndOfConversationCodes.completed_successfully, )) return DialogTurnResult(DialogTurnStatus.Complete) else: await step_context.context.send_activity( f"{card_type.value} cards are not supported in the " f"{step_context.context.activity.channel_id} channel.") return await step_context.replace_dialog(self.initial_dialog_id, "What card would you want?")
async def getProvider(turn_context: TurnContext, type): if type == "[HOSP]": url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=33.8971058%2C35.4833635&radius=1000&type=hospital&fields=name%2Cformatted_address%2Cformatted_phone_number&key={}".format( DefaultConfig.API_KEY) response = requests.get(url) if response.status_code == 200: hospitalsList = [] for i in range(4): hospital = [] result = response.json()['results'][i] name = result['name'] vicinity = result['vicinity'] place_id = result['place_id'] openNow = result.get('opening_hours') link = "https://www.google.com/maps/place/?q=place_id:{}".format( place_id) photoreference = result.get("photos") if (photoreference): photoreference = photoreference[0].get('photo_reference') if openNow: openNow = openNow.get('open_now') if openNow == True: openNow = "Open" else: openNow = "Closed" else: openNow = "opening hours not registered" rating = result.get('rating') if rating: pass else: rating = "No ratings available" user_ratings_total = result.get('user_ratings_total') if user_ratings_total: pass else: user_ratings_total = "N/A" Imageurl = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference={}&key={}".format( photoreference, DefaultConfig.API_KEY, ) hospital.append(name) hospital.append(vicinity) hospital.append(openNow) hospital.append(rating) hospital.append(user_ratings_total) hospital.append(link) hospital.append(Imageurl) hospitalsList.append(hospital) for hospital in hospitalsList: reply = MessageFactory.list([]) reply.attachments.append(create_thumbnail_card(hospital)) await turn_context.send_activity(reply) elif response.status_code == 404: print('Not Found.') else: url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=33.8971058,35.4833635&radius=1000&type=pharmacy&fields=name,formatted_address,photo,vicinity&key={}".format( DefaultConfig.API_KEY) response = requests.get(url) if response.status_code == 200: pharmacysList = [] for i in range(4): pharmacy = [] result = response.json()['results'][i] name = result['name'] vicinity = result['vicinity'] place_id = result['place_id'] openNow = result.get('opening_hours') link = "https://www.google.com/maps/place/?q=place_id:{}".format( place_id) photoreference = result.get("photos") if (photoreference): photoreference = photoreference[0].get('photo_reference') if openNow: openNow = openNow.get('open_now') if openNow == True: openNow = "Open" else: openNow = "Closed" else: openNow = "<not registered>" rating = result.get('rating') if rating: pass else: rating = "No ratings available" user_ratings_total = result.get('user_ratings_total') if user_ratings_total: pass else: user_ratings_total = "N/A" Imageurl = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference={}&key={}".format( photoreference, DefaultConfig.API_KEY, ) pharmacy.append(name) pharmacy.append(vicinity) pharmacy.append(openNow) pharmacy.append(rating) pharmacy.append(user_ratings_total) pharmacy.append(link) pharmacy.append(Imageurl) pharmacysList.append(pharmacy) for pharmacy in pharmacysList: reply = MessageFactory.list([]) reply.attachments.append(create_thumbnail_card(pharmacy)) await turn_context.send_activity(reply) elif response.status_code == 404: print('Not Found.')
async def loop_step(self, step_context: WaterfallStepContext): country = step_context.values["country"].capitalize() # If they chose an option execute script if step_context.result.value == 'Covid-19 Cases': await step_context.context.send_activity( MessageFactory.text("Wait a moment...")) querystring = {"country": "{}".format(country)} response = requests.request("GET", url, headers=headers, params=querystring) response_json = json.loads(response.text) new_cases = response_json['response'][0]['cases']['new'] active_cases = response_json['response'][0]['cases']['active'] recovered_cases = response_json['response'][0]['cases'][ 'recovered'] await step_context.context.send_activity( MessageFactory.text(f"COVID-19 Cases from {country} \n\n" f"New Cases {new_cases} \n\n" f"Active Cases {active_cases} \n\n" f"Recovered Cases {recovered_cases} \n\n")) reply = Activity(type=ActivityTypes.message) reply.attachments = [self._get_inline_attachment(country)] await step_context.context.send_activity(reply) if step_context.result.value == 'Covid-19 Deaths': await step_context.context.send_activity( MessageFactory.text("Wait a moment...")) querystring = {"country": "{}".format(country)} response = requests.request("GET", url, headers=headers, params=querystring) response_json = json.loads(response.text) new_deaths = response_json['response'][0]['deaths']['new'] m_deaths = response_json['response'][0]['deaths']['1M_pop'] total_deaths = response_json['response'][0]['deaths']['total'] await step_context.context.send_activity( MessageFactory.text(f"COVID-19 Deaths from {country} \n\n" f"New Deaths {new_deaths} \n\n" f"1M_pop Deaths {m_deaths} \n\n" f"Total Deaths {total_deaths} \n\n")) if step_context.result.value == 'Covid-19 Tests': await step_context.context.send_activity( MessageFactory.text("Wait a moment...")) querystring = {"country": "{}".format(country)} response = requests.request("GET", url, headers=headers, params=querystring) response_json = json.loads(response.text) m_tests = response_json['response'][0]['tests']['1M_pop'] total_tests = response_json['response'][0]['tests']['total'] await step_context.context.send_activity( MessageFactory.text(f"COVID-19 PCR Tests from {country} \n\n" f"New Tests {m_tests} \n\n" f"Total PCR Tests {total_tests} \n\n")) if step_context.result.value == 'Covid-19 Twitter': await step_context.context.send_activity( MessageFactory.text( "Obtaining last tweets in your country related to COVID-19 wait a moment..." )) result = [] query = f'{country} AND covid OR covid-19 OR coronavirus OR Covid-19' for tweet in tweepy.Cursor(api.search, q=query).items(5): reply = MessageFactory.list([]) reply.attachments.append(self.create_tweet_card(tweet)) await step_context.context.send_activity(reply) if step_context.result.value == 'Covid-19 Meme': # show covid meme reply = MessageFactory.list([]) reply.attachments.append(self.create_hero_card()) await step_context.context.send_activity(reply) # If they're done, exit and return their list. elif step_context.result.value == 'Done': return await step_context.end_dialog() # Otherwise, repeat this dialog, passing in the selections from this iteration. return await step_context.replace_dialog(ReviewSelectionDialog.__name__ )
async def NegativeMoodCarousel(self, waterfall_step: WaterfallStepContext): name = waterfall_step._turn_context.activity.text waterfall_step.values["first_click"] = name waterfall_step.values[ "first_clicktime"] = waterfall_step._turn_context.activity.timestamp.strftime( "%d-%b-%Y (%H:%M:%S.%f)") reply = MessageFactory.list([]) reply.attachment_layout = AttachmentLayoutTypes.carousel if name == "feelings": reply.attachments.append(self.create_hero_card2_feelings_1()) reply.attachments.append(self.create_hero_card2_feelings_2()) reply.attachments.append(self.create_hero_card2_feelings_3()) reply.attachments.append(self.create_hero_card2_feelings_4()) elif name == "life": reply.attachments.append(self.create_hero_card2_life_1()) reply.attachments.append(self.create_hero_card2_life_2()) reply.attachments.append(self.create_hero_card2_life_3()) reply.attachments.append(self.create_hero_card2_life_4()) elif name == "job": reply.attachments.append(self.create_hero_card2_job_1()) reply.attachments.append(self.create_hero_card2_job_2()) reply.attachments.append(self.create_hero_card2_job_3()) reply.attachments.append(self.create_hero_card2_job_4()) elif name == "friends": reply.attachments.append(self.create_hero_card2_friends_1()) reply.attachments.append(self.create_hero_card2_friends_2()) reply.attachments.append(self.create_hero_card2_friends_3()) reply.attachments.append(self.create_hero_card2_friends_4()) elif name == "health": reply.attachments.append(self.create_hero_card2_health_1()) reply.attachments.append(self.create_hero_card2_health_2()) reply.attachments.append(self.create_hero_card2_health_3()) reply.attachments.append(self.create_hero_card2_health_4()) elif name == "family": reply.attachments.append(self.create_hero_card2_family_1()) reply.attachments.append(self.create_hero_card2_family_2()) reply.attachments.append(self.create_hero_card2_family_3()) reply.attachments.append(self.create_hero_card2_family_4()) elif name == "spouse": reply.attachments.append(self.create_hero_card2_spouse_1()) reply.attachments.append(self.create_hero_card2_spouse_2()) reply.attachments.append(self.create_hero_card2_spouse_3()) reply.attachments.append(self.create_hero_card2_spouse_4()) elif name == "love": reply.attachments.append(self.create_hero_card2_love_1()) reply.attachments.append(self.create_hero_card2_love_2()) reply.attachments.append(self.create_hero_card2_love_3()) reply.attachments.append(self.create_hero_card2_love_4()) elif name == "self": reply.attachments.append(self.create_hero_card2_self_1()) reply.attachments.append(self.create_hero_card2_self_2()) reply.attachments.append(self.create_hero_card2_self_3()) reply.attachments.append(self.create_hero_card2_self_4()) elif name == "home": reply.attachments.append(self.create_hero_card2_home_1()) reply.attachments.append(self.create_hero_card2_home_2()) reply.attachments.append(self.create_hero_card2_home_3()) reply.attachments.append(self.create_hero_card2_home_4()) return await waterfall_step.context.send_activity(reply)
async def on_message_activity(self, turn_context: TurnContext): """ Respond to messages sent from the user. """ reply = MessageFactory.list([]) # Get the state properties from the turn context. welcome_user_state = await self.user_state_accessor.get( turn_context, WelcomeUserState) if not welcome_user_state.did_welcome_user: welcome_user_state.did_welcome_user = True text = turn_context.activity.text.lower() if text in ("hello", "hi", "intro", "help", "menu"): #await self.__send_intro_card(turn_context) reply.attachments.append(self.create_signin_card()) await turn_context.send_activity(reply) else: # This example hardcodes specific utterances. You should use LUIS or QnA for more advance language # understanding. print("Printing action------", turn_context.activity.text) print("Printing JSON------", turn_context._activity.value) if turn_context._activity.value is not None: print("Printing type------", turn_context._activity.value["type"]) print("Printing customer id------", turn_context._activity.value["customerId"]) print("Printing password------", turn_context._activity.value["password"]) customerId = turn_context._activity.value["customerId"] password = turn_context._activity.value["password"] terms = turn_context._activity.value["terms"] isvalid = True if (customerId is None) or (str(customerId).strip() == ""): isvalid = False await turn_context.send_activity( "Please enter valid Customer ID") if (password is None) or (str(password).strip() == ""): isvalid = False await turn_context.send_activity( "Please enter valid Password") if (terms is None or terms in ("false")): isvalid = False await turn_context.send_activity( "Please accept the terms and conditions.") if (isvalid and turn_context._activity.value["type"] in ("Login")): # defining a params dict for the parameters to be sent to the API PARAMS = {'userName': customerId, 'password': password} # sending get request and saving the response as response object r = requests.get(url="http://localhost:8080/login", params=PARAMS) # extracting data in json format data = r.json() print("printing response ", data["loginStatus"]) if (data["loginStatus"] is not None and data["loginStatus"] in ("success")): await turn_context.send_activity("Login Succeded") await turn_context.send_activity( "An OTP is sent to your registered mobile number xxxxxxxx90." ) await turn_context.send_activity( "Please enter the OTP.") else: await turn_context.send_activity( "Login Failed. Please try again") # for key in turn_context._activity.value: # print(turn_context._activity.value[key]) else: text = turn_context.activity.text.lower() if text in ("369"): await turn_context.send_activity("Thanks!!") await self.__send_intro_card(turn_context) elif text in ("sign-in", "login"): await self.__login_otp_card_card(turn_context) elif text in ("hello", "hi", "intro", "help", "menu"): await self.__send_intro_card(turn_context) #await turn_context.send_activity(f"You said { text }") elif text in ("account balance"): await self.__send_accountbalance_card(turn_context) await turn_context.send_activity( "Also, your deposit xxxxxxxxx9243 is closed pre-maturely as per your request and amount is credited to your third party account." ) elif text in ("xxxxxxxxx4567"): await self.__list_accountTransaction_card(turn_context) await self.__mobile_billDue_card(turn_context) elif text in ("yes, pay my mobile bill"): await self.__show_invoice_card(turn_context) await self.__show_selectAccountForBill_card(turn_context) elif text in ("debit from xxxxxxxxx4567"): await turn_context.send_activity( "An OTP is sent to your registered mobile number xxxxxxxx90." ) await turn_context.send_activity("Please enter the OTP.") elif text in ("1234"): await turn_context.send_activity( "Transaction Successful !! Mobile bill paid for $100 from your account number xxxxxxxxx4567" ) await turn_context.send_activity( "As a loyal customer, we are happy to offer you one year free VISA card which comes with $25 movie voucher.\n\n Also your balance reward points 514 from card xxxxxxxxxxxx7653 will be added to the new card." ) await self.__show_congratulations_card(turn_context) elif text in ("credit card"): await turn_context.send_activity( "Credit card xxxxxxxxxxxx7653 \n\n Current outstanding is $0.00 \n\n Card closed on 09/01/2020 \n\n Balance reward points are 514" ) elif text in ("service requests"): await turn_context.send_activity( "Currently there are no open service requests.") elif text in ("xxxxxxxxx4566"): await turn_context.send_activity( "Your current account xxxxxxxxx4566 is Active, but there are no transactions on it." ) elif text in ("debit from xxxxxxxxx4566"): await turn_context.send_activity( "Insufficient account balance. Please choose another account" ) await self.__show_selectAccountForBill_card(turn_context)