Sun, May 12, 2019
Read in 3 minutes
It's a powerful tool being able to easily send notifications using PowerShell.
I was tinkering a bit with getting information about Counter-Strike: Global Offensive (CS:GO) streams on Twitch.tv, and wondered if there was an easy way to get notifications on my smartphone, without building and publishing an app, and without using texts and e-mails, and, most importantly, using PowerShell.
IFTTT is a pretty neat service that integrates different things, and it can do quite a lot. For example, want to get an e-mail when a specific person tweets? Want to start your Roomba robot vacuum cleaner when you leave for work? Want to change the color of your Philips HUE lights when you get a new follower on Twitter? It can do that, easily, and these integrations are called Applets.
To use IFTTT, the first step is, unsurprisingly, to create an account. After I’m logged in, I browse to My Applets to create a new one.
IFTTT supports webhooks, so I want to create an Applet that, when a webhook is triggered, creates a notification on my smartphone. It’s quite simple to use IFTTT, but here are all the steps I did to make it work, just to, you know… be thorough.
When triggering a webhook on IFTTT, it needs an event name, which identifies the Applet where it belongs. I need this name later when I’m going to trigger the webhook.
I’m going with the rich notifications because it looks pretty, and it can show the relevant information directly.
When using webhooks on IFTTT, it’s possible to pass a maximum of 3 values, appropriately named value1, value2 and yes, you guessed it, value3. I’m using them to show the channel name, amount of viewers, and the title of the channel.
The Image URL is optional, but I’m using a CS:GO logo to, again, make it pretty.
The Applet is ready, but I still need the key to use it. The easiest way to get that is to click the gear icon on my newly created Applet, then click Webhooks in the breadcrumbs. Alternatively, I can search for webhooks in services.
From the Webhooks page, I can find the key under Settings.
There’s more detailed information about how the webhook works by following the URL, but all I need is the highlighted key.
To make it all work, I need a bit of PowerShell magic.
function Send-IftttAppNotification {
[cmdletbinding()]
param(
[Parameter(Mandatory)]
[string]$EventName,
[Parameter(Mandatory)]
[string]$Key,
[string]$Value1,
[string]$Value2,
[string]$Value3
)
$webhookUrl = "https://maker.ifttt.com/trigger/{0}/with/key/{1}" -f $EventName, $Key
$body = @{
value1 = $Value1
value2 = $Value2
value3 = $Value3
}
Invoke-RestMethod -Method Get -Uri $webhookUrl -Body $body
}
This was a lot easier than I anticipated, and the possibilities for how to use it are endless.
Happy hacking!