-
-
Save bevinduplessis/c3631d26f3f10fbc480ed0a6064a1e52 to your computer and use it in GitHub Desktop.
Sending a WhatsApp message from a Powershell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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