π‘ PSTeams β New way / Christmas Edition
This weekend I've decided to add some new syntax and some more functionality. For some time, I've been working on PSWriteHTML module which allowed me to learn some new things and at the same time fell in love with the syntax it uses. Therefore today PSTeams gets it's very own DSL syntax.
$TeamsID = ''
Send-TeamsMessage -Verbose {
New-TeamsSection -ActivityTitle "**Elon Musk**" -ActivitySubtitle "@elonmusk - 9/12/2016 at 5:33pm" -ActivityImageLink "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg" -ActivityText "Climate change explained in comic book form by xkcd xkcd.com/1732"
New-TeamsSection -ActivityTitle "**Mark Knopfler**" -ActivitySubtitle "@MarkKnopfler - 9/12/2016 at 1:12pm" -ActivityImageLink "https://pbs.twimg.com/profile_images/1042367841117384704/YvrqQiBK_400x400.jpg" -ActivityText "Mark Knopfler features on B.B King's all-star album of Blues greats, released on this day in 2005..."
New-TeamsSection -ActivityTitle "**Elon Musk**" -ActivitySubtitle "@elonmusk - 9/12/2016 at 5:33pm" -ActivityImageLink "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg" -ActivityText "Climate change explained in comic book form by xkcd xkcd.com/1732"
} -Uri $TeamsID -Color DarkSeaGreen -MessageSummary 'Tweet'
I know the code isn't pretty and hard to read, but it delivers a full message in just four lines of code. Code above generates the following JSON, which is then sent to Microsoft Teams.
Body {
"sections": [
{
"activityTitle": "**Elon Musk**",
"activitySubtitle": "@elonmusk - 9/12/2016 at 5:33pm",
"activityImage": "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg",
"activityText": "Climate change explained in comic book form by xkcd xkcd.com/1732"
},
{
"activityTitle": "**Mark Knopfler**",
"activitySubtitle": "@MarkKnopfler - 9/12/2016 at 1:12pm",
"activityImage": "https://pbs.twimg.com/profile_images/1042367841117384704/YvrqQiBK_400x400.jpg",
"activityText": "Mark Knopfler features on B.B King\u0027s all-star album of Blues greats, released on this day in 2005..."
},
{
"activityTitle": "**Elon Musk**",
"activitySubtitle": "@elonmusk - 9/12/2016 at 5:33pm",
"activityImage": "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg",
"activityText": "Climate change explained in comic book form by xkcd xkcd.com/1732"
}
],
"themeColor": "#8fbc8f",
"summary": "Tweet"
}
The code above allows you to define one or more sections within Send-TeamsMessage. You can set for each section its Title, Subtitle, Image Link, or Image Text. All that is fully translated to JSON and displayed nicely in Microsoft Teams. You can also use Splatting if you like, for readability purposes.
Send-TeamsMessage -Verbose {
$Splat1 = @{
ActivityTitle = "**Elon Musk**"
ActivitySubtitle = "@elonmusk - 9/12/2016 at 5:33pm"
ActivityImageLink = "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg"
ActivityText = "Climate change explained in comic book form by xkcd xkcd.com/1732"
}
New-TeamsSection @Splat1
$Splat2 = @{
ActivityTitle = "**Mark Knopfler**"
ActivitySubtitle = "@MarkKnopfler - 9/12/2016 at 1:12pm"
ActivityImageLink = "https://pbs.twimg.com/profile_images/1042367841117384704/YvrqQiBK_400x400.jpg"
ActivityText = "Mark Knopfler features on B.B King's all-star album of Blues greats, released on this day in 2005..."
}
New-TeamsSection @Splat2
New-TeamsSection @Splat1
} -Uri $TeamsID -Color DarkSeaGreen -MessageSummary 'Tweet'
Send-TeamsMessage -Verbose {
New-TeamsSection {
ActivityTitle -Title "**Elon Musk**"
ActivitySubtitle -Subtitle "@elonmusk - 9/12/2016 at 5:33pm"
ActivityImageLink -Link "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg"
ActivityText -Text "Climate change explained in comic book form by xkcd xkcd.com/1732"
}
New-TeamsSection {
ActivityTitle -Title "**Mark Knopfler**"
ActivitySubtitle -Subtitle "@MarkKnopfler - 9/12/2016 at 1:12pm"
ActivityImageLink -Link "https://pbs.twimg.com/profile_images/1042367841117384704/YvrqQiBK_400x400.jpg"
ActivityText -Text "Mark Knopfler features on B.B King's all-star album of Blues greats, released on this day in 2005..."
}
New-TeamsSection {
ActivityTitle -Title "**Elon Musk**"
ActivitySubtitle -Subtitle "@elonmusk - 9/12/2016 at 5:33pm"
ActivityImageLink -Link "https://pbs.twimg.com/profile_images/782474226020200448/zDo-gAo0.jpg"
ActivityText -Text "Climate change explained in comic book form by xkcd xkcd.com/1732"
}
} -Uri $TeamsID -Color DarkSeaGreen -MessageSummary 'Tweet'
Whether you prefer to use oneliner, splatting, or DSL style all the way β it's all there.