Skip to content

Commit 4822459

Browse files
chemidyhiranya911
authored andcommitted
add snippets for Send a batch of messages (#264)
1 parent 512351f commit 4822459

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

snippets/messaging.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"log"
2121
"time"
2222

23-
"firebase.google.com/go"
23+
firebase "firebase.google.com/go"
2424
"firebase.google.com/go/messaging"
2525
)
2626

@@ -106,6 +106,40 @@ func sendToCondition(ctx context.Context, client *messaging.Client) {
106106
// [END send_to_condition_golang]
107107
}
108108

109+
func sendAll(ctx context.Context, client *messaging.Client) {
110+
// This registration token comes from the client FCM SDKs.
111+
registrationToken := "YOUR_REGISTRATION_TOKEN"
112+
113+
// [START send_a_batch_golang]
114+
// Create a list containing up to 100 messages.
115+
messages := []*messaging.Message{
116+
{
117+
Notification: &messaging.Notification{
118+
Title: "Price drop",
119+
Body: "5% off all electronics",
120+
},
121+
Token: registrationToken,
122+
},
123+
{
124+
Notification: &messaging.Notification{
125+
Title: "Price drop",
126+
Body: "2% off all books",
127+
},
128+
Topic: "readers-club",
129+
},
130+
}
131+
132+
br, err := client.SendAll(context.Background(), messages)
133+
if err != nil {
134+
log.Fatalln(err)
135+
}
136+
137+
// See the BatchResponse reference documentation
138+
// for the contents of response.
139+
fmt.Println(br.SuccessCount, " messages were sent successfully")
140+
// [END send_a_batch_golang]
141+
}
142+
109143
func sendDryRun(ctx context.Context, client *messaging.Client) {
110144
message := &messaging.Message{
111145
Data: map[string]string{

0 commit comments

Comments
 (0)