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.
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}
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
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 loggingfrom_property
results. There are several instances of matchingaad_object_id
where one line will have aname
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 backNone
, and not be defined infrom_property
.Expected (output from
print(turn_context)
:Received (Occasionally):
To Reproduce
(Simplified for brevity) Add to the
actions
array of an adaptive card template being posted to the channel.Accepting the interaction (in bot.py):