Skip to content

Commit

Permalink
feat: implement gRPC support sound field for FCM (#794)
Browse files Browse the repository at this point in the history
- Add `IsGRPC` field to `PushNotification` struct
- Add logic to handle sound configuration for gRPC notifications in `GetAndroidNotification`
- Set `IsGRPC` to `true` in the `Send` function of the `Server` struct

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy authored Jul 16, 2024
1 parent 1f48853 commit cc8b9e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions notify/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type PushNotification struct {

// ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24
InterruptionLevel string `json:"interruption_level,omitempty"`
IsGRPC bool `json:"is_grpc,omitempty"`
}

// Bytes for queue message
Expand Down
16 changes: 16 additions & 0 deletions notify/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
}
}

// Check if the notification has a sound
if req.Sound != "" && req.IsGRPC {
req.APNS = &messaging.APNSConfig{
Payload: &messaging.APNSPayload{
Aps: &messaging.Aps{
Sound: req.Sound.(string),
},
},
}
req.Android = &messaging.AndroidConfig{
Notification: &messaging.AndroidNotification{
Sound: req.Sound.(string),
},
}
}

// Check if the notification is a topic
if req.IsTopic() {
message := &messaging.Message{
Expand Down
1 change: 1 addition & 0 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
Priority: strings.ToLower(in.GetPriority().String()),
PushType: in.PushType,
Development: in.Development,
IsGRPC: true,
}

if badge > 0 {
Expand Down

0 comments on commit cc8b9e4

Please sign in to comment.