EvotecIT / PSTeams

PSTeams is a PowerShell Module working on Windows / Linux and Mac. It allows sending notifications to Microsoft Teams via WebHook Notifications. It's pretty flexible and provides a bunch of options. Initially, it only supported one sort of Team Cards but since version 2.X.X it supports Adaptive Cards, Hero Cards, List Cards, and Thumbnail Cards. All those new cards have their own cmdlets and the old version of creating Teams Cards stays as-is for compatibility reasons.
MIT License
409 stars 41 forks source link

How can I make a post with a mention, so IT dept gets notifications about the post #17

Closed MOKknudsen closed 2 years ago

MOKknudsen commented 4 years ago

How can I make a post with a mention, so IT dept gets notifications about the post

https://myteamsday.com/2019/03/05/sending-message-with-atmention-onto-a-channel-using-graphapi/

PrzemyslawKlys commented 4 years ago

Right now PSTeams supports only Message Cards using Incoming Webhook and not Graph API. It doesn't support Mentions. However, this is an interesting subject for me. Maybe I should pursue this.

In the meantime, you could try using: https://www.powershellgallery.com/packages/Microsoft.Graph.Teams.Chats straight from Microsoft :-)

MOKknudsen commented 4 years ago

I would really appreciate if you could look into this. I’m really happy with your work in PSTeams 😊

Med venlig hilsen | Best Regards​ Morten Waltorp Knudsen CEO & Senior Consultant [cid:image011.jpg@01D6129D.005B57C0]https://2linkit.net/wp-content/uploads/2018/02/53A1809.jpg [cid:image012.png@01D6129D.005B57C0] +45 40 178 179<tel:+45%2040%20178%20179> [cid:image013.png@01D6129D.005B57C0] MOK@2LINKIT.NETmailto:MOK@2linkit.net [cid:image014.png@01D6129D.005B57C0] [cid:image015.png@01D6129D.005B57C0] [cid:image016.png@01D6129D.005B57C0] [cid:image017.png@01D6129D.005B57C0] [cid:image018.png@01D6129D.005B57C0] [cid:image019.png@01D6129D.005B57C0]http://www.2linkit.net/ Strandvejen 21A 6000 Kolding Denmark 2linkIT QuickSupport ​(TeamViewer) ​https://get.teamviewer.com/2linkit-supporthttps://get.teamviewer.com/2linkit-support

