Created
July 11, 2018 16:24
-
-
Save rob-watts/02ac94a9b9ce42f0cf59c3e25160c332 to your computer and use it in GitHub Desktop.
A shell script to send an sms message via callfire api
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
#!/usr/bin/env bash | |
function usage { | |
programName=$0 | |
echo "description: use this program to send an email using the SendGrid API" | |
echo "usage: $programName [-p \"to phone\"] [-m \"message\"]" | |
echo " -p The recipient phone" | |
echo " -m The message" | |
exit 1 | |
} | |
while getopts ":p:m:h" opt; do | |
case ${opt} in | |
p) phone="$OPTARG" | |
;; | |
m) message="$OPTARG" | |
;; | |
h) usage | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
if [[ ! "${phone}" || ! "${message}" ]]; then | |
echo "A phone number AND a message is required." | |
usage | |
fi | |
read -rd '' payLoad << EOF | |
[ | |
{ | |
"phoneNumber": "${phone}", | |
"message": "${message}" | |
} | |
] | |
EOF | |
url="https://api.callfire.com/v2/texts" | |
statusCode=$(curl \ | |
--write-out %{http_code} \ | |
-X POST ${url}\ | |
-H 'Content-type: application/json' \ | |
-H 'Authorization: Basic YOURTOKENHERE' \ | |
--data "${payLoad}" ) | |
echo ${statusCode} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment