1
votes

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,

  1. 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

  2. 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.

1
I'm not actually clear on what you exact question is, but I'm guessing it's that you don't want multiple messages sent? Or, do you want them sent directly to the users, instead of to the group chat? Or do you want them sent to the group chat, but only one message?Hilton Giesenow
I'm trying to send 1:1 Personal messages to users from Bot. The bot is unable to send messages to the user who hasn't conversed after deployment. And If it's able to send after conversed, it is sending the same messages multiple times according to the number of users who have already conversed with the bot, I.e. If there are 10 users conversed with bot after deployment, BOT will send the desired message to the desired user 10 times.Nithin Bhargav

1 Answers

1
votes

Based on the answers in the comments, I think I understand the scenario better, and it looks to me like the problem is that you're not setting a Conversation Id anyway - although you tell the Bot which user you want to interact with, it needs to know if you want to interact with them directly (i.e. 1-1), or as part of a group chat somewhere, or a Teams channel.

You need to set this by configuring the Conversation property on the Activity instance (in your case the "message" variable). See my post here for more detailed information: Programmatically sending a message to a bot in Microsoft Teams

Hope that helps - if not, let me know