8000 Merge branch 'master' into v-bruhal/expazcontainer5-27 · TaffyWrinkle/botbuilder-python@4a21e60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a21e60

Browse files
authored
Merge branch 'master' into v-bruhal/expazcontainer5-27
2 parents 62057df + 37aa423 commit 4a21e60

File tree

16 files changed

+346
-36
lines changed

16 files changed

+346
-36
lines changed

.github/CODEOWNERS

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# More details are here: https://help.github.com/articles/about-codeowners/
5+
6+
# The '*' pattern is global owners.
7+
8+
# Order is important. The last matching pattern has the most precedence.
9+
# The folders are ordered as follows:
10+
11+
# In each subsection folders are ordered first by depth, then alphabetically.
12+
# This should make it easy to add new rules without breaking existing ones.
13+
14+
# Global rule:
15+
* @microsoft/bb-python
16+
17+
# Functional tests
18+
/libraries/functional-tests/** @tracyboehrer
19+
20+
# Adapters
21+
/libraries/botbuilder-adapters-slack/** @tracyboehrer @garypretty
22+
23+
# Platform Integration Libaries (aiohttp)
24+
/libraries/botbuilder-integration-aiohttp/** @microsoft/bb-python-integration
25+
/libraries/botbuilder-integration-applicationinsights-aiohttp/** @microsoft/bb-python-integration @garypretty
26+
27+
# Application Insights/Telemetry
28+
/libraries/botbuilder-applicationinsights/** @axelsrz @garypretty
29+
30+
# AI: LUIS + QnA Maker
31+
/libraries/botbuilder-ai/** @microsoft/bf-cog-services
32+
33+
# Azure (Storage)
34+
/libraries/botbuilder-azure/** @tracyboehrer @EricDahlvang
35+
36+
# Adaptive Dialogs
37+
/libraries/botbuilder-dialogs-*/** @tracyboehrer @microsoft/bf-adaptive
38+
39+
# AdaptiveExpressions & LanguageGeneration libraries
40+
/libraries/adaptive-expressions/** @axelsrz @microsoft/bf-adaptive
41+
/libraries/botbuilder-lg/** @axelsrz @microsoft/bf-adaptive
42+
43+
# BotBuilder Testing
44+
/libraries/botbuilder-testing/** @axelsrz @gabog
45+
46+
# Streaming library
47+
/libraries/botbuilder-streaming/** @microsoft/bf-streaming
48+
49+
# BotBuilder library
50+
/libraries/botbuilder-core/** @axelsrz @gabog @johnataylor
51+
52+
# BotBuilder Dialogs
53+
/libraries/botbuilder-dialogs/** @microsoft/bf-dialogs
54+
55+
# Swagger
56+
/libraries/swagger/** @axelsrz @EricDahlvang
57+
58+
# Bot Framework Schema
59+
/libraries/botbuilder-schema/** @EricDahlvang @johnataylor
60+
61+
# Bot Framework connector
62+
libraries\botframework-connector/** @axelsrz @carlosscastro @johnataylor
63+
64+
# Bot Framework Authentication
65+
/libraries/botbuilder-core/botbuilder/core/oauth/** @microsoft/bf-auth
66+
/libraries/botframework-connector/botframework/connector/auth/** @microsoft/bf-auth
67+
68+
# Bot Framework Skills
69+
/libraries/botbuilder-core/botbuilder/core/skills/** @microsoft/bf-skills
70+
/libraries/botbuilder-integration-aiohttp/botbuilder/integration/aiohttp/skills/** @microsoft/bf-skills
71+
/tests/skills/** @microsoft/bf-skills
72+
73+
# Bot Framework & Microsoft Teams
74+
/libraries/botbuilder-core/botbuilder/core/teams/** @microsoft/bf-teams
75+
/libraries/botbuilder-schema/botbuilder/schema/teams/** @microsoft/bf-teams
76+
/tests/teams/** @microsoft/bf-teams
77+
78+
# Ownership by specific files or file types
79+
# This section MUST stay at the bottom of the CODEOWNERS file. For more information, see
80+
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#example-of-a-codeowners-file
81+
82+
# Shipped package files
83+
# e.g. READMEs, requirements.txt, setup.py, MANIFEST.in
84+
/libraries/**/README.rst @microsoft/bb-python
85+
/libraries/**/requirements.txt @microsoft/bb-python
86+
/libraries/**/setup.py @microsoft/bb-python
87+
/libraries/**/setup.cfg @microsoft/bb-python
88+
/libraries/**/MANIFEST.in @microsoft/bb-python
89+
90+
# CODEOWNERS
91+
/.github/CODEOWNERS @stevengum @cleemullins @microsoft/bb-python

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### [What's new with Bot Framework](https://docs.microsoft.com/en-us/azure/bot-service/what-is-new?view=azure-bot-service-4.0)
44

