-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Describe the bug
My use case is to create a proactive channel conversation as a group conversation by including other user. But when i try it creates a 1:1 conversation/
Expected behavior
I expect, that when i execute below code, then, a message should be posted to a specific team channel of my ms-teams team from the bot.
Nuget Dependencies
"Microsoft.AspNetCore" Version="2.1.3"
"Microsoft.AspNetCore.All" Version="2.0.8"
"Microsoft.Bot.Builder" Version="4.2.0"
"Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.2.0"
"microsoft.bot.builder.teams" Version="4.0.0-beta1"
"Microsoft.Bot.Configuration" Version="4.2.0"
"Microsoft.Bot.Connector" Version="4.2.0"
"Microsoft.Bot.Schema" Version="4.2.0"
"Microsoft.Extensions.Logging.AzureAppServices" Version="2.1.1"
.Net Version
Microsoft.NETCore.App(2.1)
CODE
This is the source code i am trying :
ClaimsIdentity claimsIdentity = turnContext.TurnState.Get<ClaimsIdentity>("BotIdentity");
Claim botAppIdClaim = claimsIdentity.Claims?.SingleOrDefault(claim => claim.Type == AuthenticationConstants.AudienceClaim)
??
claimsIdentity.Claims?.SingleOrDefault(claim => claim.Type == AuthenticationConstants.AppIdClaim);
string appPassword = await this.credentialProvider.GetAppPasswordAsync(botAppIdClaim.Value).ConfigureAwait(false);
var identity = new MicrosoftAppCredentials(botAppIdClaim.Value, appPassword);
MicrosoftAppCredentials.TrustServiceUrl(teamConversationData.ServiceUrl);
var connectorClient = new ConnectorClient(new Uri(teamConversationData.ServiceUrl),identity);
var mem2 = new List<ChannelAccount> { teamConversationData.TeamRoster.First().Value };
var parameters = new ConversationParameters
{
//teamConversationData has my state info. like team roster ,tenant id, ms teams channels for my team etc.
Bot = new ChannelAccount(teamConversationData.BotID, teamConversationData.BotName),
Members = mem2,//Cant set to more than one account, if i try result in bad request exception
IsGroup = false, //if this is set to true then always get an error while creating a conversation.
TopicName = "Anything ",
ChannelData = JObject.FromObject(
new TeamsChannelData
{
Tenant = new TenantInfo(teamConversationData.Tenant.Id),
Team = new TeamInfo(teamConversationData.Team.Id),
Channel = new ChannelInfo(teamConversationData.Channels.Conversations[0].Id),
},
JsonSerializer.Create(new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
})),
};
//things which are not working..
//1. having more then 1 member in the members property of conversation parameter AND/OR setting isGroup to true. it throws a bad request error.
var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters);
var message = Activity.CreateMessageActivity();
message.From = new ChannelAccount(teamConversationData.BotID, teamConversationData.BotName);
message.Conversation = new ConversationAccount(id: conversationResource.Id.ToString());
var mentions = new List<Entity>();
var activityText = new StringBuilder($"a notification message, for following users : ");
foreach (var member in members)
{
var mentionsText = $"<at>@{member.Name}</at>";
mentions.Add(new Entity()
{
Type = "mention",
Properties = JObject.FromObject(
new { mentioned = new { id = member.Id, name = member.Name }, text = mentionsText }
, JsonSerializer.Create(new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, })),
});
activityText.Append(mentionsText);
}
message.Entities = mentions;
message.Text = activityText.ToString();
await connectorClient.Conversations.SendToConversationAsync((Activity)message);