Incoming Webhook for Private Messages in Microsoft Teams
Source : Stack Overflow [microsoft-teams].)
Incoming Webhook for Private Messages in Microsoft Teams
Source : Stack Overflow [microsoft-teams].)
The best approach to achieve your goal at this point is to create a Bot and implement it to expose a webhook endpoint which your app or service can post to and for the bot to post those messages into chat with the user.
Start by capturing the information required to successfully post to a conversation of a bot with user based on the incoming activity received by your bot.
var callBackInfo = new CallbackInfo()
{
ConversationId = activity.Conversation.Id,
ServiceUrl = activity.ServiceUrl
};
Then pack the callBackInfo into a token that would later be used as a parameter to your webhook.
var token = Convert.ToBase64String(
Encoding.Default.GetBytes(
JsonConvert.SerializeObject(callBackInfo)));
var webhookUrl = host + "/v1/hook/" + token;
Finally, implement the webhook handler to unpack the callBackInfo:
var jsonString = Encoding.Default.GetString(Convert.FromBase64String(token));
var callbackInfo = JsonConvert.DeserializeObject<CallbackInfo>(jsonString);
And post to the conversation of the bot with the user:
ConnectorClient connector = new ConnectorClient(new Uri(callbackInfo.ServiceUrl));
var newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.Conversation = new ConversationAccount(id: callbackInfo.ConversationId);
newMessage.TextFormat = "xml";
newMessage.Text = message.Text;
await connector.Conversations.SendToConversationAsync(newMessage as Activity);
Take a look my blog post on this topic here. If you have never written a Microsoft Teams bot before, take a look at my other blog post with step-by-step instructions here.