From: Przemysław Kłys notifications@github.com Sent: 14. april 2020 20:35 To: EvotecIT/PSTeams PSTeams@noreply.github.com Cc: Morten Waltorp Knudsen MOK@2LINKIT.NET; Author author@noreply.github.com Subject: [EXT] Re: [EvotecIT/PSTeams] How can I make a post with a mention, so IT dept gets notifications about the post (#17)

Right now PSTeams supports only Message Cards using Incoming Webhook and not Graph API. It doesn't support Mentions. However, this is an interesting subject for me. Maybe I should pursue this.

In the meantime, you could try using: https://www.powershellgallery.com/packages/Microsoft.Graph.Teams.Chatshttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FMicrosoft.Graph.Teams.Chats&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851060873&sdata=b26inEKNJg1SeqWgN9SmoO17kcP5qmhvLECijiZx2wQ%3D&reserved=0 straight from Microsoft :-)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEvotecIT%2FPSTeams%2Fissues%2F17%23issuecomment-613609944&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851060873&sdata=AlkzowjGreH12er1Q4hXlRuAi9io6rfOkLvk2FAFjLw%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKIF7YPME3QLNTNYNLYC6LLRMSUEDANCNFSM4MH4ICSQ&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851070829&sdata=rj4iBsXAOWo68Djy32V7QzLXgTvVSpx1358gqjMDg0k%3D&reserved=0.

MOKknudsen commented 4 years ago

How can I attach file to the post in teams?

Med venlig hilsen | Best Regards Morten Waltorp Knudsen CEO & Senior Consultant +45 40 178 179 MOK@2LINKIT.NET Strandvejen 21A 6000Kolding Denmark 2linkIT QuickSupport ​(TeamViewer) ​https://get.teamviewer.com/2linkit-support


Fra: Przemysław Kłys notifications@github.com Sendt: Tuesday, April 14, 2020 8:34:41 PM Til: EvotecIT/PSTeams PSTeams@noreply.github.com Cc: Morten Waltorp Knudsen MOK@2LINKIT.NET; Author author@noreply.github.com Emne: [EXT] Re: [EvotecIT/PSTeams] How can I make a post with a mention, so IT dept gets notifications about the post (#17)

Right now PSTeams supports only Message Cards using Incoming Webhook and not Graph API. It doesn't support Mentions. However, this is an interesting subject for me. Maybe I should pursue this.

In the meantime, you could try using: https://www.powershellgallery.com/packages/Microsoft.Graph.Teams.Chatshttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FMicrosoft.Graph.Teams.Chats&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851060873&sdata=b26inEKNJg1SeqWgN9SmoO17kcP5qmhvLECijiZx2wQ%3D&reserved=0 straight from Microsoft :-)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEvotecIT%2FPSTeams%2Fissues%2F17%23issuecomment-613609944&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851060873&sdata=AlkzowjGreH12er1Q4hXlRuAi9io6rfOkLvk2FAFjLw%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKIF7YPME3QLNTNYNLYC6LLRMSUEDANCNFSM4MH4ICSQ&data=02%7C01%7Cmok%402linkit.net%7C1821a2dbc8a242af3bdb08d7e0a27f98%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224860851070829&sdata=rj4iBsXAOWo68Djy32V7QzLXgTvVSpx1358gqjMDg0k%3D&reserved=0.

PrzemyslawKlys commented 4 years ago

It's not supported in Message Cards, It may be supported by Graph API

MOKknudsen commented 4 years ago

It appears so:

You can post messages with card attachments referencing existing SharePoint files using the Microsoft Graph APIs for OneDrive and SharePointhttps://docs.microsoft.com/en-us/onedrive/developer/rest-api/. Using the Graph APIs requires obtaining access to a user's OneDrive folder (for personaland groupchat files) or the files in a team's channels (for channel files) through the standard OAuth 2.0 authorization flow.

Please have a look at Send and receive fileshttps://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-files#using-the-microsoft-graph-apisdocumentation.

Med venlig hilsen | Best Regards Morten Waltorp Knudsen CEO & Senior Consultant +45 40 178 179 MOK@2LINKIT.NET Strandvejen 21A 6000Kolding Denmark 2linkIT QuickSupport ​(TeamViewer) ​https://get.teamviewer.com/2linkit-support


Fra: Przemysław Kłys notifications@github.com Sendt: Tuesday, April 14, 2020 10:52:50 PM Til: EvotecIT/PSTeams PSTeams@noreply.github.com Cc: Morten Waltorp Knudsen MOK@2LINKIT.NET; Author author@noreply.github.com Emne: [EXT] Re: [EvotecIT/PSTeams] How can I make a post with a mention, so IT dept gets notifications about the post (#17)

It's not supported in Message Cards, It may be supported by Graph API

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEvotecIT%2FPSTeams%2Fissues%2F17%23issuecomment-613675553&data=02%7C01%7Cmok%402linkit.net%7Cfea19e153ae44e3b0de808d7e0b5ccac%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224943745084110&sdata=xuP7GR%2B84DV0bDz2AnSqhB3eZrhxCmD22mXEUJmfiMs%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKIF7YPRJWC52LKCDHVIEITRMTEKFANCNFSM4MH4ICSQ&data=02%7C01%7Cmok%402linkit.net%7Cfea19e153ae44e3b0de808d7e0b5ccac%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224943745084110&sdata=taMw2KvDiAz6Jr1gYVmny3e26PiLHUlTCG4mMXOvmTo%3D&reserved=0.

MOKknudsen commented 4 years ago

Hi again, Do you have any experience in integrating Flow/Power apps workflow with an approval proces. Example:

Med venlig hilsen | Best Regards​ Morten Waltorp Knudsen CEO & Senior Consultant [cid:image011.jpg@01D61408.0BE047B0]https://2linkit.net/wp-content/uploads/2018/02/53A1809.jpg [cid:image012.png@01D61408.0BE047B0] +45 40 178 179<tel:+45%2040%20178%20179> [cid:image013.png@01D61408.0BE047B0] MOK@2LINKIT.NETmailto:MOK@2linkit.net [cid:image014.png@01D61408.0BE047B0] [cid:image015.png@01D61408.0BE047B0] [cid:image016.png@01D61408.0BE047B0] [cid:image017.png@01D61408.0BE047B0] [cid:image018.png@01D61408.0BE047B0] [cid:image019.png@01D61408.0BE047B0]http://www.2linkit.net/ Strandvejen 21A 6000 Kolding Denmark 2linkIT QuickSupport ​(TeamViewer) ​https://get.teamviewer.com/2linkit-supporthttps://get.teamviewer.com/2linkit-support

From: Przemysław Kłys notifications@github.com Sent: 14. april 2020 22:53 To: EvotecIT/PSTeams PSTeams@noreply.github.com Cc: Morten Waltorp Knudsen MOK@2LINKIT.NET; Author author@noreply.github.com Subject: [EXT] Re: [EvotecIT/PSTeams] How can I make a post with a mention, so IT dept gets notifications about the post (#17)

It's not supported in Message Cards, It may be supported by Graph API

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEvotecIT%2FPSTeams%2Fissues%2F17%23issuecomment-613675553&data=02%7C01%7Cmok%402linkit.net%7Cfea19e153ae44e3b0de808d7e0b5ccac%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224943745084110&sdata=xuP7GR%2B84DV0bDz2AnSqhB3eZrhxCmD22mXEUJmfiMs%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKIF7YPRJWC52LKCDHVIEITRMTEKFANCNFSM4MH4ICSQ&data=02%7C01%7Cmok%402linkit.net%7Cfea19e153ae44e3b0de808d7e0b5ccac%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637224943745084110&sdata=taMw2KvDiAz6Jr1gYVmny3e26PiLHUlTCG4mMXOvmTo%3D&reserved=0.

PrzemyslawKlys commented 4 years ago

PSTeams is not going to help you with that, at least not in the near future.

MOKknudsen commented 4 years ago

is it possible to get a URL link to the message, I post to Teams, so I can refer to it e.g. in a planner task just below my post

Med venlig hilsen | Best Regards​ Morten Waltorp Knudsen CEO & Senior Consultant [cid:image011.jpg@01D619C2.C0EA51E0]https://2linkit.net/wp-content/uploads/2018/02/53A1809.jpg [cid:image012.png@01D619C2.C0EA51E0] +45 40 178 179<tel:+45%2040%20178%20179> [cid:image013.png@01D619C2.C0EA51E0] MOK@2LINKIT.NETmailto:MOK@2linkit.net [cid:image014.png@01D619C2.C0EA51E0] [cid:image015.png@01D619C2.C0EA51E0] [cid:image016.png@01D619C2.C0EA51E0] [cid:image017.png@01D619C2.C0EA51E0] [cid:image018.png@01D619C2.C0EA51E0] [cid:image019.png@01D619C2.C0EA51E0]http://www.2linkit.net/ Strandvejen 21A 6000 Kolding Denmark 2linkIT QuickSupport ​(TeamViewer) ​https://get.teamviewer.com/2linkit-supporthttps://get.teamviewer.com/2linkit-support

From: Przemysław Kłys notifications@github.com Sent: 16. april 2020 19:53 To: EvotecIT/PSTeams PSTeams@noreply.github.com Cc: Morten Waltorp Knudsen MOK@2LINKIT.NET; Author author@noreply.github.com Subject: [EXT] Re: [EvotecIT/PSTeams] How can I make a post with a mention, so IT dept gets notifications about the post (#17)

PSTeams is not going to help you with that, at least not in the near future.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEvotecIT%2FPSTeams%2Fissues%2F17%23issuecomment-614802314&data=02%7C01%7Cmok%402linkit.net%7C26bb87193a9947683beb08d7e22f0a9b%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637226563984690627&sdata=NZI0g5aUIDhZmsVcVZQYe4UBIjU3uVViKZEnzYQCErQ%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKIF7YLV2P5G7PTLDM5G6B3RM5AYXANCNFSM4MH4ICSQ&data=02%7C01%7Cmok%402linkit.net%7C26bb87193a9947683beb08d7e22f0a9b%7Cf0fa27a08e7c4f639a77ec94786b7c9e%7C1%7C0%7C637226563984690627&sdata=ywqPlBLQvwi8khRf4LVDsPwA2WMyMheF6DgoB3SVdtA%3D&reserved=0.

PrzemyslawKlys commented 4 years ago

Don't think so.

anhducng commented 2 years ago

It looks like MS Teams now support mention within Adaptive Card

https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#mention-support-within-adaptive-cards

PrzemyslawKlys commented 2 years ago

I'll verify this, but:

image

So it says bots and messaging extensions - what we do may not be applicable. And i you check my tries from months back I was using the code they propose

https://github.com/EvotecIT/PSTeams/blob/1198dd77be84bf6bbef9dda7396a55a32cdd9df5/Public/New-AdaptiveCard.ps1#L171-L207

But maybe they enabled it in the backend and we just need to check things.

robinmalik commented 2 years ago

This works: https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#user-mention-in-incoming-webhook-with-adaptive-cards

but the user doesn't receive any notification they've been tagged. Note:

image

PrzemyslawKlys commented 2 years ago

ok, super cool. Time to add it I guess :)

PrzemyslawKlys commented 2 years ago

Well, it seems not much have changed

image

It still acts the same 1 year later

image

I guess I can add it, and when it's really usable it will just start working.

PrzemyslawKlys commented 2 years ago

Mentions added:

image

New-AdaptiveCard -Uri $Env:TEAMSPESTERID -VerticalContentAlignment center {
    New-AdaptiveTextBlock -Size ExtraLarge -Weight Bolder -Text 'Test' -Color Attention -HorizontalAlignment Center
    New-AdaptiveColumnSet {
        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Dark
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Light
        }
        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Warning
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1' -Color Good
        }
        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Name</at>' -Color Warning
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Zenon Jaskuła</at>' -Color Warning
        }
    }
    New-AdaptiveMention -Text 'Zenon Jaskuła' -UserPrincipalName 'przemyslaw.klys@evotec.test'
    New-AdaptiveMention -Text 'Name' -UserPrincipalName 'przemyslaw.klys@evotec.test'
} -Verbose #-SelectAction Action.OpenUrl -SelectActionUrl 'https://evotec.xyz'

But it's a bit useless because mention is mention, but without notification ;/

PrzemyslawKlys commented 2 years ago

Closing, hopefully things will start working automatically once Microsoft enables it.

robinmalik commented 2 years ago

Mention notifications now work and have tested the above code - all good.

PrzemyslawKlys commented 2 years ago

Great! I just tested and it seems to work, with just one issue - you need chars are removed along with the data so you need to add additional text... or are you seeing something different?

        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Name</at>' -Color Warning
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1 <at>Przemysław Kłys</at> Przemysław Kłys' -Color Warning
        }

