Created
October 10, 2019 15:31
-
-
Save cmbuckley/d5ea5c3e49645797f5f22b6381ab418a to your computer and use it in GitHub Desktop.
Nexmo SMS script
This file contains hidden or 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
#!/bin/bash | |
function msisdn() { | |
sed 's/^0/44/' <<< "$1" | |
} | |
API=https://rest.nexmo.com/sms/json | |
KEY= # Nexmo API key | |
SECRET= # Nexmo API secret | |
DEFAULT= # Default SMS sender | |
FROM=$(msisdn ${3:-$DEFAULT}) | |
TO=$(msisdn $1) | |
TEXT="${2:-}" | |
TYPE=unicode | |
# send as text if it can fit in GSM 03.38 | |
grep -Pq '^[\r\n -_a-~¡£¤¥§¿ÄÅÆÇÉÑÑÖØÜßàäåæèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€]*$' <<< "$TEXT" && TYPE=text | |
# check usage | |
if [ $# -lt 2 ]; then | |
echo "Usage: $(basename "$0") TO MSG [FROM]" >&2 | |
exit 1 | |
fi | |
curl -Ss $API -G -d "api_key=$KEY&api_secret=$SECRET&from=$FROM&to=$TO&type=$TYPE" --data-urlencode "text=$TEXT" | python -mjson.tool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment