diff --git a/README.md b/README.md index 75326bd..fae5871 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,10 @@ Multiple registration ids can be listed in the same command "registration_ids" : string -- one or more registration ids separated by commas }, "message" : { - "event" : string, - "data" : object, - "time" : int + "event" : string, + "data" : object, + "notification": object, + "time" : int } } ``` diff --git a/message.go b/message.go index df5cbfd..e8e68de 100644 --- a/message.go +++ b/message.go @@ -18,9 +18,10 @@ type CommandMsg struct { } type Message struct { - Event string `json:"event"` - Data map[string]interface{} `json:"data"` - Time int64 `json:"time"` + Event string `json:"event"` + Data map[string]interface{} `json:"data"` + Notification map[string]interface{} `json:"notification"` + Time int64 `json:"time"` } func (this *CommandMsg) FromSocket(sock *Socket) { @@ -163,12 +164,13 @@ func (this *CommandMsg) FromRedis(server *Server) { func (this *CommandMsg) formatMessage() (*Message, error) { event, e_ok := this.Message["event"].(string) data, b_ok := this.Message["data"].(map[string]interface{}) + notification, c_ok := this.Message["notification"].(map[string]interface{}) - if !b_ok || !e_ok { + if !b_ok || !e_ok { // notification is optional return nil, errors.New("Could not format message") } - msg := &Message{event, data, time.Now().UTC().Unix()} + msg := &Message{event, data, notification, time.Now().UTC().Unix()} return msg, nil } @@ -249,7 +251,7 @@ func (this *CommandMsg) pushAndroid(server *Server) { data := map[string]interface{}{"event": msg.Event, "data": msg.Data, "time": msg.Time} regIDs := strings.Split(registration_ids, ",") - gcmMessage := gcm.NewMessage(data, regIDs...) + gcmMessage := gcm.NewMessage(data, regIDs..., msg.Notification) sender := server.GetGCMClient() diff --git a/message_test.go b/message_test.go index 4942e5b..35415dc 100644 --- a/message_test.go +++ b/message_test.go @@ -78,6 +78,10 @@ func TestGCM(t *testing.T) { "data": { "foobar": "foo" }, + "notification" : { + "title": "Notification Title", + "body": "Notification Body" + }, "time": 1234 } }`), &msg)