5-
This repository contains code for the Python version of the [Microsoft Bot Framework SDK](https://github.com/Microsoft/botframework-sdk), which is part of the Microsoft Bot Framework - a comprehensive framework for building enterprise-grade conversational AI experiences.
5+
This repository contains code for the Python version of the [Microsoft Bot Framework SDK](https://github.com/Microsoft/botframework-sdk), which is part of the Microsoft Bot Framework - a comprehensive framework for building enterprise-grade conversational AI experiences.
66

77
This SDK enables developers to model conversation and build sophisticated bot applications using Python. SDKs for [JavaScript](https://github.com/Microsoft/botbuilder-js), [.NET](https://github.com/Microsoft/botbuilder-dotnet) and [Java (preview)](https://github.com/Microsoft/botbuilder-java) are also available.
88

@@ -15,7 +15,7 @@ For more information jump to a section below.
1515
* [Getting started](#getting-started)
1616
* [Getting support and providing feedback](#getting-support-and-providing-feedback)
1717
* [Contributing and our code of conduct](contributing-and-our-code-of-conduct)
18-
* [Reporting security sssues](#reporting-security-issues)
18+
* [Reporting security issues](#reporting-security-issues)
1919

2020
## Build Status
2121

@@ -40,13 +40,13 @@ To get started building bots using the SDK, see the [Azure Bot Service Documenta
4040

4141
The [Bot Framework Samples](https://github.com/microsoft/botbuilder-samples) includes a rich set of samples repository.
4242

43-
If you want to debug an issue, would like to [contribute](#contributing), or understand how the Bot Builder SDK works, instructions for building and testing the SDK are below.
43+
If you want to debug an issue, would like to [contribute](#contributing-code), or understand how the Bot Builder SDK works, instructions for building and testing the SDK are below.
4444

4545
### Prerequisites
4646
- [Git](https://git-scm.com/downloads)
4747
- [Python 3.8.2](https://www.python.org/downloads/)
4848

49-
Python "Virtual Environments" allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally, as such it is common practice to use them. Click [here](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments) to learn more about creating _and activating_ Virtual Environments in Python.
49+
Python "Virtual Environments" allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally, as such it is common practice to use them. Click [here](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments) to learn more about creating _and activating_ Virtual Environments in Python.
5050

5151
### Clone
5252
Clone a copy of the repo:
@@ -60,12 +60,7 @@ cd botbuilder-python
6060

6161
### Using the SDK locally
6262

63-
You will need the following 3 packages installed in your environment:
64-
- [botframework-connector](https://pypi.org/project/botframework-connector/)
65-
- [botbuilder-core](https://pypi.org/project/botbuilder-core/)
66-
- [botbuilder-schema](https://pypi.org/project/botbuilder-schema/)
67-
68-
To use a local copy of the SDK you can link to these packages with the pip -e option.
63+
To use a local copy of the SDK you can link to these packages with the pip -e option.
6964

7065
```bash
7166
pip install -e ./libraries/botbuilder-schema
@@ -108,12 +103,12 @@ plugins: cov-2.5.1
108103
Below are the various channels that are available to you for obtaining support and providing feedback. Please pay carful attention to which channel should be used for which type of content. e.g. general "how do I..." questions should be asked on Stack Overflow, Twitter or Gitter, with GitHub issues being for feature requests and bug reports.
109104

110105
### Github issues
111-
[Github issues](https://github.com/Microsoft/botbuilder-python/issues) should be used for bugs and feature requests.
106+
[Github issues](https://github.com/Microsoft/botbuilder-python/issues) should be used for bugs and feature requests.
112107

113108
### Stack overflow
114109
[Stack Overflow](https://stackoverflow.com/questions/tagged/botframework) is a great place for getting high-quality answers. Our support team, as well as many of our community members are already on Stack Overflow providing answers to 'how-to' questions.
115110

116-
### Azure Support
111+
### Azure Support
117112
If you issues relates to [Azure Bot Service](https://azure.microsoft.com/en-gb/services/bot-service/), you can take advantage of the available [Azure support options](https://azure.microsoft.com/en-us/support/options/).
118113

119114
### Twitter
@@ -125,15 +120,25 @@ The [Gitter Channel](https://gitter.im/Microsoft/BotBuilder) provides a place wh
125120
## Contributing and our code of conduct
126121
We welcome contributions and suggestions. Please see our [contributing guidelines](./contributing.md) for more information.
127122

128-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
123+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
124+
129125
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact
130126
[opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
131127

128+
### Contributing Code
129+
130+
In order to create pull requests, submitted code must pass ```pylint``` and ```black``` checks. Run both tools on every file you've changed.
131+
132+
For more information and installation instructions, see:
133+
134+
* [black](https://pypi.org/project/black/)
135+
* [pylint](https://pylint.org/)
136+
132137
## Reporting Security Issues
133-
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC)
138+
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC)
134139
at [secure@microsoft.com](mailto:secure@microsoft.com). You should receive a response within 24 hours. If for some
135-
reason you do not, please follow up via email to ensure we received your original message. Further information,
136-
including the [MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can be found in the
140+
reason you do not, please follow up via email to ensure we received your original message. Further information,
141+
including the [MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can be found in the
137142
[Security TechCenter](https://technet.microsoft.com/en-us/security/default).
138143

139144
Copyright (c) Microsoft Corporation. All rights reserved.

libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/application_insights_telemetry_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ def __init__(
3838
instrumentation_key: str,
3939
telemetry_client: TelemetryClient = None,
4040
telemetry_processor: Callable[[object, object], bool] = None,
41+
client_queue_size: int = None,
4142
):
4243
self._instrumentation_key = instrumentation_key
44+
4345
self._client = (
4446
telemetry_client
4547
if telemetry_client is not None
4648
else TelemetryClient(self._instrumentation_key)
4749
)
50+
if client_queue_size:
51+
self._client.channel.queue.max_queue_length = client_queue_size
52+
4853
# Telemetry Processor
4954
processor = (
5055
telemetry_processor

libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
import base64
34
import json
45
from abc import ABC, abstractmethod
6+
from _sha256 import sha256
57

68

79
class TelemetryProcessor(ABC):
@@ -11,8 +13,9 @@ class TelemetryProcessor(ABC):
1113
def activity_json(self) -> json:
1214
"""Retrieve the request body as json (Activity)."""
1315
body_text = self.get_request_body()
14-
body = json.loads(body_text) if body_text is not None else None
15-
return body
16+
if body_text:
17+
return body_text if isinstance(body_text, dict) else json.loads(body_text)
18+
return None
1619

1720
@abstractmethod
1821
def can_process(self) -> bool:
@@ -67,15 +70,34 @@ def __call__(self, data, context) -> bool:
6770
conversation = (
6871
post_data["conversation"] if "conversation" in post_data else None
6972
)
70-
conversation_id = conversation["id"] if "id" in conversation else None
73+
74+
session_id = ""
75+
if "id" in conversation:
76+
conversation_id = conversation["id"]
77+
session_id = base64.b64encode(
78+
sha256(conversation_id.encode("utf-8")).digest()
79+
).decode()
80+
81+
# Set the user id on the Application Insights telemetry item.
7182
context.user.id = channel_id + user_id
72-
context.session.id = conversation_id
7383

74-
# Additional bot-specific properties
84+
# Set the session id on the Application Insights telemetry item.
85+
# Hashed ID is used due to max session ID length for App Insights session Id
86 10000 +
context.session.id = session_id
87+
88+
# Set the activity id:
89+
# https://github.com/Microsoft/botframework-obi/blob/master/botframework-activity/botframework-activity.md#id
7590
if "id" in post_data:
7691
data.properties["activityId"] = post_data["id"]
92+
93+
# Set the channel id:
94+
# https://github.com/Microsoft/botframework-obi/blob/master/botframework-activity/botframework-activity.md#channel-id
7795
if "channelId" in post_data:
7896
data.properties["channelId"] = post_data["channelId"]
97+
98+
# Set the activity type:
99+
# https://github.com/Microsoft/botframework-obi/blob/master/botframework-activity/botframework-activity.md#type
79100
if "type" in post_data:
80101
data.properties["activityType"] = post_data["type"]
102+
81103
return True

libraries/botbuilder-core/botbuilder/core/adapter_extensions.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
from warnings import warn
4+
35
from botbuilder.core import (
46
BotAdapter,
7+
BotState,
58
Storage,
69
RegisterClassMiddleware,
710
UserState,
@@ -23,6 +26,39 @@ def use_storage(adapter: BotAdapter, storage: Storage) -> BotAdapter:
2326
"""
2427
return adapter.use(RegisterClassMiddleware(storage))
2528

29+
@staticmethod
30+
def use_bot_state(
31+
bot_adapter: BotAdapter, *bot_states: BotState, auto: bool = True
32+
) -> BotAdapter:
33+
"""
34+
Registers bot state object into the TurnContext. The botstate will be available via the turn context.
35+
36+
:param bot_adapter: The BotAdapter on which to register the state objects.
37+
:param bot_states: One or more BotState objects to register.
38+
:return: The updated adapter.
39+
"""
40+
if not bot_states:
41+
raise TypeError("At least one BotAdapter is required")
42+
43+
for bot_state in bot_states:
44+
bot_adapter.use(
45+
RegisterClassMiddleware(
46+
bot_state, AdapterExtensions.fullname(bot_state)
47+
)
48+
)
49+
50+
if auto:
51+
bot_adapter.use(AutoSaveStateMiddleware(bot_states))
52+
53+
return bot_adapter
54+
55+
@staticmethod
56+
def fullname(obj):
57+
module = obj.__class__.__module__
58+
if module is None or module == str.__class__.__module__:
59+
return obj.__class__.__name__ # Avoid reporting __builtin__
60+
return module + "." + obj.__class__.__name__
61+
2662
@staticmethod
2763
def use_state(
2864
adapter: BotAdapter,
@@ -31,7 +67,7 @@ def use_state(
3167
auto: bool = True,
3268
) -> BotAdapter:
3369
"""
34-
Registers user and conversation state objects with the adapter. These objects will be available via
70+
[DEPRECATED] Registers user and conversation state objects with the adapter. These objects will be available via
3571
the turn context's `turn_state` property.
3672
3773
:param adapter: The BotAdapter on which to register the state objects.
@@ -40,6 +76,11 @@ def use_state(
4076
:param auto: True to automatically persist state each turn.
4177
:return: The BotAdapter
4278
"""
79+
warn(
80+
"This method is deprecated in 4.9. You should use the method .use_bot_state() instead.",
81+
DeprecationWarning,
82+
)
83+
4384
if not adapter:
4485
raise TypeError("BotAdapter is required")
4586

libraries/botbuilder-core/botbuilder/core/register_class_middleware.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ class RegisterClassMiddleware(Middleware):
1010
Middleware for adding an object to or registering a service with the current turn context.
1111
"""
1212

13-
def __init__(self, service):
13+
def __init__(self, service, key: str = None):
1414
self.service = service
15+
self._key = key
1516

1617
async def on_turn(
1718
self, context: TurnContext, logic: Callable[[TurnContext], Awaitable]
1819
):
1920
# C# has TurnStateCollection with has overrides for adding items
2021
# to TurnState. Python does not. In C#'s case, there is an 'Add'
2122
# to handle adding object, and that uses the fully qualified class name.
22-
context.turn_state[self.fullname(self.service)] = self.service
23+
key = self._key or self.fullname(self.service)
24+
context.turn_state[key] = self.service
2325
await logic()
2426

2527
@staticmethod

libraries/botbuilder-core/botbuilder/core/skills/skill_handler.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ async def _process_activity(
151151
if not skill_conversation_reference:
152152
raise KeyError("SkillConversationReference not found")
153153

154+
if not skill_conversation_reference.conversation_reference:
155+
raise KeyError("conversationReference not found")
156+
157+
# If an activity is sent, return the ResourceResponse
158+
resource_response: ResourceResponse = None
159+
154160
async def callback(context: TurnContext):
161+
nonlocal resource_response
155162
context.turn_state[
156163
SkillHandler.SKILL_CONVERSATION_REFERENCE_KEY
157164
] = skill_conversation_reference
@@ -177,15 +184,19 @@ async def callback(context: TurnContext):
177184
self._apply_event_to_turn_context_activity(context, activity)
178185
await self._bot.on_turn(context)
179186
else:
180-
await context.send_activity(activity)
187+
resource_response = await context.send_activity(activity)
181188

182189
await self._adapter.continue_conversation(
183190
skill_conversation_reference.conversation_reference,
184191
callback,
185192
claims_identity=claims_identity,
186193
audience=skill_conversation_reference.oauth_scope,
187194
)
188-
return ResourceResponse(id=str(uuid4()))
195+
196+
if not resource_response:
197+
resource_response = ResourceResponse(id=str(uuid4()))
198+
199+
return resource_response
189200

190201
@staticmethod
191202
def _apply_eoc_to_turn_context_activity(

0 commit comments

Comments
 (0)
0