Forum Discussion
amatthews-yakchat
Apr 22, 2022Copper Contributor
Mentioning multiple users with Bot Framework
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 u...
- May 12, 2022
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);
Meghana-MSFT
Apr 29, 2022Former Employee
amatthews-yakchat - Could you please share a code snippet of how you are mentioning multiple users?
amatthews-yakchat
May 03, 2022Copper Contributor
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;