diff --git a/gorush/notification.go b/gorush/notification.go index 3f77a99..c7d068e 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -70,15 +70,15 @@ type PushNotification struct { Retry int `json:"retry,omitempty"` // Android - APIKey string `json:"api_key,omitempty"` - To string `json:"to,omitempty"` - CollapseKey string `json:"collapse_key,omitempty"` - DelayWhileIdle bool `json:"delay_while_idle,omitempty"` - TimeToLive *uint `json:"time_to_live,omitempty"` - RestrictedPackageName string `json:"restricted_package_name,omitempty"` - DryRun bool `json:"dry_run,omitempty"` - Condition string `json:"condition,omitempty"` - Notification fcm.Notification `json:"notification,omitempty"` + APIKey string `json:"api_key,omitempty"` + To string `json:"to,omitempty"` + CollapseKey string `json:"collapse_key,omitempty"` + DelayWhileIdle bool `json:"delay_while_idle,omitempty"` + TimeToLive *uint `json:"time_to_live,omitempty"` + RestrictedPackageName string `json:"restricted_package_name,omitempty"` + DryRun bool `json:"dry_run,omitempty"` + Condition string `json:"condition,omitempty"` + Notification *fcm.Notification `json:"notification,omitempty"` // iOS Expiration *int64 `json:"expiration,omitempty"` diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index 6f48c65..d6202e6 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -60,19 +60,21 @@ func GetAndroidNotification(req PushNotification) *fcm.Message { } } - notification.Notification = &req.Notification + notification.Notification = req.Notification - // Set request message if body is empty - if len(req.Message) > 0 { - notification.Notification.Body = req.Message - } + if req.Notification != nil { + // Set request message if body is empty + if len(req.Message) > 0 { + notification.Notification.Body = req.Message + } - if len(req.Title) > 0 { - notification.Notification.Title = req.Title - } + if len(req.Title) > 0 { + notification.Notification.Title = req.Title + } - if v, ok := req.Sound.(string); ok && len(v) > 0 { - notification.Notification.Sound = v + if v, ok := req.Sound.(string); ok && len(v) > 0 { + notification.Notification.Sound = v + } } return notification diff --git a/gorush/notification_fcm_test.go b/gorush/notification_fcm_test.go index 60c4aad..b999625 100644 --- a/gorush/notification_fcm_test.go +++ b/gorush/notification_fcm_test.go @@ -235,9 +235,10 @@ func TestAndroidNotificationStructure(t *testing.T) { "a": "1", "b": 2, }, - Notification: fcm.Notification{ + Notification: &fcm.Notification{ Color: test, Tag: test, + Body: "", }, } @@ -263,6 +264,9 @@ func TestAndroidNotificationStructure(t *testing.T) { req = PushNotification{ Tokens: []string{"a", "b"}, To: test, + Notification: &fcm.Notification{ + Body: "", + }, } notification = GetAndroidNotification(req)