Last active
March 17, 2022 09:43
-
-
Save hiranya911/8bac5d089b760988c9562ff2327ceade to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"log" | |
firebase "firebase.google.com/go" | |
"firebase.google.com/go/messaging" | |
) | |
func main() { | |
ctx := context.Background() | |
app, err := firebase.NewApp(ctx, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
db, err := app.Firestore(ctx) | |
if err != nil { | |
log.Fatal(err) | |
} | |
snapshot, err := db.Collection("users").Doc("alice").Get(ctx) | |
if err != nil { | |
log.Fatal(err) | |
} | |
topic, err := snapshot.DataAt("topicName") | |
if err != nil { | |
log.Fatal(err) | |
} | |
fcm, err := app.Messaging(ctx) | |
if err != nil { | |
log.Fatal(err) | |
} | |
resp, err := fcm.Send(ctx, &messaging.Message{ | |
Topic: topic.(string), | |
Notification: &messaging.Notification{ | |
Title: "Hello from the other side", | |
Body: "I must have called this proxy a thousand times", | |
}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Println(resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment