async def logic(context: TurnContext): if test_case != SkillFlowTestCase.root_bot_only: # Create a skill ClaimsIdentity and put it in turn_state so isSkillClaim() returns True. claims_identity = ClaimsIdentity({}, False) claims_identity.claims[ "ver" ] = "2.0" # AuthenticationConstants.VersionClaim claims_identity.claims[ "aud" ] = ( SimpleComponentDialog.skill_bot_id ) # AuthenticationConstants.AudienceClaim claims_identity.claims[ "azp" ] = ( SimpleComponentDialog.parent_bot_id ) # AuthenticationConstants.AuthorizedParty context.turn_state[BotAdapter.BOT_IDENTITY_KEY] = claims_identity if test_case == SkillFlowTestCase.root_bot_consuming_skill: # Simulate the SkillConversationReference with a channel OAuthScope stored in turn_state. # This emulates a response coming to a root bot through SkillHandler. context.turn_state[ SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY ] = SkillConversationReference( None, AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE ) if test_case == SkillFlowTestCase.middle_skill: # Simulate the SkillConversationReference with a parent Bot ID stored in turn_state. # This emulates a response coming to a skill from another skill through SkillHandler. context.turn_state[ SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY ] = SkillConversationReference( None, SimpleComponentDialog.parent_bot_id ) async def aux( turn_context: TurnContext, # pylint: disable=unused-argument activities: List[Activity], next: Callable, ): for activity in activities: if activity.type == ActivityTypes.end_of_conversation: SimpleComponentDialog.eoc_sent = activity break return await next() # Interceptor to capture the EoC activity if it was sent so we can assert it in the tests. context.on_send_activities(aux) SimpleComponentDialog.dm_turn_result = await dialog_manager.on_turn(context)
async def logic(context: TurnContext): if test_case != FlowTestCase.root_bot_only: claims_identity = ClaimsIdentity( { AuthenticationConstants.VERSION_CLAIM: "2.0", AuthenticationConstants.AUDIENCE_CLAIM: self.skill_bot_id, AuthenticationConstants.AUTHORIZED_PARTY: self.parent_bot_id, }, True, ) context.turn_state[ BotAdapter.BOT_IDENTITY_KEY] = claims_identity if test_case == FlowTestCase.root_bot_consuming_skill: context.turn_state[ SkillHandler. SKILL_CONVERSATION_REFERENCE_KEY] = SkillConversationReference( None, AuthenticationConstants. TO_CHANNEL_FROM_BOT_OAUTH_SCOPE) if test_case == FlowTestCase.middle_skill: context.turn_state[ SkillHandler. SKILL_CONVERSATION_REFERENCE_KEY] = SkillConversationReference( None, self.parent_bot_id) async def capture_eoc(inner_context: TurnContext, activities: List[Activity], next): # pylint: disable=unused-argument for activity in activities: if activity.type == ActivityTypes.end_of_conversation: self.eoc_sent = activity break return await next() context.on_send_activities(capture_eoc) await DialogExtensions.run_dialog( dialog, context, convo_state.create_property("DialogState"))
async def create_skill_conversation_id( self, options_or_conversation_reference: Union[ SkillConversationIdFactoryOptions, ConversationReference], ) -> str: key = (options_or_conversation_reference.activity.conversation.id + options_or_conversation_reference.activity.service_url) if key not in self.conversation_refs: self.conversation_refs[key] = SkillConversationReference( conversation_reference=TurnContext.get_conversation_reference( options_or_conversation_reference.activity), oauth_scope=options_or_conversation_reference. from_bot_oauth_scope, ) return key
async def create_skill_conversation_id( self, options_or_conversation_reference: Union[ SkillConversationIdFactoryOptions, ConversationReference], ) -> str: self.creation_options = options_or_conversation_reference key = self._conversation_id self._conversation_refs[key] = self._conversation_refs.get( key, SkillConversationReference( conversation_reference=options_or_conversation_reference. activity.get_conversation_reference(), oauth_scope=options_or_conversation_reference. from_bot_oauth_scope, ), ) return key
async def create_skill_conversation_id( # pylint: disable=W0221 self, options: SkillConversationIdFactoryOptions ) -> str: conversation_reference = TurnContext.get_conversation_reference( options.activity ) key = hashlib.md5( f"{conversation_reference.conversation.id}{conversation_reference.service_url}".encode() ).hexdigest() skill_conversation_reference = SkillConversationReference( conversation_reference=conversation_reference, oauth_scope=options.from_bot_oauth_scope, ) self._conversation_refs[key] = skill_conversation_reference return key
async def create_skill_conversation_id( self, options_or_conversation_reference: Union[ SkillConversationIdFactoryOptions, ConversationReference ], ) -> str: if not options_or_conversation_reference: raise TypeError("Need options or conversation reference") if not isinstance( options_or_conversation_reference, SkillConversationIdFactoryOptions ): raise TypeError( "This SkillConversationIdFactory can only handle SkillConversationIdFactoryOptions" ) options = options_or_conversation_reference # Create the storage key based on the SkillConversationIdFactoryOptions. conversation_reference = TurnContext.get_conversation_reference( options.activity ) skill_conversation_id = ( f"{conversation_reference.conversation.id}" f"-{options.bot_framework_skill.id}" f"-{conversation_reference.channel_id}" f"-skillconvo" ) # Create the SkillConversationReference instance. skill_conversation_reference = SkillConversationReference( conversation_reference=conversation_reference, oauth_scope=options.from_bot_oauth_scope, ) # Store the SkillConversationReference using the skill_conversation_id as a key. skill_conversation_info = {skill_conversation_id: skill_conversation_reference} await self._storage.write(skill_conversation_info) # Return the generated skill_conversation_id (that will be also used as the conversation ID to call the skill). return skill_conversation_id