microsoft / botbuilder-python

The Microsoft Bot Framework provides what you need to build and connect intelligent bots that interact naturally wherever your users are talking, from text/sms to Skype, Slack, Office 365 mail and other popular services.
http://botframework.com
MIT License
694 stars 279 forks source link

Intermittently Missing User Name in turn_context's activity.from_property #2149

Closed qneville closed 3 days ago

qneville commented 1 month ago

Version

botbuilder-core 4.16.1

Describe the bug

When a user interacts with a button, we receive an inconsistent result in our turn_context returned from Microsoft. To debug this, we've been logging from_property results. There are several instances of matching aad_object_id where one line will have a name present, and one will not.

My temporary workaround was to wrap all our calls to activity.from_property.name in this function because occasionally a username will come back None, and not be defined in from_property.

def get_username_from_context(turn_context):
    fallback = "A Team Member"
    teams_username = turn_context.activity.from_property.name
    name = teams_username if teams_username else fallback
    return name

Expected (output from print(turn_context):

{'additional_properties': {}, 'id': '29:1PqtMqQTPxxxxxxxxxxxxxxxxxYyzHIkq3OW69T-A', 'name': 'Guy Who Clicked A Thing', 'aad_object_id': 'fd0b1f02-xxxx-xxxx-xxxx-f6fb9b071369', 'role': None}

Received (Occasionally):

{'additional_properties': {}, 'id': '29:1PqtMqQTPxxxxxxxxxxxxxxxxxYyzHIkq3OW69T-A', 'name': None, 'aad_object_id': 'fd0b1f02-xxxx-xxxx-xxxx-f6fb9b071369', 'role': None}

To Reproduce

(Simplified for brevity) Add to the actions array of an adaptive card template being posted to the channel.

{
            "type": "Action.Submit",
            "title": "Click me!",
            "data": {
                "msteams": {
                    "type": "invoke",
                    "value": {
                        "option": "click-me"
                    }
                }
            }
        },

Accepting the interaction (in bot.py):

async def on_invoke_activity(self, turn_context):
            name = turn_context.activity.from_property.name   # May or may not be None
            print(turn_context.activity.from_property)                  # Will show something like the above output examples
stevkan commented 1 week ago

@qneville - Thank you for your patience. Are you still experiencing an issue with this? If so,

stevkan commented 3 days ago

Closing due to inactivity. Please feel free to reopen if the issue persists or you have new details to share.