It is not possible to send a direct message to a user using Teams Incoming Webhook. The Incoming Webhook is designed to post messages to a specific channel, not to individual users. However, you can achieve this by creating a Teams bot application. Teams bot applications can send messages to individual users, group chats, and public channels.
To send a message to a user directly, you would need to use the Microsoft Bot Framework and the Teams SDK. You would need to capture the user's Teams-specific identifiers, which you can do by fetching the roster or user profile data, subscribing to conversation events, or using Microsoft Graph.
var turnContext = new TurnContext(new AdapterWithErrorHandler(new ConfigurationCredentialProvider(Configuration)), activity);
var conversationParameters = new ConversationParameters
{
IsGroup = false,
Bot = turnContext.Activity.Recipient,
Members = new ChannelAccount[] { new ChannelAccount(userId) },
TenantId = tenantId
};
await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
channelId,
serviceUrl,
credentials,
conversationParameters,
async (t1, c1) =>
{
var reply = MessageFactory.Text("Hello, user!");
await t1.SendActivityAsync(reply, c1);
},
cancellationToken);
Please refer to the Microsoft Bot Framework documentation and Teams SDK documentation for more detailed information on how to create a bot and send messages to users.
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. Click here to escalate.