Skip to content

Instantly share code, notes, and snippets.

@bevinduplessis
Forked from whatsmate/send-whatsapp.ps1
Created December 7, 2016 07:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bevinduplessis/c3631d26f3f10fbc480ed0a6064a1e52 to your computer and use it in GitHub Desktop.
Save bevinduplessis/c3631d26f3f10fbc480ed0a6064a1e52 to your computer and use it in GitHub Desktop.
Sending a WhatsApp message from a Powershell script
$number = "12025550108"
$message = "Howdy, this is a message from PowerShell."
$clientId = "FREE_TRIAL_ACCOUNT" # No need to change
$clientSecret = "PUBLIC_SECRET" # No need to change
$jsonObj = @{'number'=$number;
'message'=$message;}
Try {
$res = Invoke-WebRequest -Uri 'http://api.whatsmate.net/v1/whatsapp/queue/message' `
-Method Post `
-Headers @{"X-WM-CLIENT-ID"=$clientId; "X-WM-CLIENT-SECRET"=$clientSecret;} `
-Body (ConvertTo-Json $jsonObj)
Write-host "Status Code: " $res.StatusCode
Write-host $res.Content
}
Catch {
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
Write-host "Status Code: " $_.Exception.Response.StatusCode
Write-host $responseBody
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment