@@ -17,6 +17,7 @@ def get_user(db: Session, user: str):
17
17
18
18
19
19
def create_announcement (db : Session , announcement : schemas .AnnouncementCreate ):
20
+ print (f"Sending notification { announcement .title } to { len (announcement .recipients )} users" )
20
21
recipients = []
21
22
tokens = []
22
23
for recipient in announcement .recipients :
@@ -25,17 +26,22 @@ def create_announcement(db: Session, announcement: schemas.AnnouncementCreate):
25
26
for token in user .tokens :
26
27
tokens .append (token .token )
27
28
29
+ print (f"Found { len (recipients )} registered users and { len (tokens )} relevant tokens" )
28
30
db_announcement = models .Announcement (title = announcement .title , description = announcement .description ,
29
31
content = announcement .content , recipients = recipients )
30
32
db .add (db_announcement )
31
33
db .commit ()
32
34
db .refresh (db_announcement )
33
35
34
- requests .post ("https://api.expo.dev/v2/push/send" , json = {
35
- "to" : tokens ,
36
- "title" : announcement .title ,
37
- "body" : announcement .description
38
- }, timeout = 10 )
36
+ for token in tokens :
37
+ result = requests .post ("https://exp.host/--/api/v2/push/send" , json = {
38
+ "to" : token ,
39
+ "title" : announcement .title ,
40
+ "body" : announcement .description
41
+ }, timeout = 10 )
42
+ if result .status_code != 200 :
43
+ print (f"Oeps, er ging iets mis { result .content } " )
44
+
39
45
return db_announcement
40
46
41
47
0 commit comments