forked from cloudwebrtc/go-sip-ua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcm.go
38 lines (30 loc) · 876 Bytes
/
fcm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package fcm
import (
"fmt"
"context"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
"google.golang.org/api/option"
)
func FCMPush(fcmCert string, token string, payload map[string]string) (string, error) {
opt := option.WithCredentialsFile(fcmCert)
app, err := firebase.NewApp(context.Background(), nil, opt)
// Obtain a messaging.Client from the App.
ctx := context.Background()
client, err := app.Messaging(ctx)
// See documentation on defining a message payload.
message := &messaging.Message{
Data: payload,
Token: token,
}
// Send a message to the device corresponding to the provided
// registration token.
response, err := client.Send(ctx, message)
if err != nil {
fmt.Println(err)
return "", err
}
// Response is a message ID string.
fmt.Println("Successfully sent message:", response)
return response, err
}