Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMessage(req *PushNotification) error
- func CheckPushConf(cfg *config.ConfYaml) error
- func DispatchFeedback(ctx context.Context, log logx.LogPushEntry, url string, timeout int64, ...) error
- func GetAndroidNotification(req *PushNotification) []*messaging.Message
- func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
- func GetIOSNotification(req *PushNotification) *apns2.Notification
- func GetPushClient(conf *c.Config) (*client.HMSClient, error)
- func InitAPNSClient(ctx context.Context, cfg *config.ConfYaml) error
- func InitFCMClient(ctx context.Context, cfg *config.ConfYaml) (*fcm.Client, error)
- func InitHMSClient(cfg *config.ConfYaml, appSecret, appID string) (*client.HMSClient, error)
- func SetProxy(proxy string) error
- type Alert
- type D
- type PushNotification
- type RequestPush
- type ResponsePush
- func PushToAndroid(ctx context.Context, req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error)
- func PushToHuawei(ctx context.Context, req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error)
- func PushToIOS(ctx context.Context, req *PushNotification, cfg *config.ConfYaml) (resp *ResponsePush, err error)
- func SendNotification(ctx context.Context, req qcore.TaskMessage, cfg *config.ConfYaml) (resp *ResponsePush, err error)
- type Sound
Constants ¶
const ( HIGH = "high" NORMAL = "nornal" )
const ( // ApnsPriorityLow will tell APNs to send the push message at a time that takes // into account power considerations for the device. Notifications with this // priority might be grouped and delivered in bursts. They are throttled, and // in some cases are not delivered. ApnsPriorityLow = 5 // ApnsPriorityHigh will tell APNs to send the push message immediately. // Notifications with this priority must trigger an alert, sound, or badge on // the target device. It is an error to use this priority for a push // notification that contains only the content-available key. ApnsPriorityHigh = 10 )
Variables ¶
var ( // ApnsClient is apns client ApnsClient *apns2.Client // FCMClient is apns client FCMClient *fcm.Client // HMSClient is Huawei push client HMSClient *core.HMSClient // MaxConcurrentIOSPushes pool to limit the number of concurrent iOS pushes MaxConcurrentIOSPushes chan struct{} )
var DialTLS = func(cfg *tls.Config) func(network, addr string) (net.Conn, error) { return func(network, addr string) (net.Conn, error) { dialer := &net.Dialer{ Timeout: tlsDialTimeout, KeepAlive: tcpKeepAlive, } return tls.DialWithDialer(dialer, network, addr, cfg) } }
DialTLS is the default dial function for creating TLS connections for non-proxied HTTPS requests.
var Run = func(cfg *config.ConfYaml) func(ctx context.Context, msg qcore.TaskMessage) error { return func(ctx context.Context, msg qcore.TaskMessage) error { _, err := SendNotification(ctx, msg, cfg) return err } }
Run send notification
Functions ¶
func CheckMessage ¶
func CheckMessage(req *PushNotification) error
CheckMessage for check request message
func CheckPushConf ¶
CheckPushConf provide check your yml config.
func DispatchFeedback ¶
func DispatchFeedback( ctx context.Context, log logx.LogPushEntry, url string, timeout int64, header []string, ) error
DispatchFeedback sends a feedback log entry to a specified URL via an HTTP POST request.
Parameters:
- ctx: The context for the HTTP request.
- log: The log entry to be sent as feedback.
- url: The destination URL for the feedback.
- timeout: The timeout duration for the HTTP request in seconds.
- header: A slice of strings representing additional headers to be included in the request.
Returns:
- error: An error if the request fails or the response status is not OK.
func GetAndroidNotification ¶
func GetAndroidNotification(req *PushNotification) []*messaging.Message
GetAndroidNotification use for define Android notification. HTTP Connection Server Reference for Android https://firebase.google.com/docs/cloud-messaging/http-server-ref
func GetHuaweiNotification ¶
func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error)
GetHuaweiNotification use for define HMS notification. HTTP Connection Server Reference for HMS https://developer.huawei.com/consumer/en/doc/development/HMS-References/push-sendapi
func GetIOSNotification ¶
func GetIOSNotification(req *PushNotification) *apns2.Notification
GetIOSNotification use for define iOS notification. The iOS Notification Payload (Payload Key Reference) Ref: https://apple.co/2VtH6Iu
func GetPushClient ¶
GetPushClient use for create HMS Push.
func InitAPNSClient ¶
InitAPNSClient use for initialize APNs Client.
func InitFCMClient ¶
InitFCMClient use for initialize FCM Client.
func InitHMSClient ¶
InitHMSClient use for initialize HMS Client.
Types ¶
type Alert ¶
type Alert struct {
Action string `json:"action,omitempty"`
ActionLocKey string `json:"action-loc-key,omitempty"`
Body string `json:"body,omitempty"`
LaunchImage string `json:"launch-image,omitempty"`
LocArgs []string `json:"loc-args,omitempty"`
LocKey string `json:"loc-key,omitempty"`
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
SummaryArg string `json:"summary-arg,omitempty"`
SummaryArgCount int `json:"summary-arg-count,omitempty"`
}
Alert is APNs payload
type PushNotification ¶
type PushNotification struct {
// Common
ID string `json:"notif_id,omitempty"`
To string `json:"to,omitempty"`
Topic string `json:"topic,omitempty"` // FCM and iOS only
Tokens []string `json:"tokens" binding:"required"`
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"`
Sound interface{} `json:"sound,omitempty"`
Data D `json:"data,omitempty"`
Retry int `json:"retry,omitempty"`
// Android
Notification *messaging.Notification `json:"notification,omitempty"`
Android *messaging.AndroidConfig `json:"android,omitempty"`
Webpush *messaging.WebpushConfig `json:"webpush,omitempty"`
APNS *messaging.APNSConfig `json:"apns,omitempty"`
FCMOptions *messaging.FCMOptions `json:"fcm_options,omitempty"`
Condition string `json:"condition,omitempty"`
// Huawei
AppID string `json:"app_id,omitempty"`
AppSecret string `json:"app_secret,omitempty"`
HuaweiNotification *model.AndroidNotification `json:"huawei_notification,omitempty"`
HuaweiData string `json:"huawei_data,omitempty"`
HuaweiCollapseKey int `json:"huawei_collapse_key,omitempty"`
HuaweiTTL string `json:"huawei_ttl,omitempty"`
BiTag string `json:"bi_tag,omitempty"`
FastAppTarget int `json:"fast_app_target,omitempty"`
// iOS
Expiration *int64 `json:"expiration,omitempty"`
ApnsID string `json:"apns_id,omitempty"`
CollapseID string `json:"collapse_id,omitempty"`
PushType string `json:"push_type,omitempty"`
Badge *int `json:"badge,omitempty"`
Category string `json:"category,omitempty"`
ThreadID string `json:"thread-id,omitempty"`
URLArgs []string `json:"url-args,omitempty"`
Alert Alert `json:"alert,omitempty"`
Production bool `json:"production,omitempty"`
Development bool `json:"development,omitempty"`
SoundName string `json:"name,omitempty"`
SoundVolume float32 `json:"volume,omitempty"`
// ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24
InterruptionLevel string `json:"interruption_level,omitempty"`
// live-activity support
// ref: https://apple.co/3MLe2DB
ContentState D `json:"content-state,omitempty"`
StaleDate int64 `json:"stale-date,omitempty"`
DismissalDate int64 `json:"dismissal-date"`
Event string `json:"event,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
}
PushNotification is single notification request
func (*PushNotification) IsTopic ¶
func (p *PushNotification) IsTopic() bool
IsTopic check if message format is topic for FCM ref: https://firebase.google.com/docs/cloud-messaging/send-message#topic-http-post-request
func (*PushNotification) Payload ¶ added in v1.19.0
func (p *PushNotification) Payload() []byte
Payload for queue message
type RequestPush ¶
type RequestPush struct {
Notifications []PushNotification `json:"notifications" binding:"required"`
}
RequestPush support multiple notification request.
type ResponsePush ¶
type ResponsePush struct {
Logs []logx.LogPushEntry `json:"logs"`
}
ResponsePush response of notification request.
func PushToAndroid ¶
func PushToAndroid( ctx context.Context, req *PushNotification, cfg *config.ConfYaml, ) (resp *ResponsePush, err error)
PushToAndroid provide send notification to Android server.
func PushToHuawei ¶
func PushToHuawei( ctx context.Context, req *PushNotification, cfg *config.ConfYaml, ) (resp *ResponsePush, err error)
PushToHuawei provide send notification to Android server.
func PushToIOS ¶
func PushToIOS( ctx context.Context, req *PushNotification, cfg *config.ConfYaml, ) (resp *ResponsePush, err error)
PushToIOS provide send notification to APNs server.
func SendNotification ¶
func SendNotification( ctx context.Context, req qcore.TaskMessage, cfg *config.ConfYaml, ) (resp *ResponsePush, err error)
SendNotification provide send notification.