diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/send_twilio.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/send_twilio.sh b/tools/send_twilio.sh new file mode 100755 index 0000000..cb9717e --- /dev/null +++ b/tools/send_twilio.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -e + +# @describe Send SMS or Twilio Messaging Channels messages using Twilio API. +# @env TWILIO_ACCOUNT_SID! The twilio account sid +# @env TWILIO_AUTH_TOKEN! The twilio auth token +# @env TWILIO_FROM_NUMBER! The twilio from number +# @option --to-number! The recipient's phone number. Prefix with 'whatsapp:' for WhatsApp messages, e.g. whatsapp:+1234567890 +# @option --message! The content of the message to be sent + +main() { + from_number="$TWILIO_FROM_NUMBER" + to_number="$argc_to_number" + if [[ "$to_number" == 'whatsapp:'* ]]; then + from_number="whatsapp:$from_number" + fi + if [[ "$to_number" != 'whatsapp:'* && "$to_number" != '+'* ]]; then + to_number="+$to_number" + fi + res="$(curl -s -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \ + -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \ + -w "\n%{http_code}" \ + --data-urlencode "From=$from_number" \ + --data-urlencode "To=$to_number" \ + --data-urlencode "Body=$argc_message")" + status="$(echo "$res" | tail -n 1)" + body="$(echo "$res" | head -n -1)" + if [[ "$status" -ge 200 && "$status" -lt 300 ]]; then + if [[ "$(echo "$body" | jq -r 'has("sid")')" == "true" ]]; then + echo "Message sent successfully" >> "$LLM_OUTPUT" + else + _die "$body" + fi + else + _die "$body" + fi +} + +_die() { + echo "$*" >&2 + exit 1 +} + +eval "$(argc --argc-eval "$0" "$@")" |
