-
Notifications
You must be signed in to change notification settings - Fork 304
Closed
Labels
Bot ServicesRequired for internal Azure reporting. Do not delete. Do not change color.Required for internal Azure reporting. Do not delete. Do not change color.bugIndicates an unexpected problem or an unintended behavior.Indicates an unexpected problem or an unintended behavior.customer-replied-toIndicates that the team has replied to the issue reported by the customer. Do not delete.Indicates that the team has replied to the issue reported by the customer. Do not delete.customer-reportedIssue is created by anyone that is not a collaborator in the repository.Issue is created by anyone that is not a collaborator in the repository.
Description
Version
4.14
Describe the bug
Channel data from Teams are incorrectly used in Telemetry Middleware. Bot is not able to respond to any message sent via Teams when the Telemetry is enabled. The same bot works fine when tested in Bot Framework Emulator.
To Reproduce
Steps to reproduce the behavior:
- Add Telemetry to your Python Bot:
TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(
CONFIG.APPINSIGHTS_INSTRUMENTATION_KEY, telemetry_processor=AiohttpTelemetryProcessor(), client_queue_size=1
)
TELEMETRY_LOGGER_MIDDLEWARE = TelemetryLoggerMiddleware(TELEMETRY_CLIENT, True)
ADAPTER.use(TELEMETRY_LOGGER_MIDDLEWARE)
...
APP = web.Application(middlewares=[bot_telemetry_middleware, aiohttp_error_middleware])
- Deploy to Azure and connect to Teams
- Send a message from Teams to the bot.
- See error:
2022-04-21T10:55:29.178590260Z TelemetryLoggerMiddleware.__populate_additional_channel_properties(
2022-04-21T10:55:29.178594560Z File "/usr/local/lib/python3.8/site-packages/botbuilder/core/telemetry_logger_middleware.py", line 307, in __populate_additional_channel_properties
2022-04-21T10:55:29.178599160Z if teams_channel_data and teams_channel_data.tenant
2022-04-21T10:55:29.178603361Z AttributeError: 'dict' object has no attribute 'tenant'
Additional context
I have found out that activity.channel_data is a dict, not an object. Therefore, I changed the following method in telemetry_logger_middleware.py to use the dict instead of the object and now it works fine.
@staticmethod
def __populate_additional_channel_properties(
activity: Activity, properties: dict,
):
if activity.channel_id == Channels.ms_teams:
teams_channel_data: TeamsChannelData = activity.channel_data
properties["TeamsTenantId"] = (
teams_channel_data['tenant']['id']
if teams_channel_data and teams_channel_data.get("tenant", {}).get("id", None)
else ""
)
properties["TeamsUserAadObjectId"] = (
activity.from_property.aad_object_id if activity.from_property else ""
)
if teams_channel_data and teams_channel_data.get("team", None):
properties["TeamsTeamInfo"] = TeamInfo.serialize(
teams_channel_data['team']
)
Metadata
Metadata
Assignees
Labels
Bot ServicesRequired for internal Azure reporting. Do not delete. Do not change color.Required for internal Azure reporting. Do not delete. Do not change color.bugIndicates an unexpected problem or an unintended behavior.Indicates an unexpected problem or an unintended behavior.customer-replied-toIndicates that the team has replied to the issue reported by the customer. Do not delete.Indicates that the team has replied to the issue reported by the customer. Do not delete.customer-reportedIssue is created by anyone that is not a collaborator in the repository.Issue is created by anyone that is not a collaborator in the repository.