image

PrzemyslawKlys commented 2 years ago

It seems the implementation should be: "text": "Hi <at>Adele UPN</at>, <at>Adele AAD</at>" so it would seem you need to do both?

Source: https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#user-mention-in-incoming-webhook-with-adaptive-cards

robinmalik commented 2 years ago

I'm not sure exactly what you mean by "you need chars are removed along with the data so you need to add additional text" but I think I know what you mean. This worked for me, outputting "Hello Robin" only (but I get the notification, and that's the tag text):

New-AdaptiveCard -Uri $TeamsID -FullWidth -VerticalContentAlignment center {
    New-AdaptiveTextBlock -Size ExtraLarge -Weight Bolder -Text 'Test' -Color Attention -HorizontalAlignment Center
    New-AdaptiveColumnSet {
        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Test Card Title 1'
        }
        New-AdaptiveColumn {
            New-AdaptiveTextBlock -Size 'Medium' -Text 'Hello Robin <at>Robin Malik</at>'
        }
    }
    New-AdaptiveMention -Text 'Robin Malik' -UserPrincipalName 'username@domain.com'
}

I think the documentation is just being a little lazy, using a single TextBlock to generate/link to two methods of tagging/notifying users.

PrzemyslawKlys commented 2 years ago

Right, so you need to add text you want to display and at the same time at to get notified, but then you loose the "marking" that you normally get, which I guess is ok, but somewhat inconsistent.