aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-10-04 12:25:41 -0700
committerPinapelz <yukais@pinapelz.com>2025-10-04 12:25:41 -0700
commit4a904a11a8e69a744b07fe2ae9e64ff2f6958eec (patch)
treef1e762af4a13f45551b3d6068676f2a045ee83c8
parent81906842665debc9c390c917e8e2e3a030d8c1c7 (diff)
remove fcm tokens from kv when they are unresponsive
-rw-r--r--generate.py1
-rw-r--r--notifications.py15
2 files changed, 14 insertions, 2 deletions
diff --git a/generate.py b/generate.py
index 1c611b0..83fce32 100644
--- a/generate.py
+++ b/generate.py
@@ -266,7 +266,6 @@ def generate_museca_plus_news_file():
def generate_rbdx_plus_news_file():
news = generate_news_file("rb_deluxe_plus_news", constants.RB_DELUXE_PLUS_NEWS)
- attempt_broadcast_notifications(news, "New information for REFLEC BEAT", "rbdx_plus")
return news
if __name__ == "__main__":
diff --git a/notifications.py b/notifications.py
index bb235fa..0ec36cb 100644
--- a/notifications.py
+++ b/notifications.py
@@ -55,8 +55,21 @@ def broadcast_to_topic(topic: str, title: str, body: str, image):
print(f"Successfully sent {response.success_count} messages out of {len(tokens)}")
if response.failure_count > 0:
print(f"Failed to send {response.failure_count} messages")
+ upstash_rest_api_url = os.environ.get("KV_REST_API_URL")
+ upstash_token = os.environ.get("KV_REST_API_TOKEN")
for idx, error in enumerate(response.responses):
if not error.success:
- print(f"Error for token {tokens[idx]}: {error.exception}")
+ failed_token = tokens[idx]
+ print(f"Error for token {failed_token}: {error.exception}")
+ url = f"{upstash_rest_api_url}/srem/fcm-{topic}"
+ resp = requests.post(
+ url,
+ headers={"Authorization": f"Bearer {upstash_token}"},
+ json={"value": failed_token}
+ )
+ if resp.status_code != 200:
+ print(f"Failed to remove token {failed_token} from topic '{topic}': {resp.text}")
+ else:
+ print(f"Removed token {failed_token} from topic '{topic}'")
except Exception as e:
print(f"Error sending multicast message: {e}")
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage