@@ -20,7 +20,7 @@ import (
20
20
"log"
21
21
"time"
22
22
23
- "firebase.google.com/go"
23
+ firebase "firebase.google.com/go"
24
24
"firebase.google.com/go/messaging"
25
25
)
26
26
@@ -106,6 +106,40 @@ func sendToCondition(ctx context.Context, client *messaging.Client) {
106
106
// [END send_to_condition_golang]
107
107
}
108
108
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
+
109
143
func sendDryRun (ctx context.Context , client * messaging.Client ) {
110
144
message := & messaging.Message {
111
145
Data : map [string ]string {
0 commit comments