Christoph
Christoph

Reputation: 915

Microsoft Teams: How to send a Message/Card to a User from an external App without an Bot

we have an external ASP.NET 4.7 App (in Azure App Service), which should send Messages/Cards to one specific User in Teams (without an Bot).

I managed to send Cards to Channels via the Connector/WebHook, but cannot target an specific User.

How can i do this / which Services are needed?

please as simple as possible :-)

thank you

==========================

update: Sample Code:

Private Shared Sub SendToTeams(ChannelPath As AppSettingsKey, Card As TeamsCard)

    If String.IsNullOrWhiteSpace(ChannelPath) Then Return

    Dim Channel = AppSettings.GetAppSetting(ChannelPath)
    If String.IsNullOrWhiteSpace(Channel) Then Return

    Dim ChannelWebHook = "https://outlook.office.com"

    Dim Client = New RestClient(ChannelWebHook)

    Dim Req = New RestRequest(Method.POST) With {
        .Resource = Channel,
        .RequestFormat = DataFormat.Json
    }

    Dim JSON = Card.SaveJSON(False)

    Req.AddParameter("application/json; charset=utf-8", JSON, ParameterType.RequestBody)

    Dim Erg = Client.Execute(Req)

    Logger.Info("Teams:", Erg.StatusCode)
End Sub

And some Helpers:

Friend Class TeamsCard
    <JsonProperty(PropertyName:="@context")> Public Property context As String = "https://schema.org/extensions"
    <JsonProperty(PropertyName:="@type")> Public Property type As String = "MessageCard"
    Public Property themeColor As String = "ff6100"
    Public Property title As String = "Title"
    Public Property summary As String = "Summary"
    Public Property text As String = "Text"
    Public Property potentialAction As New List(Of TeamsCardAction)
End Class


Friend Class TeamsCardAction
    <JsonProperty(PropertyName:="@type")> Public Property type As String = "OpenUri"
    Public Property name As String = "ButtonText"
    Public Property targets As New List(Of TeamsCardButtonTarget)
    Public Sub New(Text As String, URI As String)
        name = Text
        targets.Add(New TeamsCardButtonTarget With {.uri = URI})
    End Sub
End Class


Friend Class TeamsCardButtonTarget
    Public Property os As String = "default"
    Public Property uri As String = "https://google.com"
End Class

Upvotes: 3

Views: 1643

Answers (1)

Wajeed Shaikh
Wajeed Shaikh

Reputation: 3168

Currently, Office 365 Connectos only support only channels. These can't be user to send message/card to individual users.

Only option to send message to Microsoft Teams individual user would be using Bots.

Upvotes: 1

Related Questions