From 32af2b8141bddb7230dd4db7e6612703f2dfc25b Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Thu, 22 Jun 2023 18:05:56 -0400 Subject: [PATCH 1/3] [chore] Release 4.12.0 (#561) - Release 4.12.0 --- firebase.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.go b/firebase.go index a06829b1..fb3b0b47 100644 --- a/firebase.go +++ b/firebase.go @@ -39,7 +39,7 @@ import ( var defaultAuthOverrides = make(map[string]interface{}) // Version of the Firebase Go Admin SDK. -const Version = "4.11.0" +const Version = "4.12.0" // firebaseEnvName is the name of the environment variable with the Config. const firebaseEnvName = "FIREBASE_CONFIG" From 02300a8e865290c35d0ff92ff241ee38ccd814a7 Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Tue, 11 Jul 2023 12:21:57 -0400 Subject: [PATCH 2/3] Revert "[chore] Release 4.12.0 (#561)" (#565) This reverts commit 32af2b8141bddb7230dd4db7e6612703f2dfc25b. --- firebase.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.go b/firebase.go index fb3b0b47..a06829b1 100644 --- a/firebase.go +++ b/firebase.go @@ -39,7 +39,7 @@ import ( var defaultAuthOverrides = make(map[string]interface{}) // Version of the Firebase Go Admin SDK. -const Version = "4.12.0" +const Version = "4.11.0" // firebaseEnvName is the name of the environment variable with the Config. const firebaseEnvName = "FIREBASE_CONFIG" From af8dc164d125a49a838a51fa4bfad43b6892cbcd Mon Sep 17 00:00:00 2001 From: joefspiro <97258781+joefspiro@users.noreply.github.com> Date: Thu, 12 Jun 2025 16:54:39 -0400 Subject: [PATCH 3/3] Adds sendEach snippets. --- snippets/messaging.go | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/snippets/messaging.go b/snippets/messaging.go index eec36504..f2c67e75 100644 --- a/snippets/messaging.go +++ b/snippets/messaging.go @@ -140,6 +140,40 @@ func sendAll(ctx context.Context, client *messaging.Client) { // [END send_all] } +func sendEach(ctx context.Context, client *messaging.Client) { + // This registration token comes from the client FCM SDKs. + registrationToken := "YOUR_REGISTRATION_TOKEN" + + // [START send_each] + // Create a list containing up to 500 messages. + messages := []*messaging.Message{ + { + Notification: &messaging.Notification{ + Title: "Price drop", + Body: "5% off all electronics", + }, + Token: registrationToken, + }, + { + Notification: &messaging.Notification{ + Title: "Price drop", + Body: "2% off all books", + }, + Topic: "readers-club", + }, + } + + br, err := client.SendEach(context.Background(), messages) + if err != nil { + log.Fatalln(err) + } + + // See the BatchResponse reference documentation + // for the contents of response. + fmt.Printf("%d messages were sent successfully\n", br.SuccessCount) + // [END send_each] +} + func sendMulticast(ctx context.Context, client *messaging.Client) { // [START send_multicast] // Create a list containing up to 500 registration tokens. @@ -204,6 +238,42 @@ func sendMulticastAndHandleErrors(ctx context.Context, client *messaging.Client) // [END send_multicast_error] } +func sendEachForMulticastAndHandleErrors(ctx context.Context, client *messaging.Client) { + // [START send_each_for_multicast_error] + // Create a list containing up to 500 registration tokens. + // This registration tokens come from the client FCM SDKs. + registrationTokens := []string{ + "YOUR_REGISTRATION_TOKEN_1", + // ... + "YOUR_REGISTRATION_TOKEN_n", + } + message := &messaging.MulticastMessage{ + Data: map[string]string{ + "score": "850", + "time": "2:45", + }, + Tokens: registrationTokens, + } + + br, err := client.SendEachForMulticast(context.Background(), message) + if err != nil { + log.Fatalln(err) + } + + if br.FailureCount > 0 { + var failedTokens []string + for idx, resp := range br.Responses { + if !resp.Success { + // The order of responses corresponds to the order of the registration tokens. + failedTokens = append(failedTokens, registrationTokens[idx]) + } + } + + fmt.Printf("List of tokens that caused failures: %v\n", failedTokens) + } + // [END send_each_for_multicast_error] +} + func sendDryRun(ctx context.Context, client *messaging.Client) { message := &messaging.Message{ Data: map[string]string{