From 4d18c11fbcc7ab746a07748f12fc0f487a228417 Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 23 May 2024 10:48:50 -0500 Subject: [PATCH 1/4] Corrections for errors in Skill Dialogs --- .../botbuilder/core/cloud_adapter_base.py | 12 +++++++++++- .../botbuilder/core/turn_context.py | 9 ++++++++- .../aiohttp/bot_framework_http_client.py | 14 ++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py index 7e996c90c..2780cdd87 100644 --- a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py +++ b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py @@ -150,7 +150,9 @@ async def continue_conversation( # pylint: disable=arguments-differ self, reference: ConversationReference, callback: Callable, - bot_app_id: str, + bot_app_id: str = None, # pylint: disable=unused-argument + claims_identity: ClaimsIdentity = None, # pylint: disable=unused-argument + audience: str = None, # pylint: disable=unused-argument ): """ Sends a proactive message to a conversation. @@ -166,6 +168,14 @@ async def continue_conversation( # pylint: disable=arguments-differ and is generally found in the `MicrosoftAppId` parameter in `config.py`. :type bot_app_id: :class:`typing.str` """ + if claims_identity: + return await self.continue_conversation_with_claims( + claims_identity=claims_identity, + reference=reference, + audience=audience, + logic=callback + ) + return await self.process_proactive( self.create_claims_identity(bot_app_id), get_continuation_activity(reference), diff --git a/libraries/botbuilder-core/botbuilder/core/turn_context.py b/libraries/botbuilder-core/botbuilder/core/turn_context.py index 2b4d688af..90ab99bd0 100644 --- a/libraries/botbuilder-core/botbuilder/core/turn_context.py +++ b/libraries/botbuilder-core/botbuilder/core/turn_context.py @@ -5,6 +5,7 @@ from copy import copy, deepcopy from datetime import datetime from typing import List, Callable, Union, Dict +from botframework.connector import Channels from botbuilder.schema import ( Activity, ActivityTypes, @@ -328,7 +329,13 @@ def get_conversation_reference(activity: Activity) -> ConversationReference: :return: """ return ConversationReference( - activity_id=activity.id, + activity_id=( + activity.id + if activity.type != ActivityTypes.conversation_update + and activity.channel_id != Channels.direct_line + and activity.channel_id != Channels.webchat + else None + ), user=copy(activity.from_property), bot=copy(activity.recipient), conversation=copy(activity.conversation), diff --git a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py index cf46a0081..662e21bb8 100644 --- a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py +++ b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py @@ -49,7 +49,6 @@ def __init__( self._credential_provider = credential_provider self._channel_provider = channel_provider self._logger = logger - self._session = aiohttp.ClientSession() async def post_activity( self, @@ -127,11 +126,14 @@ async def _post_content( ) json_content = json.dumps(activity.serialize()) - resp = await self._session.post( - to_url, - data=json_content.encode("utf-8"), - headers=headers_dict, - ) + + async with aiohttp.ClientSession() as session: + resp = await session.post( + to_url, + data=json_content.encode("utf-8"), + headers=headers_dict, + ) + resp.raise_for_status() data = (await resp.read()).decode() return resp.status, json.loads(data) if data else None From 8bc6cf221947b9e91a7f5a085dc3b083e1e2a23d Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 23 May 2024 10:52:25 -0500 Subject: [PATCH 2/4] black formatting --- .../botbuilder/core/cloud_adapter_base.py | 4 ++-- .../core/skills/_skill_handler_impl.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py index 2780cdd87..dac83b0ce 100644 --- a/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py +++ b/libraries/botbuilder-core/botbuilder/core/cloud_adapter_base.py @@ -173,9 +173,9 @@ async def continue_conversation( # pylint: disable=arguments-differ claims_identity=claims_identity, reference=reference, audience=audience, - logic=callback + logic=callback, ) - + return await self.process_proactive( self.create_claims_identity(bot_app_id), get_continuation_activity(reference), diff --git a/libraries/botbuilder-core/botbuilder/core/skills/_skill_handler_impl.py b/libraries/botbuilder-core/botbuilder/core/skills/_skill_handler_impl.py index dcd31a8c6..f50cd54ff 100644 --- a/libraries/botbuilder-core/botbuilder/core/skills/_skill_handler_impl.py +++ b/libraries/botbuilder-core/botbuilder/core/skills/_skill_handler_impl.py @@ -133,9 +133,9 @@ async def on_delete_activity( ) async def callback(turn_context: TurnContext): - turn_context.turn_state[ - self.SKILL_CONVERSATION_REFERENCE_KEY - ] = skill_conversation_reference + turn_context.turn_state[self.SKILL_CONVERSATION_REFERENCE_KEY] = ( + skill_conversation_reference + ) await turn_context.delete_activity(activity_id) await self._adapter.continue_conversation( @@ -160,9 +160,9 @@ async def on_update_activity( async def callback(turn_context: TurnContext): nonlocal resource_response - turn_context.turn_state[ - self.SKILL_CONVERSATION_REFERENCE_KEY - ] = skill_conversation_reference + turn_context.turn_state[self.SKILL_CONVERSATION_REFERENCE_KEY] = ( + skill_conversation_reference + ) activity.apply_conversation_reference( skill_conversation_reference.conversation_reference ) @@ -217,9 +217,9 @@ async def _process_activity( async def callback(context: TurnContext): nonlocal resource_response - context.turn_state[ - SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY - ] = skill_conversation_reference + context.turn_state[SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY] = ( + skill_conversation_reference + ) TurnContext.apply_conversation_reference( activity, skill_conversation_reference.conversation_reference From b5489a11460423b52c92b186423ed60dcf10e82b Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 23 May 2024 11:18:37 -0500 Subject: [PATCH 3/4] black formatting (PS. VS Code Black Formatter does not do exactly same thing as pipeline) --- .../botbuilder/adapters/slack/slack_helper.py | 8 +++++--- .../botbuilder/ai/luis/luis_recognizer.py | 6 +++--- .../botbuilder/ai/luis/luis_recognizer_v2.py | 16 ++++++++++------ .../botbuilder/ai/luis/luis_recognizer_v3.py | 8 +++++--- .../ai/qna/dialogs/qnamaker_dialog.py | 6 +++--- .../botbuilder/ai/qna/models/ranker_types.py | 1 - .../botbuilder/ai/qna/qnamaker.py | 6 +++--- .../botbuilder/ai/qna/utils/train_utils.py | 4 +++- .../botbuilder/core/bot_framework_adapter.py | 8 +++++--- .../core/inspection/inspection_middleware.py | 8 ++++---- .../core/telemetry_logger_middleware.py | 18 +++++++++--------- .../tests/skills/test_skill_handler.py | 6 +++--- .../tests/teams/test_teams_activity_handler.py | 6 +++--- .../botbuilder/dialogs/_user_token_access.py | 16 ++++++++++------ .../botbuilder/dialogs/dialog_context.py | 6 +++--- .../botbuilder/dialogs/dialog_extensions.py | 14 ++++++++------ .../botbuilder/dialogs/dialog_manager.py | 8 +++++--- .../dialogs/memory/dialog_state_manager.py | 6 +++--- .../botbuilder/dialogs/prompts/oauth_prompt.py | 6 +++--- .../botbuilder/dialogs/skills/skill_dialog.py | 12 ++++++------ .../tests/test_dialog_manager.py | 14 +++++--------- .../aiohttp/bot_framework_http_client.py | 1 - .../auth/certificate_app_credentials.py | 6 +++--- .../connector/auth/government_constants.py | 1 - .../tests/test_skill_validation.py | 12 ++++++------ 25 files changed, 108 insertions(+), 95 deletions(-) diff --git a/libraries/botbuilder-adapters-slack/botbuilder/adapters/slack/slack_helper.py b/libraries/botbuilder-adapters-slack/botbuilder/adapters/slack/slack_helper.py index 80d30d275..35f720c8d 100644 --- a/libraries/botbuilder-adapters-slack/botbuilder/adapters/slack/slack_helper.py +++ b/libraries/botbuilder-adapters-slack/botbuilder/adapters/slack/slack_helper.py @@ -128,9 +128,11 @@ def payload_to_activity(payload: SlackPayload) -> Activity: channel_id="slack", conversation=ConversationAccount(id=payload.channel["id"], properties={}), from_property=ChannelAccount( - id=payload.message.bot_id - if payload.message.bot_id - else payload.user["id"] + id=( + payload.message.bot_id + if payload.message.bot_id + else payload.user["id"] + ) ), recipient=ChannelAccount(), channel_data=payload, diff --git a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py index a95ebae96..bf6e15bfe 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py +++ b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer.py @@ -236,9 +236,9 @@ def fill_luis_event_properties( # Use the LogPersonalInformation flag to toggle logging PII data, text is a common example if self.log_personal_information and turn_context.activity.text: - properties[ - LuisTelemetryConstants.question_property - ] = turn_context.activity.text + properties[LuisTelemetryConstants.question_property] = ( + turn_context.activity.text + ) # Additional Properties can override "stock" properties. if telemetry_properties is not None: diff --git a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py index b58c9b40c..507b10774 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py +++ b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v2.py @@ -53,9 +53,11 @@ async def recognizer_internal(self, turn_context: TurnContext): staging=self.luis_recognizer_options_v2.staging, spell_check=self.luis_recognizer_options_v2.spell_check, bing_spell_check_subscription_key=self.luis_recognizer_options_v2.bing_spell_check_subscription_key, - log=self.luis_recognizer_options_v2.log - if self.luis_recognizer_options_v2.log is not None - else True, + log=( + self.luis_recognizer_options_v2.log + if self.luis_recognizer_options_v2.log is not None + else True + ), ) recognizer_result: RecognizerResult = RecognizerResult( @@ -65,9 +67,11 @@ async def recognizer_internal(self, turn_context: TurnContext): entities=LuisUtil.extract_entities_and_metadata( luis_result.entities, luis_result.composite_entities, - self.luis_recognizer_options_v2.include_instance_data - if self.luis_recognizer_options_v2.include_instance_data is not None - else True, + ( + self.luis_recognizer_options_v2.include_instance_data + if self.luis_recognizer_options_v2.include_instance_data is not None + else True + ), ), ) diff --git a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py index b487abfb5..4e373023e 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py +++ b/libraries/botbuilder-ai/botbuilder/ai/luis/luis_recognizer_v3.py @@ -116,9 +116,11 @@ def _build_url(self): uri += "/slots/%s/predict" % (self.luis_recognizer_options_v3.slot) params = "?verbose=%s&show-all-intents=%s&log=%s" % ( - "true" - if self.luis_recognizer_options_v3.include_instance_data - else "false", + ( + "true" + if self.luis_recognizer_options_v3.include_instance_data + else "false" + ), "true" if self.luis_recognizer_options_v3.include_all_intents else "false", "true" if self.luis_recognizer_options_v3.log else "false", ) diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/dialogs/qnamaker_dialog.py b/libraries/botbuilder-ai/botbuilder/ai/qna/dialogs/qnamaker_dialog.py index f1b052207..4bcceebaa 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/dialogs/qnamaker_dialog.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/dialogs/qnamaker_dialog.py @@ -248,9 +248,9 @@ async def __call_generate_answer(self, step_context: WaterfallStepContext): dialog_options.options.context = QnARequestContext() # Storing the context info - step_context.values[ - QnAMakerDialog.PROPERTY_CURRENT_QUERY - ] = step_context.context.activity.text + step_context.values[QnAMakerDialog.PROPERTY_CURRENT_QUERY] = ( + step_context.context.activity.text + ) # -Check if previous context is present, if yes then put it with the query # -Check for id if query is present in reverse index. diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/models/ranker_types.py b/libraries/botbuilder-ai/botbuilder/ai/qna/models/ranker_types.py index 55d6799aa..811d61623 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/models/ranker_types.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/models/ranker_types.py @@ -3,7 +3,6 @@ class RankerTypes: - """Default Ranker Behaviour. i.e. Ranking based on Questions and Answer.""" DEFAULT = "Default" diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py index e0bf9bae1..825e08e8e 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py @@ -182,9 +182,9 @@ async def fill_qna_event( properties: Dict[str, str] = dict() metrics: Dict[str, float] = dict() - properties[ - QnATelemetryConstants.knowledge_base_id_property - ] = self._endpoint.knowledge_base_id + properties[QnATelemetryConstants.knowledge_base_id_property] = ( + self._endpoint.knowledge_base_id + ) text: str = turn_context.activity.text user_name: str = turn_context.activity.from_property.name diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/utils/train_utils.py b/libraries/botbuilder-ai/botbuilder/ai/qna/utils/train_utils.py index 31c1ee441..b47eca8f9 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/utils/train_utils.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/utils/train_utils.py @@ -45,7 +45,9 @@ async def call_train(self, feedback_records: List[FeedbackRecord]): await self._query_train(feedback_records) async def _query_train(self, feedback_records: List[FeedbackRecord]): - url: str = f"{ self._endpoint.host }/knowledgebases/{ self._endpoint.knowledge_base_id }/train" + url: str = ( + f"{ self._endpoint.host }/knowledgebases/{ self._endpoint.knowledge_base_id }/train" + ) payload_body = TrainRequestBody(feedback_records=feedback_records) http_request_helper = HttpRequestUtils(self._http_client) diff --git a/libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py b/libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py index 42df5d73a..601693fd3 100644 --- a/libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py +++ b/libraries/botbuilder-core/botbuilder/core/bot_framework_adapter.py @@ -387,9 +387,11 @@ async def create_conversation( name=ActivityEventNames.create_conversation, channel_id=channel_id, service_url=service_url, - id=resource_response.activity_id - if resource_response.activity_id - else str(uuid.uuid4()), + id=( + resource_response.activity_id + if resource_response.activity_id + else str(uuid.uuid4()) + ), conversation=ConversationAccount( id=resource_response.id, tenant_id=parameters.tenant_id, diff --git a/libraries/botbuilder-core/botbuilder/core/inspection/inspection_middleware.py b/libraries/botbuilder-core/botbuilder/core/inspection/inspection_middleware.py index 2f84b0efd..bf817c1af 100644 --- a/libraries/botbuilder-core/botbuilder/core/inspection/inspection_middleware.py +++ b/libraries/botbuilder-core/botbuilder/core/inspection/inspection_middleware.py @@ -95,10 +95,10 @@ async def _trace_state(self, context: TurnContext) -> Any: ) if self.conversation_state: - bot_state[ - "conversation_state" - ] = InspectionMiddleware._get_serialized_context( - self.conversation_state, context + bot_state["conversation_state"] = ( + InspectionMiddleware._get_serialized_context( + self.conversation_state, context + ) ) await self._invoke_send(context, session, from_state(bot_state)) diff --git a/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py b/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py index 7f65d95d5..d14c3f7f2 100644 --- a/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py +++ b/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py @@ -164,9 +164,9 @@ async def fill_receive_event_properties( BotTelemetryClient.track_event method for the BotMessageReceived event. """ properties = { - TelemetryConstants.FROM_ID_PROPERTY: activity.from_property.id - if activity.from_property - else None, + TelemetryConstants.FROM_ID_PROPERTY: ( + activity.from_property.id if activity.from_property else None + ), TelemetryConstants.CONVERSATION_NAME_PROPERTY: activity.conversation.name, TelemetryConstants.LOCALE_PROPERTY: activity.locale, TelemetryConstants.RECIPIENT_ID_PROPERTY: activity.recipient.id, @@ -179,9 +179,9 @@ async def fill_receive_event_properties( and activity.from_property.name and activity.from_property.name.strip() ): - properties[ - TelemetryConstants.FROM_NAME_PROPERTY - ] = activity.from_property.name + properties[TelemetryConstants.FROM_NAME_PROPERTY] = ( + activity.from_property.name + ) if activity.text and activity.text.strip(): properties[TelemetryConstants.TEXT_PROPERTY] = activity.text if activity.speak and activity.speak.strip(): @@ -224,9 +224,9 @@ async def fill_send_event_properties( activity.attachments ) if activity.from_property.name and activity.from_property.name.strip(): - properties[ - TelemetryConstants.FROM_NAME_PROPERTY - ] = activity.from_property.name + properties[TelemetryConstants.FROM_NAME_PROPERTY] = ( + activity.from_property.name + ) if activity.text and activity.text.strip(): properties[TelemetryConstants.TEXT_PROPERTY] = activity.text if activity.speak and activity.speak.strip(): diff --git a/libraries/botbuilder-core/tests/skills/test_skill_handler.py b/libraries/botbuilder-core/tests/skills/test_skill_handler.py index 722a944b8..66d79c2ce 100644 --- a/libraries/botbuilder-core/tests/skills/test_skill_handler.py +++ b/libraries/botbuilder-core/tests/skills/test_skill_handler.py @@ -244,9 +244,9 @@ def setUpClass(cls): cls._claims_identity.claims[AuthenticationConstants.AUDIENCE_CLAIM] = cls.bot_id cls._claims_identity.claims[AuthenticationConstants.APP_ID_CLAIM] = cls.skill_id - cls._claims_identity.claims[ - AuthenticationConstants.SERVICE_URL_CLAIM - ] = "http://testbot.com/api/messages" + cls._claims_identity.claims[AuthenticationConstants.SERVICE_URL_CLAIM] = ( + "http://testbot.com/api/messages" + ) cls._conversation_reference = ConversationReference( conversation=ConversationAccount(id=str(uuid4())), service_url="http://testbot.com/api/messages", diff --git a/libraries/botbuilder-core/tests/teams/test_teams_activity_handler.py b/libraries/botbuilder-core/tests/teams/test_teams_activity_handler.py index 9a1872952..32e9f2edb 100644 --- a/libraries/botbuilder-core/tests/teams/test_teams_activity_handler.py +++ b/libraries/botbuilder-core/tests/teams/test_teams_activity_handler.py @@ -595,9 +595,9 @@ async def test_on_teams_members_added_activity(self): mock_connector_client = await SimpleAdapter.create_connector_client( self, turn_context.activity.service_url ) - turn_context.turn_state[ - BotAdapter.BOT_CONNECTOR_CLIENT_KEY - ] = mock_connector_client + turn_context.turn_state[BotAdapter.BOT_CONNECTOR_CLIENT_KEY] = ( + mock_connector_client + ) # Act bot = TestingTeamsActivityHandler() diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/_user_token_access.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/_user_token_access.py index cd2874ad4..0aa005789 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/_user_token_access.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/_user_token_access.py @@ -56,9 +56,11 @@ async def get_sign_in_resource( turn_context, settings.oath_app_credentials, settings.connection_name, - turn_context.activity.from_property.id - if turn_context.activity and turn_context.activity.from_property - else None, + ( + turn_context.activity.from_property.id + if turn_context.activity and turn_context.activity.from_property + else None + ), ) raise TypeError("OAuthPrompt is not supported by the current adapter") @@ -78,9 +80,11 @@ async def sign_out_user(turn_context: TurnContext, settings: OAuthPromptSettings return await turn_context.adapter.sign_out_user( turn_context, settings.connection_name, - turn_context.activity.from_property.id - if turn_context.activity and turn_context.activity.from_property - else None, + ( + turn_context.activity.from_property.id + if turn_context.activity and turn_context.activity.from_property + else None + ), settings.oath_app_credentials, ) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py index f221708f1..0181e67a2 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py @@ -408,9 +408,9 @@ def __set_exception_context_data(self, exception: Exception): current_dc = current_dc.parent exception.data[type(self).__name__] = { - "active_dialog": None - if self.active_dialog is None - else self.active_dialog.id, + "active_dialog": ( + None if self.active_dialog is None else self.active_dialog.id + ), "parent": None if self.parent is None else self.parent.active_dialog.id, "stack": self.stack, } diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_extensions.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_extensions.py index a5a8a34ab..f9fb67c96 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_extensions.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_extensions.py @@ -50,9 +50,9 @@ async def _internal_run( # get the DialogStateManager configuration dialog_state_manager = DialogStateManager(dialog_context) await dialog_state_manager.load_all_scopes() - dialog_context.context.turn_state[ - dialog_state_manager.__class__.__name__ - ] = dialog_state_manager + dialog_context.context.turn_state[dialog_state_manager.__class__.__name__] = ( + dialog_state_manager + ) # Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn. @@ -130,9 +130,11 @@ async def __inner_run( type=ActivityTypes.end_of_conversation, value=result.result, locale=turn_context.activity.locale, - code=EndOfConversationCodes.completed_successfully - if result.status == DialogTurnStatus.Complete - else EndOfConversationCodes.user_cancelled, + code=( + EndOfConversationCodes.completed_successfully + if result.status == DialogTurnStatus.Complete + else EndOfConversationCodes.user_cancelled + ), ) await turn_context.send_activity(activity) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_manager.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_manager.py index 84dc108c2..df7a5569e 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_manager.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_manager.py @@ -291,9 +291,11 @@ async def handle_skill_on_turn( type=ActivityTypes.end_of_conversation, value=turn_result.result, locale=turn_context.activity.locale, - code=EndOfConversationCodes.completed_successfully - if turn_result.status == DialogTurnStatus.Complete - else EndOfConversationCodes.user_cancelled, + code=( + EndOfConversationCodes.completed_successfully + if turn_result.status == DialogTurnStatus.Complete + else EndOfConversationCodes.user_cancelled + ), ) await turn_context.send_activity(activity) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/memory/dialog_state_manager.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/memory/dialog_state_manager.py index c1bf6c106..a11ab9c3a 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/memory/dialog_state_manager.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/memory/dialog_state_manager.py @@ -94,9 +94,9 @@ def __init__( self._configuration.path_resolvers.append(path_resolver) # cache for any other new dialog_state_manager instances in this turn. - dialog_context.context.turn_state[ - self._configuration.__class__.__name__ - ] = self._configuration + dialog_context.context.turn_state[self._configuration.__class__.__name__] = ( + self._configuration + ) def __len__(self) -> int: """ diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py index 55fae561f..e0db0e2bb 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py @@ -415,9 +415,9 @@ async def _recognize_token( state.scope, ) - context.turn_state[ - BotAdapter.BOT_CONNECTOR_CLIENT_KEY - ] = connector_client + context.turn_state[BotAdapter.BOT_CONNECTOR_CLIENT_KEY] = ( + connector_client + ) elif OAuthPrompt._is_teams_verification_invoke(context): code = context.activity.value["state"] diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/skills/skill_dialog.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/skills/skill_dialog.py index 81b67de18..e5be50c24 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/skills/skill_dialog.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/skills/skill_dialog.py @@ -60,17 +60,17 @@ async def begin_dialog(self, dialog_context: DialogContext, options: object = No ) # Store delivery mode in dialog state for later use. - dialog_context.active_dialog.state[ - self._deliver_mode_state_key - ] = dialog_args.activity.delivery_mode + dialog_context.active_dialog.state[self._deliver_mode_state_key] = ( + dialog_args.activity.delivery_mode + ) # Create the conversationId and store it in the dialog context state so we can use it later skill_conversation_id = await self._create_skill_conversation_id( dialog_context.context, dialog_context.context.activity ) - dialog_context.active_dialog.state[ - SkillDialog.SKILLCONVERSATIONIDSTATEKEY - ] = skill_conversation_id + dialog_context.active_dialog.state[SkillDialog.SKILLCONVERSATIONIDSTATEKEY] = ( + skill_conversation_id + ) # Send the activity to the skill. eoc_activity = await self._send_to_skill( diff --git a/libraries/botbuilder-dialogs/tests/test_dialog_manager.py b/libraries/botbuilder-dialogs/tests/test_dialog_manager.py index 1846ce42f..57b264e60 100644 --- a/libraries/botbuilder-dialogs/tests/test_dialog_manager.py +++ b/libraries/botbuilder-dialogs/tests/test_dialog_manager.py @@ -120,17 +120,13 @@ 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" - ] = ( + claims_identity.claims["ver"] = ( + "2.0" # AuthenticationConstants.VersionClaim + ) + claims_identity.claims["aud"] = ( SimpleComponentDialog.skill_bot_id ) # AuthenticationConstants.AudienceClaim - claims_identity.claims[ - "azp" - ] = ( + claims_identity.claims["azp"] = ( SimpleComponentDialog.parent_bot_id ) # AuthenticationConstants.AuthorizedParty context.turn_state[BotAdapter.BOT_IDENTITY_KEY] = claims_identity diff --git a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py index 662e21bb8..b09b3ac93 100644 --- a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py +++ b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/bot_framework_http_client.py @@ -27,7 +27,6 @@ class BotFrameworkHttpClient(BotFrameworkClient): - """ A skill host adapter that implements the API to forward activity to a skill and implements routing ChannelAPI calls from the skill up through the bot/adapter. diff --git a/libraries/botframework-connector/botframework/connector/auth/certificate_app_credentials.py b/libraries/botframework-connector/botframework/connector/auth/certificate_app_credentials.py index a458ce5bb..b39511d82 100644 --- a/libraries/botframework-connector/botframework/connector/auth/certificate_app_credentials.py +++ b/libraries/botframework-connector/botframework/connector/auth/certificate_app_credentials.py @@ -77,9 +77,9 @@ def __get_msal_app(self): client_credential={ "thumbprint": self.certificate_thumbprint, "private_key": self.certificate_private_key, - "public_certificate": self.certificate_public - if self.certificate_public - else None, + "public_certificate": ( + self.certificate_public if self.certificate_public else None + ), }, ) diff --git a/libraries/botframework-connector/botframework/connector/auth/government_constants.py b/libraries/botframework-connector/botframework/connector/auth/government_constants.py index aba16e396..3e109d3b6 100644 --- a/libraries/botframework-connector/botframework/connector/auth/government_constants.py +++ b/libraries/botframework-connector/botframework/connector/auth/government_constants.py @@ -5,7 +5,6 @@ class GovernmentConstants(ABC): - """ Government Channel Service property value """ diff --git a/libraries/botframework-connector/tests/test_skill_validation.py b/libraries/botframework-connector/tests/test_skill_validation.py index a7667c3d7..bfa4951ce 100644 --- a/libraries/botframework-connector/tests/test_skill_validation.py +++ b/libraries/botframework-connector/tests/test_skill_validation.py @@ -37,9 +37,9 @@ def test_is_skill_claim_test(self): assert not SkillValidation.is_skill_claim(claims) # Emulator Audience claim - claims[ - AuthenticationConstants.AUDIENCE_CLAIM - ] = AuthenticationConstants.TO_BOT_FROM_CHANNEL_TOKEN_ISSUER + claims[AuthenticationConstants.AUDIENCE_CLAIM] = ( + AuthenticationConstants.TO_BOT_FROM_CHANNEL_TOKEN_ISSUER + ) assert not SkillValidation.is_skill_claim(claims) # No AppId claim @@ -53,9 +53,9 @@ def test_is_skill_claim_test(self): # Anonymous skill app id del claims[AuthenticationConstants.APP_ID_CLAIM] - claims[ - AuthenticationConstants.APP_ID_CLAIM - ] = AuthenticationConstants.ANONYMOUS_SKILL_APP_ID + claims[AuthenticationConstants.APP_ID_CLAIM] = ( + AuthenticationConstants.ANONYMOUS_SKILL_APP_ID + ) assert SkillValidation.is_skill_claim(claims) # All checks pass, should be good now From 77e1f758386826f03cd77a7045631d8339b8b39d Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Thu, 23 May 2024 11:59:12 -0500 Subject: [PATCH 4/4] Test correction for Skill Dialog fix --- .../aiohttp/skills/aio_http_client_factory.py | 10 ++++------ .../tests/skills/test_skill_http_client.py | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/skills/aio_http_client_factory.py b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/skills/aio_http_client_factory.py index 84235e86b..62d4ae539 100644 --- a/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/skills/aio_http_client_factory.py +++ b/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/skills/aio_http_client_factory.py @@ -31,13 +31,11 @@ async def read_content_str(self) -> str: class _HttpClientImplementation(HttpClientBase): - def __init__(self) -> None: - self._session = ClientSession() - async def post(self, *, request: HttpRequest) -> HttpResponseBase: - aio_response = await self._session.post( - request.request_uri, data=request.content, headers=request.headers - ) + async with ClientSession() as session: + aio_response = await session.post( + request.request_uri, data=request.content, headers=request.headers + ) return _HttpResponseImpl(aio_response) diff --git a/libraries/botbuilder-integration-aiohttp/tests/skills/test_skill_http_client.py b/libraries/botbuilder-integration-aiohttp/tests/skills/test_skill_http_client.py index b3db490b7..eba3352e1 100644 --- a/libraries/botbuilder-integration-aiohttp/tests/skills/test_skill_http_client.py +++ b/libraries/botbuilder-integration-aiohttp/tests/skills/test_skill_http_client.py @@ -200,6 +200,5 @@ async def _create_http_client_with_mock_handler( # pylint: disable=protected-access client = SkillHttpClient(Mock(), id_factory, channel_provider) client._post_content = value_function - await client._session.close() return client