I'm trying to send proactive 1:1 message from bot to teams using Teams SDK with the code below
MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl);
var connectorClient = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), Configuration["MicrosoftAppId"], Configuration["MicrosoftAppPassword"]);
var userId = _operation.MemberTeamsId;
var tenantId = Configuration["TenantId"];
var parameters = new ConversationParameters
{
Members = new[] { new ChannelAccount(userId) },
ChannelData = new TeamsChannelData
{
Tenant = new TenantInfo(tenantId),
},
};
var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters);
var message = Microsoft.Bot.Schema.Activity.CreateMessageActivity();
message.Text = _operation.Message;
await connectorClient.Conversations.SendToConversationAsync(conversationResource.Id, (Microsoft.Bot.Schema.Activity)message);
I have the following issues with this,
The bot cannot send a proactive message unless the user has a prior conversation after deployment
Bot deployed
Bill to Bot - Works
Bot to Bill - Works
Bot redeployed
Bot to Bill - Not works because there are no members in the conversation now after redeploying
Bill to Bot - Works
Bot to Bill - Works now as Bill had a conversation after redeploying
Bot sends the same message multiple times to users
Bill to Bot - Works
Bot to Bill - Works Proactively - Sends 1 defined message as it should
Sim to Bot - Works
Bot to Sim - Sends 2 same messages as there are two members in the conversation now
Will to Bot - works
Bot to Will - Sends 3 same messages as there are three members in the conversation now
Note: I am storing the Teams userid in DB and use them to send direct messages to users
Any help on how to correct this would be appreciated. Thanks.