Forum Discussion
Teams Notification Bot: TeamsInfo.getPagedMembers is sometimes not returning newly added members
Hi, yes we still need help with this issue. Here is some additional information that you asked for:
1) These users are being added to the channel after the bot has been installed
2) The bot is detecting some users, but not all. See the following screenshots for our tenant, where I checkmarked the users being detected:
The users marked in red are the ones not being detected by the bot, and the blue ones are being detected. The way we create users is:
- Create a new user in admin.microsoft.com
- Add this new user to a MS Teams team/channel as an admin
The only difference between the working and non-working users is that the working ones we added a while back, and the non-working ones are all new users from us trying to reproduce the issue.
To confirm, here is my backend code, printing out the resulting list "members" confirms that only the 3 checkmarked emails are being detected:
const members = [];
do {
var pagedMembers = await TeamsInfo.getPagedMembers(context, 100, continuationToken);
continuationToken = pagedMembers.continuationToken;
members.push(...pagedMembers.members.filter(m => !!m.email));
}
while (continuationToken !== undefined);
Can you please try once with nodeJs sample once and see if you are getting all member or is it the same behavior?
Here the link - https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/57.teams-conversation-bot
Thanks
- alexkovalevDec 30, 2021Copper ContributorHi, we were finally able to get to the bottom of this issue. The problem was in this line: members.push(...pagedMembers.members.filter(m => !!m.email));
The problem is that the email property doesnt exist on the users with issues, but it seems another field userPrincipalName is available with the user email for both the users that have the email field and dont.
Can you confirm if this is the correct solution, and if there are any unintended side effects with changing the code to read from email to userPrincipalName?- HunaidHanfee-MSFTDec 31, 2021Iron Contributor
The User Principal Name is basically the ID of the user in Active Directory and sometimes might not be same as users’ email.
If you change to UserPrincipal name for external/guest user you will not get the email Id(username) that they use for signing-in.
One example for guest user - Adele Vance would be-
Email - adelev@M365x6406.onmicrosoft.comUserPrincipalName- adelev_M365x6406.onmicrosoft.com#EXT#@M365x8852.onmicrosoft.com
If this doesn't break your code then you can go ahead and change it.
If you any query please let us know.Thanks,
Hunaid L Hanfee
-----------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.
- alexkovalevDec 31, 2021Copper ContributorOkay, well unfortunately email is the unique identifier in our system that connects the users from the TeamsInfo.getPagedMembers response with the users that log in through MS oauth, so a mismatch in their userPrincipalName from their email would not work for our application.
Do you have any suggestions for how to reconcile users coming in though the 2 places above then? Most users have an email but not all, they all have userPrincipalName but sometimes that is not the email....is there any consistent identifier I can use instead of these?
Right now my best approach would have to be checking for email and falling back to userPrincipalName but it sounds like that is not a clean solution a small subset of users will continue to have this issue
- HunaidHanfee-MSFTDec 31, 2021Iron ContributorThanks for the reply and the information shared. I need verify this internally, I will get back to you soon.