mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-29 13:47:49 +00:00
Fix sms sending
When post data is set as text string, some characters like `plus` were not escaped.
This commit is contained in:
parent
a60ed71883
commit
ab3d661212
@ -14,9 +14,6 @@ if (-not (QWINSTA | FINDSTR $env:USERNAME)) {
|
|||||||
$MY_NUMBER='+xxx'
|
$MY_NUMBER='+xxx'
|
||||||
$HER_NUMBER='+xxx'
|
$HER_NUMBER='+xxx'
|
||||||
|
|
||||||
$TWILIO_ACCOUNT_SID = 'xxx'
|
|
||||||
$TWILIO_AUTH_TOKEN = 'xxx'
|
|
||||||
|
|
||||||
$REASONS=
|
$REASONS=
|
||||||
'Working hard',
|
'Working hard',
|
||||||
'Gotta ship this feature',
|
'Gotta ship this feature',
|
||||||
@ -26,14 +23,18 @@ $RAND = Get-Random -Maximum $REASONS.Count
|
|||||||
|
|
||||||
$MSG="Late at work. $REASONS[$RAND]"
|
$MSG="Late at work. $REASONS[$RAND]"
|
||||||
|
|
||||||
|
$API_URL = "https://api.twilio.com/2010-04-01/Accounts/$env:TWILIO_ACCOUNT_SID/Messages"
|
||||||
|
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $env:TWILIO_ACCOUNT_SID,$env:TWILIO_AUTH_TOKEN)))
|
||||||
|
$body = @{
|
||||||
|
From = $MY_NUMBER;
|
||||||
|
To = $HER_NUMBER;
|
||||||
|
Body = $MSG;
|
||||||
|
}
|
||||||
|
|
||||||
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN)))
|
#Send a text message and Log errors
|
||||||
|
|
||||||
#Send a text messag and Log errors
|
|
||||||
try{
|
try{
|
||||||
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages" -Body "From=$MY_NUMBER&To=$HER_NUMBER&Body=$MSG" > $null
|
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} $API_URL -Body $body > $null
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Write-Host "Failed to send SMS: $_"
|
Write-Host "Failed to send SMS: $_"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user