From 7ccfa26292439048c8762c2e2a52f0d2d39e97c3 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 28 Aug 2025 17:54:21 -0400 Subject: [PATCH 1/4] Update files --- .gitignore | 4 +- SMS_SETUP.md | 2 +- check_sms_limits.sh | 36 +++++ check_sms_usage.py | 80 ++++++++++ cloudformation/deploy.sh | 16 +- debug_sms.py | 69 +++++++++ index.html | 2 +- set_sms_config.sh | 18 +++ sms_notifier.py | 189 +++++++++++++---------- test_sms_notifications.py | 314 ++++++++++++++++---------------------- test_sms_now.py | 50 ++++++ test_textbelt.py | 72 +++++++++ url_watcher.py | 4 +- 13 files changed, 589 insertions(+), 267 deletions(-) create mode 100755 check_sms_limits.sh create mode 100644 check_sms_usage.py create mode 100644 debug_sms.py create mode 100755 set_sms_config.sh create mode 100644 test_sms_now.py create mode 100644 test_textbelt.py diff --git a/.gitignore b/.gitignore index 1fb803f..4077f6e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ venv/ .coverage* htmlcov/ .coverage_baseline.json -export_env.sh \ No newline at end of file +export_env.sh +.env +.env.local \ No newline at end of file diff --git a/SMS_SETUP.md b/SMS_SETUP.md index cffe9d7..c478583 100644 --- a/SMS_SETUP.md +++ b/SMS_SETUP.md @@ -15,7 +15,7 @@ This guide explains how to set up SMS notifications for the URL Watcher using AW ```bash cd cloudformation -./deploy.sh -p "+1234567890" +cd clo ``` Replace `+1234567890` with your actual phone number in E.164 format. diff --git a/check_sms_limits.sh b/check_sms_limits.sh new file mode 100755 index 0000000..c67ea7c --- /dev/null +++ b/check_sms_limits.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +echo "šŸ” Checking your current SMS configuration..." + +echo " +šŸ“‹ TO INCREASE SMS SPENDING LIMIT: + +1. 🌐 Open AWS Console: + https://us-east-1.console.aws.amazon.com/sns/v3/home?region=us-east-1#/mobile/text-messaging + +2. šŸ“± Navigate to SMS Settings: + - Click 'Mobile' → 'Text messaging (SMS)' + - Look for 'Account-level preferences' + +3. šŸ’° Update Spending Limit: + - Find 'Monthly spending quota for SMS messages' + - Change from \$1.00 to \$10.00 + - Click 'Save changes' + +4. ⚔ Test Immediately: + - Go back to your terminal + - Run: source set_sms_config.sh && python test_sms_now.py + +šŸ“Š SMS COSTS: +- Each SMS: ~\$0.0065 +- Current limit (\$1): ~154 messages/month +- New limit (\$10): ~1,538 messages/month + +🚨 If you can't increase the limit: +- You may need AWS Support to raise account limits +- Or we can switch to email notifications instead +" + +# Check current SMS attributes +echo "Current SMS settings:" +aws sns get-sms-attributes 2>/dev/null || echo "āŒ Cannot check SMS attributes (permission issue)" \ No newline at end of file diff --git a/check_sms_usage.py b/check_sms_usage.py new file mode 100644 index 0000000..df65b4a --- /dev/null +++ b/check_sms_usage.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +""" +Check SMS usage and cost +""" +import boto3 +from datetime import datetime, timedelta + +def check_sms_cost(): + """Check SMS usage through CloudWatch metrics""" + + cloudwatch = boto3.client( + 'cloudwatch', + aws_access_key_id="AKIAVVIGI22T5ZTXH3XS", + aws_secret_access_key="***REMOVED***", + region_name="us-east-1" + ) + + # Get SNS SMS metrics for the last 24 hours + end_time = datetime.utcnow() + start_time = end_time - timedelta(days=1) + + try: + print("Checking SMS message count in last 24 hours...") + + response = cloudwatch.get_metric_statistics( + Namespace='AWS/SNS', + MetricName='NumberOfMessagesSent', + Dimensions=[ + { + 'Name': 'TopicName', + 'Value': 'url-watcher-notifications' + } + ], + StartTime=start_time, + EndTime=end_time, + Period=3600, # 1 hour intervals + Statistics=['Sum'] + ) + + total_messages = sum(point['Sum'] for point in response['Datapoints']) + estimated_cost = total_messages * 0.00645 # $0.00645 per SMS in US + + print(f"šŸ“Š Total messages sent in last 24h: {total_messages}") + print(f"šŸ’° Estimated SMS cost: ${estimated_cost:.4f}") + print(f"🚫 Monthly limit: $1.00") + + if estimated_cost >= 1.0: + print("āŒ You've likely hit your $1 monthly SMS spending limit!") + print("šŸ’” This is why you're not receiving SMS messages.") + else: + print("āœ… You're under the spending limit.") + + except Exception as e: + print(f"āŒ Error checking metrics: {e}") + print("This might be due to insufficient CloudWatch permissions.") + +def suggest_solutions(): + """Suggest solutions for SMS delivery issues""" + print("\nšŸ”§ SOLUTIONS:") + print("1. **Increase SMS Spending Limit:**") + print(" - Go to AWS SNS Console → Mobile → Text messaging (SMS)") + print(" - Request a spending limit increase") + print(" - Or use AWS Support to request higher limit") + print() + print("2. **Check your phone:**") + print(" - SMS might be in spam/blocked messages") + print(" - Check if you've blocked unknown numbers") + print(" - Try with a different phone number") + print() + print("3. **Alternative notification methods:**") + print(" - Use email notifications instead") + print(" - Use Slack/Discord webhooks") + print(" - Use desktop notifications") + print() + print("4. **Test with a different region:**") + print(" - Some regions have different SMS costs/limits") + +if __name__ == "__main__": + check_sms_cost() + suggest_solutions() \ No newline at end of file diff --git a/cloudformation/deploy.sh b/cloudformation/deploy.sh index 4cab6b5..ab9a2b5 100755 --- a/cloudformation/deploy.sh +++ b/cloudformation/deploy.sh @@ -42,8 +42,20 @@ if [[ -z "$PHONE_NUMBER" ]]; then usage fi -# Validate phone number format -if [[ ! "$PHONE_NUMBER" =~ ^\+[1-9][0-9]{1,14}$ ]]; then +# Validate phone number format - E.164 format starts with + followed by 1-15 digits +if [[ ${#PHONE_NUMBER} -lt 3 ]] || [[ ${#PHONE_NUMBER} -gt 15 ]]; then + echo "Error: Phone number must be in E.164 format (e.g., +1234567890)" + exit 1 +fi + +if [[ "$PHONE_NUMBER" != +* ]]; then + echo "Error: Phone number must start with + (E.164 format)" + exit 1 +fi + +# Check that after + there's at least one digit and all remaining characters are digits +DIGITS_PART="${PHONE_NUMBER:1}" +if [[ -z "$DIGITS_PART" ]] || [[ ! "$DIGITS_PART" =~ ^[0-9]*$ ]] || [[ "${DIGITS_PART:0:1}" == "0" ]]; then echo "Error: Phone number must be in E.164 format (e.g., +1234567890)" exit 1 fi diff --git a/debug_sms.py b/debug_sms.py new file mode 100644 index 0000000..562d3e1 --- /dev/null +++ b/debug_sms.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +""" +Debug SMS sending with various approaches +""" +import boto3 +import json +from datetime import datetime + +def test_direct_sms(): + """Test direct SMS sending""" + + # Using the same credentials as before + sns = boto3.client( + 'sns', + aws_access_key_id="AKIAVVIGI22T5ZTXH3XS", + aws_secret_access_key="***REMOVED***", + region_name="us-east-1" + ) + + topic_arn = "arn:aws:sns:us-east-1:***REMOVED***:url-watcher-notifications" + phone_number = "+1***REMOVED***" + + print("Testing SMS sending approaches...") + + # Test 1: Simple message to topic + try: + print("\n1. Sending simple message to topic...") + response = sns.publish( + TopicArn=topic_arn, + Message="Hello from Python! Simple test message.", + Subject="URL Watcher Test" + ) + print(f"āœ… Success - Message ID: {response['MessageId']}") + except Exception as e: + print(f"āŒ Failed: {e}") + + # Test 2: Direct SMS to phone number + try: + print("\n2. Sending direct SMS to phone number...") + response = sns.publish( + PhoneNumber=phone_number, + Message="Direct SMS test - bypassing topic" + ) + print(f"āœ… Success - Message ID: {response['MessageId']}") + except Exception as e: + print(f"āŒ Failed: {e}") + + # Test 3: Check account SMS attributes + try: + print("\n3. Checking SMS account settings...") + attrs = sns.get_sms_attributes() + print("SMS Attributes:") + for key, value in attrs['attributes'].items(): + print(f" {key}: {value}") + except Exception as e: + print(f"āŒ Failed to get SMS attributes: {e}") + + # Test 4: Check topic attributes + try: + print("\n4. Checking topic attributes...") + attrs = sns.get_topic_attributes(TopicArn=topic_arn) + print("Topic Attributes:") + for key, value in attrs['Attributes'].items(): + print(f" {key}: {value}") + except Exception as e: + print(f"āŒ Failed to get topic attributes: {e}") + +if __name__ == "__main__": + test_direct_sms() \ No newline at end of file diff --git a/index.html b/index.html index 836d44d..23fe112 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ Test hello Page -

Hello...

+

Hello so sadi

This is a test page for the URL watcher.

Last updated: