Documentation ¶
Overview ¶
Package expo is used to send push notifications to Expo Experiences from a Go server
A simplest example:
package main import "github.com/Terminux/exponent-server-sdk-go" const token = "EXPO_TOKEN" func main() { if expo.IsExpoPushToken(token) { message := expo.PushMessage{ To: token, Title: "Notification title", Body: "Notification content", Sound: "default", Badge: 1 Data: struct{ Value string }{"mydata"}}} message.Send() } }
Index ¶
- Variables
- func ChunkPushNotifications(messages []*PushMessage) [][]*PushMessage
- func IsExpoPushToken(token string) bool
- func SendPushNotification(message *PushMessage) (*PushNotificationResult, *PushNotificationError, error)
- func SendPushNotifications(messages []*PushMessage) (r []*PushNotificationResult, e []*PushNotificationError, err error)
- type PushMessage
- type PushNotificationError
- type PushNotificationResult
Constants ¶
This section is empty.
Variables ¶
var ChunkLimit = 100
ChunkLimit allows to set the max message in each chunk. This variable is used on ChunkPushNotifications function. The ChunkLimit can be increase or decrease but it is not recommanded to set higher than 100
var MaxBodySizeWithoutGzip = 1024
MaxBodySizeWithoutGzip allows to set the max length of body allowed to be send without gzip. The MaxBodySizeWithoutGzip can be increase or decrease but it is not recommanded to set higher than 1024
Functions ¶
func ChunkPushNotifications ¶
func ChunkPushNotifications(messages []*PushMessage) [][]*PushMessage
ChunkPushNotifications returns an array of chunks The chunks size is determined with the ChunkLimit variable
func IsExpoPushToken ¶
IsExpoPushToken determines if the token is a Expo push token
func SendPushNotification ¶
func SendPushNotification(message *PushMessage) (*PushNotificationResult, *PushNotificationError, error)
SendPushNotification allows to send the message
func SendPushNotifications ¶
func SendPushNotifications(messages []*PushMessage) (r []*PushNotificationResult, e []*PushNotificationError, err error)
SendPushNotifications allows to send several messages at the same times Is highly recommanded to not send more than 100 messages at once
Types ¶
type PushMessage ¶
type PushMessage struct { // To is an Expo push token specifying the recipient of this message. To string `json:"to"` // Title is the title to display in the notification. On iOS this is displayed only on Apple Watch. Title string `json:"title,omitempty"` // Body is the push notification content Body string `json:"body,omitempty"` // Data is a JSON object delivered to your app. It may be up to about 4KiB; the total // notification payload sent to Apple and Google must be at most 4KiB or else you will get a "Message Too Big" error. Data interface{} `json:"data,omitempty"` // Sound to play when the recipient receives this notification. // Specify "default" to play the device's default notification sound, or omit this field to play no sound. Sound string `json:"sound,omitempty"` // TTL (Time to Live) is the number of seconds for which the message may be kept around for redelivery if it hasn't been delivered yet. TTL int `json:"ttl"` // Expiration is a timestamp since the UNIX epoch specifying when the message expires. Expiration int `json:"expiration"` // Priority is the delivery priority of the message. // Possible values: normal | hight | default or omit field to use the default priority Priority string `json:"priority,omitempty"` // Badge is the number to display in the badge on the app icon Badge int `json:"badge"` }
PushMessage is the message sended to the Expo api
func (*PushMessage) Send ¶
func (p *PushMessage) Send() (r *PushNotificationResult, e *PushNotificationError, err error)
Send allows to send the current message
type PushNotificationError ¶
type PushNotificationError struct { Code string `json:"code"` Message string `json:"message"` Details string `json:"details"` Stack string `json:"stack"` }
PushNotificationError is the result error returned by the Expo api
type PushNotificationResult ¶
type PushNotificationResult struct { Status string `json:"status"` Message string `json:"message"` Details struct { Error string `json:"error"` } `json:"details"` }
PushNotificationResult is the result returned by the Expo api