Skip to content

Commit ab3d661

Browse files
committed
Fix sms sending
When post data is set as text string, some characters like `plus` were not escaped.
1 parent a60ed71 commit ab3d661

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

powershell/smack_my_bitch_up.ps1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ if (-not (QWINSTA | FINDSTR $env:USERNAME)) {
1414
$MY_NUMBER='+xxx'
1515
$HER_NUMBER='+xxx'
1616

17-
$TWILIO_ACCOUNT_SID = 'xxx'
18-
$TWILIO_AUTH_TOKEN = 'xxx'
19-
2017
$REASONS=
2118
'Working hard',
2219
'Gotta ship this feature',
@@ -26,14 +23,18 @@ $RAND = Get-Random -Maximum $REASONS.Count
2623

2724
$MSG="Late at work. $REASONS[$RAND]"
2825

26+
$API_URL = "https://api.twilio.com/2010-04-01/Accounts/$env:TWILIO_ACCOUNT_SID/Messages"
27+
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $env:TWILIO_ACCOUNT_SID,$env:TWILIO_AUTH_TOKEN)))
28+
$body = @{
29+
From = $MY_NUMBER;
30+
To = $HER_NUMBER;
31+
Body = $MSG;
32+
}
2933

30-
$BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $TWILIO_ACCOUNT_SID,$TWILIO_AUTH_TOKEN)))
31-
32-
#Send a text messag and Log errors
34+
#Send a text message and Log errors
3335
try{
34-
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
36+
Invoke-RestMethod -Method Post -Headers @{Authorization=("Basic {0}" -f $BASE64AUTHINFO)} $API_URL -Body $body > $null
3537
}
3638
catch{
3739
Write-Host "Failed to send SMS: $_"
3840
}
39-

0 commit comments

Comments
 (0)