1

vbscript for sending pushover notifications

Hey All,

I was looking for a way to send pushover notifications from VB script and couldn't find a way online to send notifications with Windows native scripting. The example code on Pushover.net has Powershell script and an example using a third party curl program, neither of which worked for what I wanted to do.

After a bit of futzing around with the code, I came up with this working example.

Note: I offer no assurances or guarantees on this, and I'm not the guy you want to debug this code if something doesn't work. In other words, I'm not a programmer, I just play one on TV. :)

Usage: cscript pushover.vbs "Hello World"

#Pushover.vbs

Dim parameters
Set parameters = CreateObject("Scripting.Dictionary")
parameters.Add "token", "APP_TOKEN"
parameters.Add "user", "USER_TOKEN"
parameters.Add "message", WScript.Arguments.Item(0)

Dim client
Set client = CreateObject("MSXML2.XMLHTTP")
client.Open "POST", "https://api.pushover.net/1/messages.json", False
client.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
client.send EncodeParameters(parameters)

Function EncodeParameters(dict)
Dim encodedParams
For Each key In dict.Keys
If Not IsEmpty(encodedParams) Then
encodedParams = encodedParams & "&"
End If
encodedParams = encodedParams & key & "=" & URLDecode(dict(key))
Next
EncodeParameters = encodedParams
End Function

Function URLDecode(str)
Dim htmlDecode, stream
Set htmlDecode = CreateObject("htmlfile")
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.WriteText str
stream.Position = 0
htmlDecode.Write stream.ReadText
URLDecode = htmlDecode.documentElement.innerText
End Function