Skip to content

Adds sendEach snippets for FCM. #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
54b8114
Merge dev into master
google-oss-bot May 21, 2020
cef91ac
Merge dev into master
google-oss-bot Jun 16, 2020
77177c7
Merge dev into master
google-oss-bot Oct 22, 2020
a957589
Merge dev into master
google-oss-bot Jan 28, 2021
eb0d2a0
Merge dev into master
google-oss-bot Mar 24, 2021
05378ef
Merge dev into master
google-oss-bot Mar 29, 2021
4121c50
Merge dev into master
google-oss-bot Apr 14, 2021
928b104
Merge dev into master
google-oss-bot Jun 2, 2021
02cde4f
Merge dev into master
google-oss-bot Nov 4, 2021
6b40682
Merge dev into master
google-oss-bot Dec 15, 2021
e60757f
Merge dev into master
google-oss-bot Jan 20, 2022
bb055ed
Merge dev into master
google-oss-bot Apr 6, 2022
23a1f17
Merge dev into master
google-oss-bot Oct 6, 2022
1d24577
Merge dev into master
google-oss-bot Nov 10, 2022
61c6c04
Merge dev into master
google-oss-bot Apr 6, 2023
32af2b8
[chore] Release 4.12.0 (#561)
lahirumaramba Jun 22, 2023
02300a8
Revert "[chore] Release 4.12.0 (#561)" (#565)
lahirumaramba Jul 11, 2023
74c9bd5
Merge dev into master
google-oss-bot Jul 12, 2023
37c7936
Merge dev into master
google-oss-bot Sep 25, 2023
b04387e
Merge dev into master
google-oss-bot Nov 23, 2023
87b867c
Merge dev into master
google-oss-bot Apr 10, 2024
6a28190
Merge dev into master
google-oss-bot May 30, 2024
c3be6f2
Merge dev into master
google-oss-bot Oct 24, 2024
afeaa15
Merge dev into master
google-oss-bot Dec 5, 2024
570427a
Merge dev into master
google-oss-bot Feb 13, 2025
fe866a0
Merge dev into master
google-oss-bot Jun 5, 2025
db240e4
Merge dev into master
google-oss-bot Jun 11, 2025
af8dc16
Adds sendEach snippets.
joefspiro Jun 12, 2025
f470e89
Merge branch 'dev' into send-each-snippets
joefspiro Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions snippets/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
// [END send_multicast_error]
}

func sendEachForMulticastAndHandleErrors(ctx context.Context, client *messaging.Client) {

Check failure on line 239 in snippets/messaging.go

View workflow job for this annotation

GitHub Actions / Module build (1.24)

other declaration of sendEachForMulticastAndHandleErrors

Check failure on line 239 in snippets/messaging.go

View workflow job for this annotation

GitHub Actions / Module build (1.23)

other declaration of sendEachForMulticastAndHandleErrors
// [START send_each_for_multicast_error]
// Create a list containing up to 500 registration tokens.
// This registration tokens come from the client FCM SDKs.
Expand Down Expand Up @@ -272,6 +272,42 @@
// [END send_each_for_multicast_error]
}

func sendEachForMulticastAndHandleErrors(ctx context.Context, client *messaging.Client) {

Check failure on line 275 in snippets/messaging.go

View workflow job for this annotation

GitHub Actions / Module build (1.24)

sendEachForMulticastAndHandleErrors redeclared in this block

Check failure on line 275 in snippets/messaging.go

View workflow job for this annotation

GitHub Actions / Module build (1.23)

sendEachForMulticastAndHandleErrors redeclared in this block
// [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{
Expand Down
Loading