Added mutable_content option for Firebase (#364)

It is now possible to send `mutable_content` option to Firebase which gets forwarded as `mutable-content` option for APNS.

A link to official documentation is: https://firebase.google.com/docs/cloud-messaging/http-server-ref#mutable_content
This commit is contained in:
Eduard Pelesh 2018-08-15 06:47:15 +03:00 committed by Bo-Yi Wu
parent 437092c697
commit bf97ca59ec
7 changed files with 25 additions and 24 deletions

View File

@ -486,7 +486,7 @@ Request body must has a notifications array. The following is a parameter table
| badge | int | badge count | - | only iOS | | badge | int | badge count | - | only iOS |
| category | string | the UIMutableUserNotificationCategory object | - | only iOS | | category | string | the UIMutableUserNotificationCategory object | - | only iOS |
| alert | string array | payload of a iOS message | - | only iOS. See the [detail](#ios-alert-payload) | | alert | string array | payload of a iOS message | - | only iOS. See the [detail](#ios-alert-payload) |
| mutable-content | bool | enable Notification Service app extension. | - | only iOS(10.0+). | | mutable_content | bool | enable Notification Service app extension. | - | only iOS(10.0+). |
### iOS alert payload ### iOS alert payload
| name | type | description | required | note | | name | type | description | required | note |

View File

@ -56,6 +56,7 @@ type PushNotification struct {
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
Priority string `json:"priority,omitempty"` Priority string `json:"priority,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"` ContentAvailable bool `json:"content_available,omitempty"`
MutableContent bool `json:"mutable_content,omitempty"`
Sound string `json:"sound,omitempty"` Sound string `json:"sound,omitempty"`
Data D `json:"data,omitempty"` Data D `json:"data,omitempty"`
Retry int `json:"retry,omitempty"` Retry int `json:"retry,omitempty"`
@ -74,18 +75,17 @@ type PushNotification struct {
Notification fcm.Notification `json:"notification,omitempty"` Notification fcm.Notification `json:"notification,omitempty"`
// iOS // iOS
Expiration int64 `json:"expiration,omitempty"` Expiration int64 `json:"expiration,omitempty"`
ApnsID string `json:"apns_id,omitempty"` ApnsID string `json:"apns_id,omitempty"`
CollapseID string `json:"collapse_id,omitempty"` CollapseID string `json:"collapse_id,omitempty"`
Topic string `json:"topic,omitempty"` Topic string `json:"topic,omitempty"`
Badge *int `json:"badge,omitempty"` Badge *int `json:"badge,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
ThreadID string `json:"thread-id,omitempty"` ThreadID string `json:"thread-id,omitempty"`
URLArgs []string `json:"url-args,omitempty"` URLArgs []string `json:"url-args,omitempty"`
Alert Alert `json:"alert,omitempty"` Alert Alert `json:"alert,omitempty"`
MutableContent bool `json:"mutable-content,omitempty"` Production bool `json:"production,omitempty"`
Production bool `json:"production,omitempty"` Development bool `json:"development,omitempty"`
Development bool `json:"development,omitempty"`
} }
// WaitDone decrements the WaitGroup counter. // WaitDone decrements the WaitGroup counter.

View File

@ -36,6 +36,7 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
Condition: req.Condition, Condition: req.Condition,
CollapseKey: req.CollapseKey, CollapseKey: req.CollapseKey,
ContentAvailable: req.ContentAvailable, ContentAvailable: req.ContentAvailable,
MutableContent: req.MutableContent,
DelayWhileIdle: req.DelayWhileIdle, DelayWhileIdle: req.DelayWhileIdle,
TimeToLive: req.TimeToLive, TimeToLive: req.TimeToLive,
RestrictedPackageName: req.RestrictedPackageName, RestrictedPackageName: req.RestrictedPackageName,

View File

@ -231,7 +231,7 @@ func TestMutableContent(t *testing.T) {
"tokens": []string{"aaaaa", "bbbbb"}, "tokens": []string{"aaaaa", "bbbbb"},
"platform": PlatFormAndroid, "platform": PlatFormAndroid,
"message": "Welcome", "message": "Welcome",
"mutable-content": 1, "mutable_content": 1,
"topic": "test", "topic": "test",
"badge": 1, "badge": 1,
"alert": gofight.D{ "alert": gofight.D{
@ -242,7 +242,7 @@ func TestMutableContent(t *testing.T) {
}, },
}). }).
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
// json: cannot unmarshal number into Go struct field PushNotification.mutable-content of type bool // json: cannot unmarshal number into Go struct field PushNotification.mutable_content of type bool
assert.Equal(t, http.StatusBadRequest, r.Code) assert.Equal(t, http.StatusBadRequest, r.Code)
}) })
} }

View File

@ -1,10 +1,10 @@
# go-fcm # go-fcm
[![GoDoc](https://godoc.org/github.com/appleboy/go-fcm?status.svg)](https://godoc.org/github.com/edganiukov/fcm) [![GoDoc](https://godoc.org/github.com/appleboy/go-fcm?status.svg)](https://godoc.org/github.com/appleboy/go-fcm)
[![Build Status](https://travis-ci.org/appleboy/go-fcm.svg?branch=master)](https://travis-ci.org/edganiukov/fcm) [![Build Status](https://travis-ci.org/appleboy/go-fcm.svg?branch=master)](https://travis-ci.org/appleboy/go-fcm)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/go-fcm)](https://goreportcard.com/report/github.com/edganiukov/fcm) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/go-fcm)](https://goreportcard.com/report/github.com/appleboy/go-fcmm)
This project was forked from [github.com/edganiukov/fcmfcm](https://github.com/edganiukov/fcm). This project was forked from [github.com/edganiukov/fcm](https://github.com/edganiukov/fcm).
Golang client library for Firebase Cloud Messaging. Implemented only [HTTP client](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream). Golang client library for Firebase Cloud Messaging. Implemented only [HTTP client](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream).

View File

@ -24,6 +24,7 @@ var (
type Notification struct { type Notification struct {
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"` Body string `json:"body,omitempty"`
ChannelId string `json:"android_channel_id, omitempty"`
Icon string `json:"icon,omitempty"` Icon string `json:"icon,omitempty"`
Sound string `json:"sound,omitempty"` Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"` Badge string `json:"badge,omitempty"`
@ -45,6 +46,7 @@ type Message struct {
CollapseKey string `json:"collapse_key,omitempty"` CollapseKey string `json:"collapse_key,omitempty"`
Priority string `json:"priority,omitempty"` Priority string `json:"priority,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"` ContentAvailable bool `json:"content_available,omitempty"`
MutableContent bool `json:"mutable_content,omitempty"`
DelayWhileIdle bool `json:"delay_while_idle,omitempty"` DelayWhileIdle bool `json:"delay_while_idle,omitempty"`
TimeToLive *uint `json:"time_to_live,omitempty"` TimeToLive *uint `json:"time_to_live,omitempty"`
DeliveryReceiptRequested bool `json:"delivery_receipt_requested,omitempty"` DeliveryReceiptRequested bool `json:"delivery_receipt_requested,omitempty"`

8
vendor/vendor.json vendored
View File

@ -21,12 +21,10 @@
"revisionTime": "2018-04-10T03:06:38Z" "revisionTime": "2018-04-10T03:06:38Z"
}, },
{ {
"checksumSHA1": "1Jql7x7zDOmbDxGr4gsa8rFEC5g=", "checksumSHA1": "gm1OOCOLjT16sLsu2jyvpXksx20=",
"path": "github.com/appleboy/go-fcm", "path": "github.com/appleboy/go-fcm",
"revision": "3bc382cee4180b7e4753761fda69a003de97b0e9", "revision": "834eba2ee169f0930af5b355519f22f908cf3e49",
"revisionTime": "2017-10-25T02:33:50Z", "revisionTime": "2018-08-14T17:09:15Z"
"version": "0.1.1",
"versionExact": "0.1.1"
}, },
{ {
"checksumSHA1": "Ab7MUtqX0iq2PUzzBxWpgzPSydw=", "checksumSHA1": "Ab7MUtqX0iq2PUzzBxWpgzPSydw=",