Last active
April 9, 2020 22:44
-
-
Save whatsmate/3ba4213c8aee9a6bfa71 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" # Specify the recipient's number here. NOT the gateway number | |
$message = "Howdy, this is a message from PowerShell." | |
$instanceId = "YOUR_INSTANCE_ID_HERE" # TODO: Replace it with your gateway instance ID | |
$clientId = "YOUR_CLIENT_ID_HERE" # TODO: Replace it with your Forever Green client ID here | |
$clientSecret = "YOUR_CLIENT_SECRET_HERE" # TODO: Replace it with your Forever Green client secret here | |
$jsonObj = @{'number'=$number; | |
'message'=$message;} | |
Try { | |
$res = Invoke-WebRequest -Uri "http://api.whatsmate.net/v3/whatsapp/single/text/message/$instanceId" ` | |
-Method Post ` | |
-Headers @{"X-WM-CLIENT-ID"=$clientId; "X-WM-CLIENT-SECRET"=$clientSecret;} ` | |
-ContentType "application/json; charset=utf-8" ` | |
-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
Write-up: http://whatsmate.github.io/2016-02-19-send-whatsapp-message-powershell-script/