def show_location(): Bot.init = False card = SigninCard(buttons=[ CardAction(type=ActionTypes.im_back, title=i, value=i) for i in Hotels.data().keys() ]) locs = CardFactory.signin_card(card) return locs
def create_signin_card() -> Attachment: card = SigninCard(text="BotFramework Sign-in Card", buttons=[ CardAction(type=ActionTypes.signin, title="Sign-in", value="https://login.microsoftonline.com") ]) return CardFactory.signin_card(card)
def create_signin_card(self) -> Attachment: card = SigninCard( text="ModernBank - Login", buttons=[ CardAction( type=ActionTypes.im_back, title="Sign-In", value="Sign-In", ) ], ) return CardFactory.signin_card(card)
async def send_oauth_card(self, context: TurnContext, prompt: Union[Activity, str] = None): if not isinstance(prompt, Activity): prompt = MessageFactory.text(prompt or "", None, InputHints.accepting_input) else: prompt.input_hint = prompt.input_hint or InputHints.accepting_input prompt.attachments = prompt.attachments or [] if self._channel_suppports_oauth_card(context.activity.channel_id): if not any(att.content_type == CardFactory.content_types.oauth_card for att in prompt.attachments): prompt.attachments.append( CardFactory.oauth_card( OAuthCard( text=self._settings.text, connection_name=self._settings.connection_name, buttons=[ CardAction( title=self._settings.title, text=self._settings.text, type=ActionTypes.signin, ) ], ))) else: if not any( att.content_type == CardFactory.content_types.signin_card for att in prompt.attachments): if not hasattr(context.adapter, "get_oauth_sign_in_link"): raise Exception( "OAuthPrompt.send_oauth_card(): get_oauth_sign_in_link() not supported by the current adapter" ) link = await context.adapter.get_oauth_sign_in_link( context, self._settings.connection_name) prompt.attachments.append( CardFactory.signin_card( SigninCard( text=self._settings.text, buttons=[ CardAction( title=self._settings.title, value=link, type=ActionTypes.signin, ) ], ))) # Send prompt await context.send_activity(prompt)
def test_should_create_signin_card_attachment(self): button = CardAction(type=ActionTypes.signin, title='test', value='https://example.org/signin') card = SigninCard(title='test', buttons=[button]) attachment = CardFactory.signin_card(card) assert_attachment(attachment, CardFactory.content_types.signin_card) assert_actions(attachment.content.buttons, 1, ['test']) assert attachment.content.buttons[ 0].type == 'signin', 'wrong action type.' assert attachment.content.buttons[ 0].value == 'https://example.org/signin', 'wrong action value.'
def test_should_create_signin_card_attachment(self): button = CardAction(type=ActionTypes.signin, title="test", value="https://example.org/signin") card = SigninCard(title="test", buttons=[button]) attachment = CardFactory.signin_card(card) assert_attachment(attachment, CardFactory.content_types.signin_card) assert_actions(attachment.content.buttons, 1, ["test"]) assert attachment.content.buttons[ 0].type == "signin", "wrong action type." assert (attachment.content.buttons[0].value == "https://example.org/signin"), "wrong action value."
def menu_card(hotel): #Hotel Menu add = [] check = {'Wine', 'Dine', 'Event', 'Package', 'Book', 'FAQ', 'Call'} keys = set(key for key in hotel.keys() if hotel.get(key) == True) res = check & keys #print(res) if 'Book' in res: add = add + ['Book a Room'] if 'Dine' in res: if 'Wine' in res: add = add + ['Wine & Dine'] else: add = add + ['Dining'] if 'Event' in res: add = add + ['Plan an Event'] if 'Package' in res: add = add + ['Book a Package'] if 'FAQ' in res: add = add + ['Have any Questions?'] if 'Call' in res: add = add + ['Request Callback'] opt = add + ['Main Menu'] card = SigninCard(text=Bot.Name + ", How may I help you?", buttons=[ CardAction(type=ActionTypes.im_back, title=i, value=i) for i in opt ]) locs = CardFactory.signin_card(card) return locs
async def _send_oauth_card(self, context: TurnContext, prompt: Union[Activity, str] = None): if not isinstance(prompt, Activity): prompt = MessageFactory.text(prompt or "", None, InputHints.accepting_input) else: prompt.input_hint = prompt.input_hint or InputHints.accepting_input prompt.attachments = prompt.attachments or [] if OAuthPrompt._channel_suppports_oauth_card( context.activity.channel_id): if not any(att.content_type == CardFactory.content_types.oauth_card for att in prompt.attachments): adapter: ExtendedUserTokenProvider = context.adapter card_action_type = ActionTypes.signin sign_in_resource: SignInUrlResponse = await adapter.get_sign_in_resource_from_user_and_credentials( context, self._settings.oath_app_credentials, self._settings.connection_name, context.activity.from_property.id, ) link = sign_in_resource.sign_in_link bot_identity: ClaimsIdentity = context.turn_state.get( BotAdapter.BOT_IDENTITY_KEY) # use the SignInLink when in speech channel or bot is a skill or # an extra OAuthAppCredentials is being passed in if ((bot_identity and SkillValidation.is_skill_claim(bot_identity.claims)) or not context.activity.service_url.startswith("http") or self._settings.oath_app_credentials): if context.activity.channel_id == Channels.emulator: card_action_type = ActionTypes.open_url elif not OAuthPrompt._channel_requires_sign_in_link( context.activity.channel_id): link = None json_token_ex_resource = ( sign_in_resource.token_exchange_resource.as_dict() if sign_in_resource.token_exchange_resource else None) prompt.attachments.append( CardFactory.oauth_card( OAuthCard( text=self._settings.text, connection_name=self._settings.connection_name, buttons=[ CardAction( title=self._settings.title, text=self._settings.text, type=card_action_type, value=link, ) ], token_exchange_resource=json_token_ex_resource, ))) else: if not any( att.content_type == CardFactory.content_types.signin_card for att in prompt.attachments): if not hasattr(context.adapter, "get_oauth_sign_in_link"): raise Exception( "OAuthPrompt._send_oauth_card(): get_oauth_sign_in_link() not supported by the current adapter" ) link = await context.adapter.get_oauth_sign_in_link( context, self._settings.connection_name, None, self._settings.oath_app_credentials, ) prompt.attachments.append( CardFactory.signin_card( SigninCard( text=self._settings.text, buttons=[ CardAction( title=self._settings.title, value=link, type=ActionTypes.signin, ) ], ))) # Send prompt await context.send_activity(prompt)
async def _send_oauth_card(self, context: TurnContext, prompt: Union[Activity, str] = None): if not isinstance(prompt, Activity): prompt = MessageFactory.text(prompt or "", None, InputHints.accepting_input) else: prompt.input_hint = prompt.input_hint or InputHints.accepting_input prompt.attachments = prompt.attachments or [] if OAuthPrompt._channel_suppports_oauth_card( context.activity.channel_id): if not any(att.content_type == CardFactory.content_types.oauth_card for att in prompt.attachments): link = None card_action_type = ActionTypes.signin bot_identity: ClaimsIdentity = context.turn_state.get( "BotIdentity") # check if it's from streaming connection if not context.activity.service_url.startswith("http"): if not hasattr(context.adapter, "get_oauth_sign_in_link"): raise Exception( "OAuthPrompt: get_oauth_sign_in_link() not supported by the current adapter" ) link = await context.adapter.get_oauth_sign_in_link( context, self._settings.connection_name, None, self._settings.oath_app_credentials, ) elif bot_identity and SkillValidation.is_skill_claim( bot_identity.claims): link = await context.adapter.get_oauth_sign_in_link( context, self._settings.connection_name, None, self._settings.oath_app_credentials, ) card_action_type = ActionTypes.open_url prompt.attachments.append( CardFactory.oauth_card( OAuthCard( text=self._settings.text, connection_name=self._settings.connection_name, buttons=[ CardAction( title=self._settings.title, text=self._settings.text, type=card_action_type, value=link, ) ], ))) else: if not any( att.content_type == CardFactory.content_types.signin_card for att in prompt.attachments): if not hasattr(context.adapter, "get_oauth_sign_in_link"): raise Exception( "OAuthPrompt.send_oauth_card(): get_oauth_sign_in_link() not supported by the current adapter" ) link = await context.adapter.get_oauth_sign_in_link( context, self._settings.connection_name, None, self._settings.oath_app_credentials, ) prompt.attachments.append( CardFactory.signin_card( SigninCard( text=self._settings.text, buttons=[ CardAction( title=self._settings.title, value=link, type=ActionTypes.signin, ) ], ))) # Send prompt await context.send_activity(prompt)
def __handle_message_activity(self, activity): #Main logic to handle each reply self.send_response(200) self.end_headers() credentials = MicrosoftAppCredentials(APP_ID, APP_PASSWORD) connector = ConnectorClient(credentials, base_url=activity.service_url) if Bot.init: #Initial customization Bot.Name = activity.text locs = Bot.show_location() st = wlc + Bot.Name + " to chat with me. \nPlease choose which city you prefer." reply = Bot.__create_reply_activity(activity, st, locs) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.init = False else: if not Bot.menu_opt: # If it is not hotel menu if not Bot.sub: #If it is not a sub-hotel menu (sub-hotel menu meaning - it is not clicked from the list of many hotels in a single city) Bot.city = activity.text hotel = Hotels.data().get(Bot.city) if len( hotel.keys() ) == 1: # If there is only one hotel in the city, directly display the pics and info Bot.hotel_name = list(hotel.keys())[0] ht = list(hotel.values())[0] info = ht['info'] img = ht['img'] card = Bot.hotel_card(info, img) Bot.property_code = ht['PropertyCode'] reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) time.sleep(1) menu = Bot.menu_card(hotel.get(Bot.hotel_name)) reply = Bot.__create_reply_activity(activity, '', menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.menu_opt = True else: #If there are more than one hotel in a city, show the hotels list and set Bot.sub as True htlst = SigninCard( text="Choose a hotel in {}".format(Bot.city), buttons=[ CardAction(type=ActionTypes.im_back, title=i, value=i) for i in hotel.keys() ]) card = CardFactory.signin_card(htlst) reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.sub = True else: # For choosing one hotel from multiple hotels in single city, i.e it is a sub-hotel menu Bot.hotel_name = activity.text hotel = Hotels.data().get(Bot.city).get(Bot.hotel_name) info = hotel.get('info') img = hotel.get('img') card = Bot.hotel_card(info, img) Bot.property_code = hotel['PropertyCode'] reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) time.sleep(1) menu = Bot.menu_card(hotel) reply = Bot.__create_reply_activity(activity, '', menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.menu_opt = True else: #For rest of the inputs value = activity.text defmsg = "I am Sorry " + Bot.Name + ", Kindly share your e-mail id. I will revert at the earliest." if value == "Book_Package": msg = Bot.Name + ", Your details have been submitted successfully. We will call you back shortly. Thanks for contacting us." reply = Bot.__create_reply_activity(activity, msg, menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) hotel = Hotels.data().get(Bot.city).get(Bot.hotel_name) menu = Bot.menu_card(hotel) #Display main menu reply = Bot.__create_reply_activity( activity, 'Is there anything else I can help you with?', menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.menu_opt = True if Bot.query == True: #If faq is clicked out = Bot.faq(value) reply = Bot.__create_reply_activity(activity, out) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.query = False hotel = Hotels.data().get(Bot.city).get(Bot.hotel_name) menu = Bot.menu_card(hotel) reply = Bot.__create_reply_activity( activity, 'Is there anything else I can help you with?', menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.menu_opt = True else: if value == 'Book a Room': Bot.reset_flags() Bot.flag_dict['book'] = True card = Bot.book_room() #show booking form reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) elif value == "Dining" or value == "Wine & Dine": Bot.reset_flags() Bot.flag_dict['dine'] = True images = Hotels.data().get(Bot.city).get( Bot.hotel_name).get('img') card = Bot.guest_info() reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) elif value == "Plan an Event": Bot.reset_flags() Bot.flag_dict['event'] = True images = Hotels.data().get(Bot.city).get( Bot.hotel_name).get('img') card = Bot.guest_info() reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) elif value == "Book a Package": Bot.reset_flags() Bot.flag_dict['package'] = True card = Bot.guest_info() reply = Bot.__create_reply_activity(activity, '', card) connector.conversations.send_to_conversation( reply.conversation.id, reply) elif value == "Have any Questions?": Bot.query = True reply = Bot.__create_reply_activity( activity, 'Hey ' + Bot.Name + ',Type your question and I will try my best to answer for you..' ) connector.conversations.send_to_conversation( reply.conversation.id, reply) elif value == "Main Menu": locs = Bot.choose_hotel() reply = Bot.__create_reply_activity( activity, 'Choose a city', locs) connector.conversations.send_to_conversation( reply.conversation.id, reply) else: if value == None: #For all submit buttons, value is returned as None. So using that to differentiate inputs obtained through various submit buttons success = "Your details have been submitted successfully " + Bot.Name + ". You will soon be contacted back" if Bot.flag_dict.get( 'book' ): #Open resavenue booking page in browser data = activity.value indate = data['indate'] outdate = data['outdate'] #indate = indt[3:6]+indt[0:3]+indt[6:] #outdate = otdt[3:6]+otdt[0:3]+otdt[6:] url = "http://www.resavenue.com/bookingNew/servlet/checkAvailable.resBookings?regCode={}&arr_date={}&dep_date={}&roomNo={}&adult_1={}&child_1={}&targetTemplate=3".format( Bot.property_code, indate, outdate, data['rooms'], data['adults'], data['child']) print(url) webbrowser.open_new(url) reply = Bot.__create_reply_activity( activity, 'You will now be redirected to the booking page' ) connector.conversations.send_to_conversation( reply.conversation.id, reply) if Bot.flag_dict.get('event'): reply = Bot.__create_reply_activity( activity, success) connector.conversations.send_to_conversation( reply.conversation.id, reply) if Bot.flag_dict.get('dine'): reply = Bot.__create_reply_activity( activity, success) connector.conversations.send_to_conversation( reply.conversation.id, reply) if Bot.flag_dict.get('package'): reply = Bot.__create_reply_activity( activity, success) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.reset_flags() else: reply = Bot.__create_reply_activity( activity, defmsg) connector.conversations.send_to_conversation( reply.conversation.id, reply) hotel = Hotels.data().get(Bot.city).get(Bot.hotel_name) menu = Bot.menu_card(hotel) reply = Bot.__create_reply_activity( activity, 'Is there anything else I can help you with?', menu) connector.conversations.send_to_conversation( reply.conversation.id, reply) Bot.menu_opt = True