Repository: microsoft/botbuilder-python

Issue:
An activity with attachments raises an exception in telemetry logger
## Version
4.14.1

## Describe the bug

Activity.attachments is a list. Therefore, telemetry logger raises an exception (see below) if trying to call `strip()` on attachements.

```
  File "/Users/ivo/Projects/alvao-chatbot/bot/venv/lib/python3.8/site-packages/botbuilder/core/telemetry_logger_middleware.py", line 220, in fill_send_event_properties
    if activity.attachments and activity.attachments.strip():
AttributeError: 'list' object has no attribute 'strip'
```

This line produces the bug: https://github.com/microsoft/botbuilder-python/blob/main/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py#L220

## To Reproduce
Steps to reproduce the behavior:
1. Use TelemetryLoggerMiddleware
2. Create a card message: `MessageFactory.attachment(Attachment(content_type="application/vnd.microsoft.card.adaptive", content=card))`
3. Send this activity from bot to user
4. When this activity is being logged via TelemetryLoggerMiddleware, it raises an exception

## Expected behavior
There should be another check than `strip()`, possible `len() > 0`. Function `strip` returns a string without leading and trailing whitespaces. There is no sense to do that a) in a condition, b) on a list.




Discussion:
@ivopisarovic - investigating this issue. Are you able to provide code snippets or sample code?
Sure, I have prepared a demo. You can set your `AppInsightsInstrumentationKey` in `config.py`, start it and send any message to the bot via Emulator. The error occurs when the bot tries to reply.

https://github.com/ivopisarovic/botbuilder-telemetry-problem

The demo is based on the official [tutorial](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-create-bot?view=azure-bot-service-4.0&tabs=python%2Cvs). It uses the echo bot sample. Besides that, the telemetry was initialised and an attachment message is used instead of the default text message. See all the [changes](https://github.com/ivopisarovic/botbuilder-telemetry-problem/commit/d74867c57efd1260666189d772282cdad5944293).

 

Resolving patch:
diff --git a/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py b/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py
--- a/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py
+++ b/libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py
@@ -2,6 +2,8 @@
 # Licensed under the MIT License.
 """Middleware Component for logging Activity messages."""
 from typing import Awaitable, Callable, List, Dict
+from jsonpickle import encode
+
 from botbuilder.schema import Activity, ConversationReference, ActivityTypes
 from botbuilder.schema.teams import TeamsChannelData, TeamInfo
 from botframework.connector import Channels
@@ -33,7 +35,7 @@ def telemetry_client(self) -> BotTelemetryClient:
 
     @property
     def log_personal_information(self) -> bool:
-        """ Gets a value indicating whether determines whether to log personal
+        """Gets a value indicating whether determines whether to log personal
         information that came from the user."""
         return self._log_personal_information
 
@@ -217,10 +219,10 @@ async def fill_send_event_properties(
 
         # Use the LogPersonalInformation flag to toggle logging PII data, text and user name are common examples
         if self.log_personal_information:
-            if activity.attachments and activity.attachments.strip():
-                properties[
-                    TelemetryConstants.ATTACHMENTS_PROPERTY
-                ] = activity.attachments
+            if activity.attachments and len(activity.attachments) > 0:
+                properties[TelemetryConstants.ATTACHMENTS_PROPERTY] = encode(
+                    activity.attachments
+                )
             if activity.from_property.name and activity.from_property.name.strip():
                 properties[
                     TelemetryConstants.FROM_NAME_PROPERTY


Test patch: