diff --git a/README.md b/README.md index 86a1ce5..0fe019e 100644 --- a/README.md +++ b/README.md @@ -123,12 +123,22 @@ func main() { c := fcm.NewFcmClient(serverKey) c.NewFcmMsgTo(topic, data) + notificationPayload := NotificationPayload{ + Title: "title - foo", + Body: "body - bar", + + // Set notification image. + Image: "https://example.com/img.jpg", + } + + c.SetNotificationPayload(¬ificationPayload) + status, err := c.Send() if err == nil { - status.PrintResults() + status.PrintResults() } else { fmt.Println(err) } diff --git a/fcm.go b/fcm.go index 1a0acbe..da3cfc5 100644 --- a/fcm.go +++ b/fcm.go @@ -77,6 +77,7 @@ type NotificationPayload struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` Icon string `json:"icon,omitempty"` + Image string `json:"image,omitempty"` Sound string `json:"sound,omitempty"` Badge string `json:"badge,omitempty"` Tag string `json:"tag,omitempty"` diff --git a/fcm_test.go b/fcm_test.go index 896dd26..4c2024a 100644 --- a/fcm_test.go +++ b/fcm_test.go @@ -31,6 +31,30 @@ func TestTopicHandle_1(t *testing.T) { } } +func TestImage(t *testing.T) { + + srv := httptest.NewServer(http.HandlerFunc(topicHandle)) + chgUrl(srv) + defer srv.Close() + + c := NewFcmClient("key") + + notificationPayload := NotificationPayload{ + Title: "title - foo", + Body: "body - bar", + Image: "https://example.com/img.jpg", + } + c.SetNotificationPayload(¬ificationPayload) + + res, err := c.Send() + if err != nil { + t.Error("Response Error : ", err) + } + if res == nil { + t.Error("Res is nil") + } +} + func TestTopicHandle_2(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(topicHandle))