notify

package
v1.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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{}
)
View Source
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.

View Source
var Run = func(msg queue.QueuedMessage) error {
	SendNotification(msg)
	return nil
}

Run send notification

Functions

func CheckMessage

func CheckMessage(req PushNotification) error

CheckMessage for check request message

func CheckPushConf

func CheckPushConf(cfg config.ConfYaml) error

CheckPushConf provide check your yml config.

func DispatchFeedback

func DispatchFeedback(log logx.LogPushEntry, url string, timeout int64) error

DispatchFeedback sends a feedback to the configured gateway.

func GetAndroidNotification

func GetAndroidNotification(req PushNotification) *fcm.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 GetPushClient

func GetPushClient(conf *c.Config) (*client.HMSClient, error)

GetPushClient use for create HMS Push

func InitAPNSClient

func InitAPNSClient(cfg config.ConfYaml, key_path string, key_base64 string, key_type string, password string, key_id string, team_id string) (*apns2.Client, error)

InitAPNSClient use for initialize APNs Client.

func InitFCMClient

func InitFCMClient(cfg config.ConfYaml, key string) (*fcm.Client, error)

InitFCMClient use for initialize FCM Client.

func InitHMSClient

func InitHMSClient(cfg config.ConfYaml, appSecret, appID string) (*client.HMSClient, error)

InitHMSClient use for initialize HMS Client.

func PushToAndroid

func PushToAndroid(req PushNotification)

PushToAndroid provide send notification to Android server.

func PushToHuawei

func PushToHuawei(req PushNotification) bool

PushToHuawei provide send notification to Android server.

func PushToIOS

func PushToIOS(req PushNotification)

PushToIOS provide send notification to APNs server.

func SendNotification

func SendNotification(req queue.QueuedMessage)

SendNotification send notification

func SetProxy

func SetProxy(proxy string) error

SetProxy only working for FCM server.

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 D

type D map[string]interface{}

D provide string array

type PushNotification

type PushNotification struct {
	Wg  *sync.WaitGroup
	Log *[]logx.LogPushEntry
	Cfg config.ConfYaml

	// Common
	ID               string      `json:"notif_id,omitempty"`
	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
	APIKey                string            `json:"api_key,omitempty"`
	To                    string            `json:"to,omitempty"`
	CollapseKey           string            `json:"collapse_key,omitempty"`
	DelayWhileIdle        bool              `json:"delay_while_idle,omitempty"`
	TimeToLive            *uint             `json:"time_to_live,omitempty"`
	RestrictedPackageName string            `json:"restricted_package_name,omitempty"`
	DryRun                bool              `json:"dry_run,omitempty"`
	Condition             string            `json:"condition,omitempty"`
	Notification          *fcm.Notification `json:"notification,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"`
	Topic         string   `json:"topic,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"`
	Apns          D        `json:"apns,omitempty"`
	ApnsKeyPath   string   `json:"apns_key_path,omitempty"`
	ApnsKeyBase64 string   `json:"apns_key_base64,omitempty"`
	ApnsKeyType   string   `json:"apns_key_type,omitempty"`
	ApnsPassword  string   `json:"apns_password,omitempty"`
	ApnsKeyID     string   `json:"apns_key_id,omitempty"`
	ApnsTeamID    string   `json:"apns_team_id,omitempty"`
}

PushNotification is single notification request

func (*PushNotification) AddLog

func (p *PushNotification) AddLog(log logx.LogPushEntry)

AddLog record fail log of notification

func (*PushNotification) AddWaitCount

func (p *PushNotification) AddWaitCount()

AddWaitCount increments the WaitGroup counter.

func (*PushNotification) Bytes

func (p *PushNotification) Bytes() []byte

Bytes for queue message

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) WaitDone

func (p *PushNotification) WaitDone()

WaitDone decrements the WaitGroup counter.

type RequestPush

type RequestPush struct {
	Notifications []PushNotification `json:"notifications" binding:"required"`
}

RequestPush support multiple notification request.

type Sound

type Sound struct {
	Critical int     `json:"critical,omitempty"`
	Name     string  `json:"name,omitempty"`
	Volume   float32 `json:"volume,omitempty"`
}

Sound sets the aps sound on the payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL