SOLVED

Mentioning multiple users with Bot Framework

%3CLINGO-SUB%20id%3D%22lingo-sub-3292077%22%20slang%3D%22en-US%22%3EMentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3292077%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20having%20a%20problem%20with%20mentions%20using%20Bot%20Framework%20in%20Teams%20and%20cannot%20find%20any%20information%20about%20how%20to%20fix%20it%20or%20any%20one%20who%20has%20had%20similar%20issues.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20have%20a%20bot%20that%20has%20been%20developed%20using%20the%20C%23%20Bot%20Framework%20SDK%20Version%204%20and%20.NET%20Core%203.1%20that%20is%20installed%20via%20Teams.%20I%20am%20trying%20to%20implement%20a%20requirement%20where%20the%20bot%20can%20%40mention%20members%20of%20the%20Team%20in%20the%20messages%20it%20sends%2C%20following%20the%20documentation%20found%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fplatform%2Fbots%2Fhow-to%2Fconversations%2Fchannel-and-group-conversations%3Ftabs%3Ddotnet%23add-mentions-to-your-messages%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20This%20is%20working%20fine%20for%20a%20single%20user%2C%20however%20when%20I%20try%20to%20%40mention%20more%20than%20one%20user%20in%20a%20single%20message%20I%20am%20experiencing%20some%20weird%20behavior.%20The%20message%20only%20mentions%20the%20last%20user%20added%20to%20the%20Entities%20object%20of%20the%20MessageActivity%2C%20even%20though%20all%20the%20mention%20text%20is%20appended%20to%20the%20message%20and%20is%20formatted%20as%20though%20it%20should%20be%20a%20mention.%20Also%20the%20actual%20mention%20seems%20to%20overwrite%20the%20first%20user%20name%20that%20was%20added%20to%20the%20Entities%20list%2C%20even%20though%20the%20mention%20text%20it%20should%20be%20using%20still%20appears%20at%20the%20end%20of%20the%20message%2C%20as%20shown%20in%20the%20screenshot%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22amatthewsyakchat_0-1650617321773.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F366059iA6FC1D9B0A3C0F21%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22amatthewsyakchat_0-1650617321773.png%22%20alt%3D%22amatthewsyakchat_0-1650617321773.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20searching%20for%20a%20solution%20for%20this%20problem%20but%20I%20cannot%20find%20anything%2C%20is%20this%20a%20current%20limitation%20of%20the%20Bot%20Framework%20SDK%20or%20am%20I%20implementing%20this%20feature%20incorrectly%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3292077%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301138%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301138%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1092848%22%20target%3D%22_blank%22%3E%40Meghana-MSFT%3C%2FA%3E-%20Here%20is%20the%20code%20snippet%20for%20how%20we%20are%20attempting%20to%20implement%20this%20feature.%20This%20method%20appears%20to%20work%20for%20a%20single%20user%2C%20but%20not%20for%20multiple%20users.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EIMessageActivity%20OutboundMessage%20%3D%20Activity.CreateMessageActivity()%3B%0A%0AOutboundMessage.Entities%20%3D%20new%20List%3CENTITY%3E()%3B%0AStringBuilder%20MentionStringBuilder%20%3D%20new%20StringBuilder(2048)%3B%0A%0Aforeach%20(String%20MentionData%20in%20SubscriptionMentions)%0A%7B%0A%20ChannelAccount%20MentionAccount%20%3D%20JsonConvert.DeserializeObject%3CCHANNELACCOUNT%3E(MentionData)%3B%0A%20String%20MentionName%20%3D%20XmlConvert.EncodeName(MentionAccount.Name)%3B%0A%20if%20(MentionName.Contains(%22_x0020_%22))%0A%20%7B%0A%20%20MentionName%20%3D%20MentionName.Replace(%22_x0020_%22%2C%20%22%20%22)%3B%0A%20%7D%0A%0A%20Mention%20UserMention%20%3D%20new%20Mention()%0A%20%7B%0A%20%20Mentioned%20%3D%20MentionAccount%2C%0A%20%20Text%20%3D%20%24%22%3CAT%3E%7BMentionName%7D%3C%2FAT%3E%22%0A%20%7D%3B%0A%0A%20OutboundMessage.Entities.Add(UserMention)%3B%0A%20MentionStringBuilder.Append(%24%22%20%3CAT%3E%7BMentionName%7D%3C%2FAT%3E%2C%22)%3B%0A%20%7D%0A%0AMentionStringBuilder.Length--%3B%0AFormattedMessageWithMention%20%3D%20String.Format(BotResponse.InboundMessage_MentionFormat%2C%20%0A%20FormattedMessage%2C%20MentionStringBuilder.ToString()%2C%20Environment.NewLine)%3B%0A%0AOutboundMessage.Text%20%3D%20FormattedMessageWithMention%3B%3C%2FCHANNELACCOUNT%3E%3C%2FENTITY%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3299075%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3299075%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1370351%22%20target%3D%22_blank%22%3E%40amatthews-yakchat%3C%2FA%3E%20-%20Could%20you%20please%20share%20a%20code%20snippet%20of%20how%20you%20are%20mentioning%20multiple%20users%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3295078%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3295078%22%20slang%3D%22en-US%22%3EWe%20are%20looking%20into%20this%20issue%2C%20we%20will%20get%20back%20to%20you.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3332121%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3332121%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1370351%22%20target%3D%22_blank%22%3E%40amatthews-yakchat%3C%2FA%3E%26nbsp%3B-%20We%20checked%20this%20issue%20and%20we%20were%20able%20to%20get%20multiple%20mentions.%20The%20mentioned%20users%20get%20notifications%20in%20the%20Feed%20as%20well.%20Attaching%20the%20screenshots%20of%20the%20same.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MeghanaMSFT_0-1651835576668.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F369804i1BDCB40AE0A82D3C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22MeghanaMSFT_0-1651835576668.png%22%20alt%3D%22MeghanaMSFT_0-1651835576668.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MeghanaMSFT_1-1651836130945.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F369806iAD5E21E2190F2D27%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22MeghanaMSFT_1-1651836130945.png%22%20alt%3D%22MeghanaMSFT_1-1651836130945.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MeghanaMSFT_2-1651836211346.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F369810iC8164DEE4E7F4ADB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22MeghanaMSFT_2-1651836211346.png%22%20alt%3D%22MeghanaMSFT_2-1651836211346.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EPlease%20note%20that%20we%20added%20mentions%20individually%20by%20hardcoding%20the%20values%20for%20now.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20var%20mention2%20%3D%20new%20Mention%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Mentioned%20%3D%20new%20ChannelAccount()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20AadObjectId%20%3D%20%22xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%20%3D%20%22AlexW%40xxxxxxxx.OnMicrosoft.com%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%20%3D%20%22Alex%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Role%20%3D%20%22User%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Text%20%3D%20%24%22%3CAT%3EAlex%3C%2FAT%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20mention3%20%3D%20new%20Mention%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Mentioned%20%3D%20new%20ChannelAccount()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20AadObjectId%20%3D%20%22xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%20%3D%20%22DebraB%40xxxxxxxx.OnMicrosoft.com%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%20%3D%20%22Debra%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Role%20%3D%20%22User%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Text%20%3D%20%24%22%3CAT%3EDebra%3C%2FAT%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20replyActivity%20%3D%20MessageFactory.Text(%24%22Hello%20%7Bmention.Text%7D%20and%20%7Bmention1.Text%7D%2C%20%7Bmention2.Text%7D%2C%20%7Bmention3.Text%7D.%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20replyActivity.Entities%20%3D%20new%20List%3CENTITY%3E()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20replyActivity.Entities.Add(mention)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20replyActivity.Entities.Add(mention1)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20replyActivity.Entities.Add(mention2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20replyActivity.Entities.Add(mention3)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20turnContext.SendActivityAsync(replyActivity%2C%20cancellationToken)%3B%3C%2FENTITY%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECould%20you%20please%20confirm%20if%20you%20are%20mentioning%20the%20same%20issue%20that%20is%20working%20for%20us%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3332950%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3332950%22%20slang%3D%22en-US%22%3EYes%2C%20this%20is%20the%20functionality%20we%20are%20trying%20to%20implement%20and%20cannot%20get%20to%20function%20correctly.%20We%20are%20saving%20the%20ChannelAccount%20serialized%20as%20JSON%20against%20the%20user%20records%20in%20our%20database%2C%20so%20we%20can%20retrieve%20them%20to%20include%20in%20the%20notification%20messages.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3355159%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3355159%22%20slang%3D%22en-US%22%3ECould%20you%20please%20debug%20once%20again%20and%20check%20if%20you%20are%20getting%20correct%20values%20into%20the%20mention%20objects%20as%20we%20do%20not%20have%20a%20repro%20for%20this.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3357279%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3357279%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1092848%22%20target%3D%22_blank%22%3E%40Meghana-MSFT%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20run%20another%20test%20of%20this%20and%20gotten%20the%20same%20result.%20Here%20is%20the%20debug%20data%20I%20have%20collected%20from%20the%20testing%2C%20the%20message%20should%20have%205%20entities%20mentioned%20in%20the%20message%20posted%2C%20all%205%20entities%20are%20added%20to%20the%20entity%20collection%20for%20the%20message%2C%20but%20I%20am%20getting%20the%20same%20odd%20behavior%20of%20only%20the%20last%20entity%20added%20to%20the%20last%20being%20mentioned%20and%20the%20mention%20overwriting%20the%20text%20for%20the%20first%20entity%20in%20the%20list%20when%20displayed%20in%20teams.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEntity%201%3CBR%20%2F%3EMention.Text%3CBR%20%2F%3E%3CAT%3EAndrew%20Matthews%3C%2FAT%3E%3CBR%20%2F%3EMention.Mentioned%3CBR%20%2F%3E%7B%22id%22%3A%2229%3A1_2qC_nUipbzr4xvKNXUJfZ-fPXWbe7FhvjxFSy7eD6joNRLh1rtZyNpp1dYl-dw7t5kRYbKz_1GChCTtB1KMjg%22%2C%22name%22%3A%22Andrew%20Matthews%22%2C%22aadObjectId%22%3A%22ac5c8125-daaa-4764-a0a1-250e3b14faf1%22%2C%22role%22%3Anull%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEntity%202%3CBR%20%2F%3EMention.Text%3CBR%20%2F%3E%3CAT%3EJack%20Jenson%3C%2FAT%3E%3CBR%20%2F%3EMention.Mentioned%3CBR%20%2F%3E%7B%22id%22%3A%2229%3A1znmswEmc8SskPlpBAqpWvv7uaXt4B046WXcDVzeFDZTD64L6bhQ4NZVK6veZJyGcRNOCRiAWSllSiBlo1V_dbw%22%2C%22name%22%3A%22Jack%20Jenson%22%2C%22aadObjectId%22%3A%223d02d75f-c6e1-4f0d-8a2f-225c564958dd%22%2C%22role%22%3Anull%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEntity%203%3CBR%20%2F%3EMention.Text%3CBR%20%2F%3E%3CAT%3EDalia%20Farouk%3C%2FAT%3E%3CBR%20%2F%3EMention.Mentioned%3CBR%20%2F%3E%7B%22id%22%3A%2229%3A1-Oe0wuCbfYw-rBj20L0ePQxWqF1bmhwT2IVF6PpogH7xafGMxN3YJWaMtHYJFt8Sf_9EJ6rlCdHht2E7RfnV7w%22%2C%22name%22%3A%22Dalia%20Farouk%22%2C%22aadObjectId%22%3A%22fcf3d09e-6f54-4f14-9476-cc11c8727a59%22%2C%22role%22%3Anull%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEntity%204%3CBR%20%2F%3EMention.Text%3CBR%20%2F%3E%3CAT%3EU12%20Test%3C%2FAT%3E%3CBR%20%2F%3EMention.Mentioned%3CBR%20%2F%3E%7B%22id%22%3A%2229%3A15XaomK15dlPgsKUxoZ84DL9MUJcpnR6Z7q70-_7BHosfp78ZSrh6zPrecb9IL2L3rDqm_JRsPwdmsMoVokir1A%22%2C%22name%22%3A%22U12%20Test%22%2C%22aadObjectId%22%3A%220b302b93-d0f0-499f-8e3c-6072e3db6535%22%2C%22role%22%3Anull%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEntity%205%3CBR%20%2F%3EMention.Text%3CBR%20%2F%3E%3CAT%3EYakChat%20Test%203%3C%2FAT%3E%3CBR%20%2F%3EMention.Mentioned%3CBR%20%2F%3E%7B%22id%22%3A%2229%3A1AdwTVIKCmaV9_jkN9OF9B-kYZaHbDqcnTS7B4QeU6JkdJSUAN2Un-pnj7qhj0lR44M4bUTi3c5RSKZY0lE1MBA%22%2C%22name%22%3A%22YakChat%20Test%203%22%2C%22aadObjectId%22%3A%22b9301a39-8978-4dfa-944f-d63ac583b4d6%22%2C%22role%22%3Anull%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMessage%20sent%20out%20from%20the%20Bot%3CBR%20%2F%3EOutboundMessage.Text%3CBR%20%2F%3E__Message%20From%20*%2B19186014007*__%20Test%201307%20%3CAT%3EAndrew%20Matthews%3C%2FAT%3E%2C%20%3CAT%3EDalia%20Farouk%3C%2FAT%3E%2C%20%3CAT%3EJack%20Jenson%3C%2FAT%3E%2C%20%3CAT%3EU12%20Test%3C%2FAT%3E%2C%20%3CAT%3EYakChat%20Test%203%3C%2FAT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMessage%20as%20it%20appears%20in%20Teams%3C%2FP%3E%3CDIV%20class%3D%22%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22amatthewsyakchat_1-1652272415632.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F370779i2580C0B5939FF6AC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22amatthewsyakchat_1-1652272415632.png%22%20alt%3D%22amatthewsyakchat_1-1652272415632.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3365123%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3365123%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1370351%22%20target%3D%22_blank%22%3E%40amatthews-yakchat%3C%2FA%3E%26nbsp%3B-%26nbsp%3BWe%20tried%20this%20with%20your%20code%20as%20well%20and%20its%20working%2C%20could%20you%20also%20please%20try%20by%20using%20user%20principal%20names%20once.%20We%20hardcoded%20the%20values%20into%26nbsp%3B%3CSPAN%3ESubscriptionMentions%20object.%20Also%20please%20note%20that%20we%26nbsp%3B%3CSPAN%20class%3D%22cm-variable%22%3EMentionStringBuilder%3C%2FSPAN%3E.%3CSPAN%20class%3D%22cm-variable%22%3EToString%3C%2FSPAN%3E()%20directly%20at%20the%20end.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ECould%20you%20please%20give%20a%20try%20like%20this%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20%20%20%20%20var%20SubscriptionMentions%20%3D%20new%20string%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%40%22%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%3A%20'admin%40M365x654992.onmicrosoft.com'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%3A%20'Admin'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%40%22%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%3A%20'adelev%40M365x654992.onmicrosoft.com'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%3A%20'Adele'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%40%22%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%3A%20'AlexW%40M365x654992.OnMicrosoft.com'%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Name%3A%20'Alex'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20IMessageActivity%20OutboundMessage%20%3D%20Activity.CreateMessageActivity()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20OutboundMessage.Entities%20%3D%20new%20List%3CENTITY%3E()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20StringBuilder%20MentionStringBuilder%20%3D%20new%20StringBuilder(2048)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20foreach%20(String%20MentionData%20in%20SubscriptionMentions)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ChannelAccount%20MentionAccount%20%3D%20JsonConvert.DeserializeObject%3CCHANNELACCOUNT%3E(MentionData)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20String%20MentionName%20%3D%20XmlConvert.EncodeName(MentionAccount.Name)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(MentionName.Contains(%22_x0020_%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20MentionName%20%3D%20MentionName.Replace(%22_x0020_%22%2C%20%22%20%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Mention%20UserMention%20%3D%20new%20Mention()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Mentioned%20%3D%20MentionAccount%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Text%20%3D%20%24%22%3CAT%3E%7BMentionName%7D%3C%2FAT%3E%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20OutboundMessage.Entities.Add(UserMention)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20MentionStringBuilder.Append(%24%22%20%3CAT%3E%7BMentionName%7D%3C%2FAT%3E%2C%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20MentionStringBuilder.Length--%3B%0A%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20OutboundMessage.Text%20%3D%20MentionStringBuilder.ToString()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20turnContext.SendActivityAsync(OutboundMessage%2C%20cancellationToken)%3B%3C%2FCHANNELACCOUNT%3E%3C%2FENTITY%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3369691%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3369691%22%20slang%3D%22en-US%22%3EUsing%20hard%20coded%20values%20for%20the%20ChannelAccount%20and%20the%20user%20principal%20names%20works%2C%20so%20I%20think%20the%20issue%20is%20that%20the%20ChannelData%20we%20are%20currently%20saving%20in%20our%20database%20has%20something%20like%2029%3A1AdwTVIKCmaV9_jkN9OF9B-kYZaHbDqcnTS7B4QeU6JkdJSUAN2Un-pnj7qhj0lR44M4bUTi3c5RSKZY0lE1MBA%20instead%20of%20the%20user%20principal%20name%20for%20the%20id%20field.%3CBR%20%2F%3E%3CBR%20%2F%3EWe%20are%20currently%20getting%20the%20ChannelAccount%20data%20from%20ITurnContext.Activity.From%20on%20the%20user's%20first%20incoming%20message%20to%20save%20it%20against%20the%20user%20record%20in%20our%20database.%20Do%20you%20have%20any%20suggestions%20on%20how%20we%20can%20change%20this%20so%20that%20instead%20of%20the%20weird%20id%20string%20we%20can%20instead%20save%20the%20user%20principal%20name%20in%20the%20id%20field%20before%20saving%20the%20serialized%20ChannelAccount%20data%20in%20our%20database%3F%20Is%20the%20fact%20multi%20mention%20doesn't%20work%20with%20this%20weird%20id%20a%20bug%2C%20or%20is%20it%20a%20known%20constraint%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3392855%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3392855%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1370351%22%20target%3D%22_blank%22%3E%40amatthews-yakchat%3C%2FA%3E%26nbsp%3B-%20You%20can%20get%20the%20Team%20member%20details%20using%26nbsp%3BTeamsInfo.GetPagedMembersAsync.%20TeamsInfo%20gives%20the%20UPN%20values%20as%20well.%20Could%20you%20please%20try%20using%20these%20UPN%20values%20and%20check%20if%20that%20solves%20your%20issue.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fplatform%2Fbots%2Fhow-to%2Fget-teams-context%3Ftabs%3Ddotnet%23fetch-the-roster-or-user-profile%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fplatform%2Fbots%2Fhow-to%2Fget-teams-context%3Ftabs%3Ddotnet%23fetch-the-roster-or-user-profile%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CLI-WRAPPER%3E%20%3C%2FLI-WRAPPER%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3400218%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3400218%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1092848%22%20target%3D%22_blank%22%3E%40Meghana-MSFT%3C%2FA%3EUsing%20the%20Teams%20member%20details%20has%20solved%20this%20issue%20for%20us%20and%20we%20are%20now%20able%20to%20mention%20multiple%20users%20in%20a%20single%20message%20from%20our%20bot.%20I%20noticed%20that%20the%20methods%20in%20TeamsInfo%20return%20TeamsChannelAccounts%20instead%20of%20ChannelAccount%20which%20is%20returned%20from%20the%20method%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoftteams%2Fplatform%2Fbots%2Fhow-to%2Fconversations%2Fchannel-and-group-conversations%3Ftabs%3Ddotnet%23add-mentions-to-your-messages%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20sure%20if%20I%20was%20referencing%20the%20incorrect%20documentation%20when%20trying%20to%20implement%20this%2C%20but%20if%20this%20is%20the%20correct%20documentation%20for%20this%20feature%2C%20could%20I%20suggest%20that%20it%20is%20updated%20to%20include%20this%20method%20of%20mentioning%20multiple%20users%20as%20the%20method%20in%20the%20documentation%20only%20appears%20to%20work%20if%20you%20are%20mentioning%20a%20single%20user.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3404985%22%20slang%3D%22en-US%22%3ERe%3A%20Mentioning%20multiple%20users%20with%20Bot%20Framework%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3404985%22%20slang%3D%22en-US%22%3EIf%20the%20response%20is%20helpful%2C%20please%20click%20%22**Mark%20as%20Best%20Response**%22%20and%20like%20it.%20You%20can%20share%20your%20feedback%20via%20Microsoft%20Teams%20Developer%20Feedback%20link.%3C%2FLINGO-BODY%3E
Occasional Contributor

I am having a problem with mentions using Bot Framework in Teams and cannot find any information about how to fix it or any one who has had similar issues.

 

We have a bot that has been developed using the C# Bot Framework SDK Version 4 and .NET Core 3.1 that is installed via Teams. I am trying to implement a requirement where the bot can @mention members of the Team in the messages it sends, following the documentation found here. This is working fine for a single user, however when I try to @mention more than one user in a single message I am experiencing some weird behavior. The message only mentions the last user added to the Entities object of the MessageActivity, even though all the mention text is appended to the message and is formatted as though it should be a mention. Also the actual mention seems to overwrite the first user name that was added to the Entities list, even though the mention text it should be using still appears at the end of the message, as shown in the screenshot below.

 

amatthewsyakchat_0-1650617321773.png

 

I have tried searching for a solution for this problem but I cannot find anything, is this a current limitation of the Bot Framework SDK or am I implementing this feature incorrectly?

12 Replies
We are looking into this issue, we will get back to you.

@amatthews-yakchat - Could you please share a code snippet of how you are mentioning multiple users?

@Meghana-MSFT- Here is the code snippet for how we are attempting to implement this feature. This method appears to work for a single user, but not for multiple users.

 

IMessageActivity OutboundMessage = Activity.CreateMessageActivity();

OutboundMessage.Entities = new List<Entity>();
StringBuilder MentionStringBuilder = new StringBuilder(2048);

foreach (String MentionData in SubscriptionMentions)
{
	ChannelAccount MentionAccount = JsonConvert.DeserializeObject<ChannelAccount>(MentionData);
	String MentionName = XmlConvert.EncodeName(MentionAccount.Name);
	if (MentionName.Contains("_x0020_"))
	{
		MentionName = MentionName.Replace("_x0020_", " ");
	}

	Mention UserMention = new Mention()
	{
		Mentioned = MentionAccount,
		Text = $"<at>{MentionName}</at>"
	};

	OutboundMessage.Entities.Add(UserMention);
	MentionStringBuilder.Append($" <at>{MentionName}</at>,");
	}

MentionStringBuilder.Length--;
FormattedMessageWithMention = String.Format(BotResponse.InboundMessage_MentionFormat, 
	FormattedMessage, MentionStringBuilder.ToString(), Environment.NewLine);

OutboundMessage.Text = FormattedMessageWithMention;

 

@amatthews-yakchat - We checked this issue and we were able to get multiple mentions. The mentioned users get notifications in the Feed as well. Attaching the screenshots of the same.

MeghanaMSFT_0-1651835576668.pngMeghanaMSFT_1-1651836130945.pngMeghanaMSFT_2-1651836211346.png

Please note that we added mentions individually by hardcoding the values for now.

 var mention2 = new Mention
            {
                Mentioned = new ChannelAccount()
                {
                    AadObjectId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                    Id = "AlexW@xxxxxxxx.OnMicrosoft.com",
                    Name = "Alex",
                    Role = "User"
                },
                Text = $"<at>Alex</at>",
            };
            var mention3 = new Mention
            {
                Mentioned = new ChannelAccount()
                {
                    AadObjectId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                    Id = "DebraB@xxxxxxxx.OnMicrosoft.com",
                    Name = "Debra",
                    Role = "User"
                },
                Text = $"<at>Debra</at>",
            };
            var replyActivity = MessageFactory.Text($"Hello {mention.Text} and {mention1.Text}, {mention2.Text}, {mention3.Text}.");
            replyActivity.Entities = new List<Entity>();
            replyActivity.Entities.Add(mention);
            replyActivity.Entities.Add(mention1);
            replyActivity.Entities.Add(mention2);
            replyActivity.Entities.Add(mention3);
            await turnContext.SendActivityAsync(replyActivity, cancellationToken);

Could you please confirm if you are mentioning the same issue that is working for us?

Yes, this is the functionality we are trying to implement and cannot get to function correctly. We are saving the ChannelAccount serialized as JSON against the user records in our database, so we can retrieve them to include in the notification messages.
Could you please debug once again and check if you are getting correct values into the mention objects as we do not have a repro for this.

@Meghana-MSFT 

 

I've run another test of this and gotten the same result. Here is the debug data I have collected from the testing, the message should have 5 entities mentioned in the message posted, all 5 entities are added to the entity collection for the message, but I am getting the same odd behavior of only the last entity added to the last being mentioned and the mention overwriting the text for the first entity in the list when displayed in teams.

 

Entity 1
Mention.Text
<at>Andrew Matthews</at>
Mention.Mentioned
{"id":"29:1_2qC_nUipbzr4xvKNXUJfZ-fPXWbe7FhvjxFSy7eD6joNRLh1rtZyNpp1dYl-dw7t5kRYbKz_1GChCTtB1KMjg","name":"Andrew Matthews","aadObjectId":"ac5c8125-daaa-4764-a0a1-250e3b14faf1","role":null}

 

Entity 2
Mention.Text
<at>Jack Jenson</at>
Mention.Mentioned
{"id":"29:1znmswEmc8SskPlpBAqpWvv7uaXt4B046WXcDVzeFDZTD64L6bhQ4NZVK6veZJyGcRNOCRiAWSllSiBlo1V_dbw","name":"Jack Jenson","aadObjectId":"3d02d75f-c6e1-4f0d-8a2f-225c564958dd","role":null}

 

Entity 3
Mention.Text
<at>Dalia Farouk</at>
Mention.Mentioned
{"id":"29:1-Oe0wuCbfYw-rBj20L0ePQxWqF1bmhwT2IVF6PpogH7xafGMxN3YJWaMtHYJFt8Sf_9EJ6rlCdHht2E7RfnV7w","name":"Dalia Farouk","aadObjectId":"fcf3d09e-6f54-4f14-9476-cc11c8727a59","role":null}

 

Entity 4
Mention.Text
<at>U12 Test</at>
Mention.Mentioned
{"id":"29:15XaomK15dlPgsKUxoZ84DL9MUJcpnR6Z7q70-_7BHosfp78ZSrh6zPrecb9IL2L3rDqm_JRsPwdmsMoVokir1A","name":"U12 Test","aadObjectId":"0b302b93-d0f0-499f-8e3c-6072e3db6535","role":null}

 

Entity 5
Mention.Text
<at>YakChat Test 3</at>
Mention.Mentioned
{"id":"29:1AdwTVIKCmaV9_jkN9OF9B-kYZaHbDqcnTS7B4QeU6JkdJSUAN2Un-pnj7qhj0lR44M4bUTi3c5RSKZY0lE1MBA","name":"YakChat Test 3","aadObjectId":"b9301a39-8978-4dfa-944f-d63ac583b4d6","role":null}

 

Message sent out from the Bot
OutboundMessage.Text
__Message From *+19186014007*__ Test 1307 <at>Andrew Matthews</at>, <at>Dalia Farouk</at>, <at>Jack Jenson</at>, <at>U12 Test</at>, <at>YakChat Test 3</at>

 

Message as it appears in Teams

 

amatthewsyakchat_1-1652272415632.png

best response confirmed by amatthews-yakchat (Occasional Contributor)
Solution

@amatthews-yakchat - We tried this with your code as well and its working, could you also please try by using user principal names once. We hardcoded the values into SubscriptionMentions object. Also please note that we MentionStringBuilder.ToString() directly at the end.

 

Could you please give a try like this?

            var SubscriptionMentions = new string[]
            {
                @"{
                    Id: 'admin@M365x654992.onmicrosoft.com',
                    Name: 'Admin'
                }",
                @"{
                    Id: 'adelev@M365x654992.onmicrosoft.com',
                    Name: 'Adele'
                }",
                @"{
                    Id: 'AlexW@M365x654992.OnMicrosoft.com',
                    Name: 'Alex'
                }",
            };
            IMessageActivity OutboundMessage = Activity.CreateMessageActivity();
            OutboundMessage.Entities = new List<Entity>();
            StringBuilder MentionStringBuilder = new StringBuilder(2048);
            foreach (String MentionData in SubscriptionMentions)
            {
                ChannelAccount MentionAccount = JsonConvert.DeserializeObject<ChannelAccount>(MentionData);
                String MentionName = XmlConvert.EncodeName(MentionAccount.Name);
                if (MentionName.Contains("_x0020_"))
                {
                    MentionName = MentionName.Replace("_x0020_", " ");
                }
                Mention UserMention = new Mention()
                {
                    Mentioned = MentionAccount,
                    Text = $"<at>{MentionName}</at>"
                };
                OutboundMessage.Entities.Add(UserMention);
                MentionStringBuilder.Append($" <at>{MentionName}</at>,");
            }
            
            MentionStringBuilder.Length--;
           
            OutboundMessage.Text = MentionStringBuilder.ToString();
            await turnContext.SendActivityAsync(OutboundMessage, cancellationToken);

 

Using hard coded values for the ChannelAccount and the user principal names works, so I think the issue is that the ChannelData we are currently saving in our database has something like 29:1AdwTVIKCmaV9_jkN9OF9B-kYZaHbDqcnTS7B4QeU6JkdJSUAN2Un-pnj7qhj0lR44M4bUTi3c5RSKZY0lE1MBA instead of the user principal name for the id field.

We are currently getting the ChannelAccount data from ITurnContext.Activity.From on the user's first incoming message to save it against the user record in our database. Do you have any suggestions on how we can change this so that instead of the weird id string we can instead save the user principal name in the id field before saving the serialized ChannelAccount data in our database? Is the fact multi mention doesn't work with this weird id a bug, or is it a known constraint?

@amatthews-yakchat - You can get the Team member details using TeamsInfo.GetPagedMembersAsync. TeamsInfo gives the UPN values as well. Could you please try using these UPN values and check if that solves your issue. 

 

https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/get-teams-context?tabs=dotnet#f...

 

@Meghana-MSFTUsing the Teams member details has solved this issue for us and we are now able to mention multiple users in a single message from our bot. I noticed that the methods in TeamsInfo return TeamsChannelAccounts instead of ChannelAccount which is returned from the method documented here

 

I'm not sure if I was referencing the incorrect documentation when trying to implement this, but if this is the correct documentation for this feature, could I suggest that it is updated to include this method of mentioning multiple users as the method in the documentation only appears to work if you are mentioning a single user.

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.