-
-
Save bruceherve/44586bb62b24ad3ea7601c86068f9bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func SendPushNotification(deviceTokens []string) error { | |
decodedKey, err := getDecodedFireBaseKey() | |
if err != nil { | |
return err | |
} | |
opts := []option.ClientOption{option.WithCredentialsJSON(decodedKey)} | |
app, err := firebase.NewApp(context.Background(), nil, opts...) | |
if err != nil { | |
log.Debug("Error in initializing firebase : %s", err) | |
return err | |
} | |
fcmClient, err := app.Messaging(context.Background()) | |
if err != nil { | |
return err | |
} | |
response, err := fcmClient.SendMulticast(context.Background(), &messaging.MulticastMessage{ | |
Notification: &messaging.Notification{ | |
Title: "Congratulations!!", | |
Body: "You have just implement push notification", | |
}, | |
Tokens: deviceTokens, | |
}) | |
if err != nil { | |
return err | |
} | |
log.Debug("Response success count : ", response.SuccessCount) | |
log.Debug("Response failure count : ", response.FailureCount) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment