How to respond with private message back to sender in same channel using Bot API?

Anand P 1 Reputation point
2021-09-03T14:59:31.717+00:00

Our Teams Bot App needs to read ALL Team chat messages for Team channels that have installed the app (and provided consent), analyze the content and respond privately to the message sender.

We are able to post a response message back to the sender using the Bot API, but NOT as a private message. The message is visible in the channel to other users as well. We need help on how to respond privately to the sender.

Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,878 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Prasad-MSFT 5,621 Reputation points Microsoft Vendor
    2021-09-13T06:31:42.197+00:00

    If you want to send a message to user personally, you will need to pass conversation Id of that 1:1 chat not the channel, so to get that, conversation reference should be like this (please see variable conversationReference inside CreateConversationAsync) :

    await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
        "msteams",
        serviceUrl,
        credentials,
        conversationParameters,
        async (t1, c1) =>
        {
            var userConversation = t1.Activity.Conversation.Id;
            var conversationReference = new ConversationReference
            {
                ServiceUrl = serviceUrl,
                Conversation = new ConversationAccount
                {
                    Id = userConversation,
                },
            };
            await ((BotFrameworkAdapter)turnContext.Adapter).ContinueConversationAsync(
                BotAppId,
                conversationReference,
                async (t2, c2) =>
                {
                    await t2.SendActivityAsync(MessageFactory.Text("This will be the first response to the new thread"), c2).ConfigureAwait(false);
                },
                cancellationToken).ConfigureAwait(false);
        },
        cancellationToken).ConfigureAwait(false);
    

    Thanks,
    Prasad Das


    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link.

    0 comments No comments