commit 2cba27fe78638b313622c89227074679e978b465
parent 6d98b6992b89a90c46daceed05569f9de1a0d298
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 7 Feb 2026 13:43:14 +0100
more verbose logging for SMS transmissions (#10981)
Diffstat:
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/src/authorization/anastasis-authorization-sms-clicksend.sh b/src/authorization/anastasis-authorization-sms-clicksend.sh
@@ -46,23 +46,24 @@ RESPONSE_CODE=$(echo "$RESPONSE" | jq -r '.response_code')
if [ "$RESPONSE_CODE" != "SUCCESS" ];
then
- echo "Failed to send message, got response code $RESPONSE_CODE." 1>&2
- exit 1
+ echo "Clicksend: failed to send SMS to $PHONE_NUMBER, got response code $RESPONSE_CODE." 1>&2
+ exit 2
fi
MESSAGE_ID=$(echo "$RESPONSE" | jq -r '.data.messages[0].message_id')
if [ "$MESSAGE_ID" == "null" ];
then
- echo "Failed to retrieve message ID." 1>&2
- exit 1
+ echo "Clicksend: failed to retrieve message ID for message to $PHONE_NUMBER." 1>&2
+ echo "$RESPONSE" 1>&2
+ exit 3
fi
MESSAGE_STATUS=$(echo "$RESPONSE" | jq -r '.data.messages[0].status')
if [ "$MESSAGE_STATUS" == "SUCCESS" ];
then
- echo "Message delivered successfully." 1>&2
+ echo "Clicksend: message delivered successfully to $PHONE_NUMBER." 1>&2
exit 0
fi
@@ -77,15 +78,16 @@ do
--user "$CLICKSEND_USERNAME:$CLICKSEND_API_KEY")
echo "$STATUS_RESPONSE" >> "$TMPFILE"
-
+
RESPONSE_CODE=$(echo "$RESPONSE" | jq -r '.response_code')
if [ "$RESPONSE_CODE" != "SUCCESS" ];
then
- echo "Failed to get message status, assuming failure." 1>&2
- exit 1
+ echo "Clicksend: failed to get status for message to $PHONE_NUMBER, assuming failure." 1>&2
+ echo "$RESPONSE" 1>&2
+ exit 4
fi
-
+
STATUS_CODE=$(echo "$STATUS_RESPONSE" | jq -r '.data.status_code')
STATUS_TEXT=$(echo "$STATUS_RESPONSE" | jq -r '.data.status_text')
STATUS=$(echo "$STATUS_TEXT" | awk --field-separator ':' '{print $1}')
@@ -106,14 +108,14 @@ do
sleep 120
;;
*)
- # Unexpected status, keep trying
+ # Unexpected status, keep trying
sleep 5
;;
esac
;;
"201")
# Message delivered to the handset
- echo "Message delivered successfully." 1>&2
+ echo "Clicksend: message delivered successfully to $PHONE_NUMBER." 1>&2
exit 0
;;
"300")
@@ -122,19 +124,19 @@ do
;;
"301")
# Delivery failed
- echo "Message delivery failed: $DESCRIPTION" 1>&2
+ echo "Clicksend: message delivery to $PHONE_NUMBER failed: $DESCRIPTION" 1>&2
exit 1
;;
"FAILED"|"INVALID_RECIPIENT")
- exit 1
+ echo "Clicksend: message delivery to $PHONE_NUMBER failed: $DESCRIPTION" 1>&2
+ exit 6
;;
*)
+ echo "Clicksend: message delivery to $PHONE_NUMBER failed: $DESCRIPTION" 1>&2
sleep 5
;;
esac
done
-echo "Unclear message delivery status $STATUS_CODE ($DESCRIPTION) after $MAX_ITERATIONS iterations. Assuming failure." 1>&2
+echo "Clicksend: unclear message delivery status $STATUS_CODE ($DESCRIPTION) after $MAX_ITERATIONS iterations. Assuming failure." 1>&2
exit 1
-
-
diff --git a/src/authorization/anastasis-authorization-sms-telesign.sh b/src/authorization/anastasis-authorization-sms-telesign.sh
@@ -35,7 +35,8 @@ REFERENCE_ID=$(jq -r '.reference_id' "$TMPFILE")
if [ "$REFERENCE_ID" == "null" ];
then
- echo "Failed to retrieve reference ID." 1>&2
+ echo "Telesign: failed to retrieve reference ID for message to $PHONE_NUMBER." 1>&2
+ echo "$RESPONSE" 1>&2
exit 1
fi
@@ -44,6 +45,7 @@ STATUS_CODE=$(echo "$RESPONSE" | jq -r '.status.code')
case "$STATUS_CODE" in
"200")
# Delivered to headset. Should basically never happen here.
+ echo "Telesign: message delivered successfully to $PHONE_NUMBER." 1>&2
exit 0
;;
"203"|"292"|"295")
@@ -52,7 +54,7 @@ case "$STATUS_CODE" in
;;
"207"|"211"|"220"|"221"|"222"|"231"|"237"|"238")
# Failure to deliver (hard)
- echo "Could not deliver" 1>&2
+ echo "Telesign: could not deliver message to $PHONE_NUMBER: $STATUS_CODE" 1>&2
exit 1
;;
"210")
@@ -60,7 +62,7 @@ case "$STATUS_CODE" in
;;
"250")
# Final status unknown
- echo "Final status unknown, assuming success" 1>&2
+ echo "Telesign: final status unknown for message to $PHONE_NUMBER, assuming success" 1>&2
exit 0
;;
"290")
@@ -68,22 +70,25 @@ case "$STATUS_CODE" in
sleep 2
;;
"502"|"503"|"504"|"505"|"506"|"507"|"508"|"509"|"510"|"511"|"512"|"513"|"514"|"515"|"517"|"520"|"521")
- echo "Carrier problem ($STATUS_CODE)" 1>&2
+ echo "Telesign: carrier problem ($STATUS_CODE) delivering to $PHONE_NUMBER" 1>&2
exit 1
;;
"10000")
# Internal error at telesign...
- echo "Telesign internal error" 1>&2
+ echo "Telesign: internal error delivering to $PHONE_NUMBER" 1>&2
+ echo "$RESPONSE" 1>&2
exit 1
;;
"10019"|"10020")
# Rate limit exceeded. Treating as hard failure for now.
- echo "Rate limit exceeded" 1>&2
+ echo "Telesign: Rate limit exceeded ($STATUS_CODE) delivering to $PHONE_NUMBER" 1>&2
+ echo "$RESPONSE" 1>&2
exit 1
;;
*)
# Many possible status codes for failure...
- echo "Message delivery failed: $STATUS_CODE" 1>&2
+ echo "Telesign: Message delivery to $PHONE_NUMBER failed: $STATUS_CODE" 1>&2
+ echo "$RESPONSE" 1&>2
exit 1
;;
esac
@@ -99,15 +104,15 @@ do
--header "Authorization: Basic $TELESIGN_AUTH_TOKEN")
echo "$STATUS_RESPONSE" >> "$TMPFILE"
-
+
STATUS_CODE=$(echo "$STATUS_RESPONSE" | jq -r '.status.code')
DESCRIPTION=$(echo "$STATUS_RESPONSE" | jq -r '.status.description')
case "$STATUS_CODE" in
"200")
# Delivered to headset. Great!
- echo "Delivered to headset" 1>&2
- exit 0
+ echo "Telesign: message delivered successfully to $PHONE_NUMBER." 1>&2
+ exit 0
;;
"203"|"290"|"292"|"295")
# Delivered to gateway, wait a bit for an update
@@ -119,36 +124,36 @@ do
;;
"207"|"211"|"220"|"221"|"222"|"231"|"237"|"238")
# Failure to deliver (hard)
- echo "Could not deliver" 1>&2
- exit 1
+ echo "Telesign: could not deliver message to $PHONE_NUMBER ($STATUS_CODE)" 1>&2
+ exit 8
;;
"250")
# Final status unknown
- echo "Final status unknown, assuming success" 1>&2
+ echo "Telesign: final status for delivery to $PHONE_NUMBER unknown, assuming success" 1>&2
exit 0
;;
"502"|"503"|"504"|"505"|"506"|"507"|"508"|"509"|"510"|"511"|"512"|"513"|"514"|"515"|"517"|"520"|"521")
- echo "Carrier problem ($STATUS_CODE)" 1>&2
- exit 1
+ echo "Telesign: carrier problem ($STATUS_CODE) for message to $PHONE_NUMBER" 1>&2
+ exit 7
;;
"10000")
# Internal error at telesign...
- echo "Telesign internal error" 1>&2
- exit 1
+ echo "Telesign: internal error for message to $PHONE_NUMBER" 1>&2
+ exit 9
;;
"10019"|"10020")
# Rate limit exceeded. Treating as hard failure for now.
- echo "Rate limit exceeded" 1>&2
- exit 1
+ echo "Telesign: rate limit exceeded for message to $PHONE_NUMBER" 1>&2
+ exit 10
;;
*)
# Many possible status codes for failure...
- echo "Message delivery failed: $STATUS_CODE" 1>&2
- exit 1
+ echo "Telesign: message delivery to $PHONE_NUMBER failed: $STATUS_CODE" 1>&2
+ echo "$RESPONSE" 1&>2
+ exit 11
;;
esac
done
-echo "Unclear message delivery status $STATUS_CODE ($DESCRIPTION) after $MAX_ITERATIONS iterations. Assuming failure." 1>&2
-exit 1
-
+echo "Telesign: unclear delivery status ${STATUS_CODE:-} (${DESCRIPTION:-}) for message to $PHONE_NUMBER after ${MAX_ITERATIONS:-} iterations. Assuming failure." 1>&2
+exit 12
diff --git a/src/authorization/anastasis-authorization-sms.sh b/src/authorization/anastasis-authorization-sms.sh
@@ -5,7 +5,7 @@ set -eu
if [ $# -ne 1 ]
then
- echo "Usage: $0 <phone_number>" 1>&2
+ echo "Usage: $0 '{\"CONTACT_PHONE\":\"+41712345678\"}'" 1>&2
exit 1
fi
@@ -13,7 +13,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME=$(basename "$0")
BASE="${SCRIPT_NAME%.sh}"
-PHONE_NUMBER="$1"
+PHONE_NUMBER=$(echo "$1" | jq -r .CONTACT_PHONE)
MESSAGE=$(cat -)
# List of sub-scripts to try.
@@ -28,10 +28,10 @@ do
then
exit 0
else
- echo "$PROVIDER failed." 1>&2
+ echo "$PROVIDER failed to send to $PHONE_NUMBER." 1>&2
fi
fi
done
-echo "All SMS providers failed." 1>&2
+echo "All SMS providers failed to send to $PHONE_NUMBER." 1>&2
exit 1