diff options
| -rw-r--r-- | generate.py | 1 | ||||
| -rw-r--r-- | notifications.py | 15 |
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}") |
