question

AnandP-8228 avatar image
0 Votes"
AnandP-8228 asked Prasad-MSFT answered

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

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.

office-teams-app-dev
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AnandP-8228,

As we are mainly responsible for general question of Microsoft Teams, your question related to Bot API is not supported by us. I will remove office-teams-windows-itpro tag. Thanks for your understanding.

0 Votes 0 ·

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);




0 Votes 0 ·

Hi Prasad, thanks for sharing the link.

The link https://stackoverflow.microsoft.com/questions/270993
is not accessible to us. Would it be possible to make the content publicly accessible?

Error: We get the below error currently.
Request Id: 9c377cdf-f0f4-40a5-a237-b4d42b70xxxx
Correlation Id: f637e986-317d-4bdd-97ed-5a3f4f56xxxx
Timestamp: 2021-09-10T03:34:25Z
Message: AADSTS50020: User account 'anandxxxxx@gmail.com' from identity provider 'live.com' does not exist in tenant 'Microsoft' and cannot access the application 'https://stackoverflow.microsoft.com/auth/saml2/post'(StackOverflowAtMicrosoft) in that tenant. The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different Azure Active Directory user account.

Thank you.

0 Votes 0 ·

Edited the answer

0 Votes 0 ·

1 Answer

Prasad-MSFT avatar image
0 Votes"
Prasad-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.