Fix image fcm (#454)

* allow sending data ONLY notifications for FCM notifications

* fix tests to pass

* support image parameter used for FCM

* remove unused import

* read apns payload on fcm notifications

* update go-fcm to 0.1.5
This commit is contained in:
Sebastien Melki 2020-02-07 05:39:44 +02:00 committed by GitHub
parent c379630c29
commit 3556bfd575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

3
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/apex/gateway v1.1.1
github.com/appleboy/com v0.0.2
github.com/appleboy/gin-status-api v1.1.0
github.com/appleboy/go-fcm v0.1.4
github.com/appleboy/go-fcm v0.1.5
github.com/appleboy/gofight/v2 v2.1.2
github.com/asdine/storm v2.1.2+incompatible
github.com/aws/aws-lambda-go v1.13.3 // indirect
@ -55,4 +55,5 @@ require (
gopkg.in/go-playground/validator.v9 v9.30.2 // indirect
gopkg.in/redis.v5 v5.2.9
gopkg.in/yaml.v2 v2.2.7 // indirect
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)

View File

@ -62,6 +62,7 @@ type PushNotification struct {
Platform int `json:"platform" binding:"required"`
Message string `json:"message,omitempty"`
Title string `json:"title,omitempty"`
Image string `json:"image,omitempty"`
Priority string `json:"priority,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"`
MutableContent bool `json:"mutable_content,omitempty"`
@ -95,6 +96,7 @@ type PushNotification struct {
Development bool `json:"development,omitempty"`
SoundName string `json:"name,omitempty"`
SoundVolume float32 `json:"volume,omitempty"`
Apns D `json:"apns,omitempty"`
}
// WaitDone decrements the WaitGroup counter.

View File

@ -4,7 +4,7 @@ import (
"errors"
"fmt"
fcm "github.com/appleboy/go-fcm"
"github.com/appleboy/go-fcm"
"github.com/sirupsen/logrus"
)
@ -72,11 +72,21 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
notification.Notification.Title = req.Title
}
if len(req.Image) > 0 {
notification.Notification.Image = req.Image
}
if v, ok := req.Sound.(string); ok && len(v) > 0 {
notification.Notification.Sound = v
}
}
// handle iOS apns in fcm
if len(req.Apns) > 0 {
notification.Apns = req.Apns
}
return notification
}