package module
Version: v0.1.3 Latest Latest

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 7 Imported by: 0



Golang Urban Airship SDK




View Source
const (
	// BaseURL is the base of the API endpoints
	BaseURL = ""
	// AcceptHeader is the value to send in the Accept header as required by docs.
	AcceptHeader = "application/vnd.urbanairship+json; version=3;"
View Source
const (
	// EndpointPushToTemplate is the path of the "/api/templates/push" POST endpoint.
	EndpointPushToTemplate = "/api/templates/push"
	// EndpointSendPush is the path of the "Send a Push" POST endpoint.
	EndpointSendPush = "/api/push"
	// EndpointCreateAndSend is the path of the "Create and Send" POST endpoint.
	EndpointCreateAndSend = "/api/create-and-send"
View Source
const (
	ActionTypeDeepLink = "deep_link"
	ActionTypeOpenURL  = "url"

Action types fro the Action.Type field


This section is empty.


func PushToTemplate

func PushToTemplate(templateID string, channels []string, substitutions map[string]string)

PushToTemplate invokes the Airship "Push to Template" API

func SendPush

func SendPush(templateID string, channels []string, substitutions map[string]string)

SendPush invokes the Airship "Send a Push" API


type Actions

type Actions struct {
	AddTag    []string      `json:"add_tag,omitempty"`
	RemoveTag []string      `json:"remove_tag,omitempty"`
	Share     string        `json:"string,omitempty"`
	Open      *uaOpenAction `json:"open,omitempty"`

Actions "Actions": Describes Actions to be performed by the SDK when a user interacts with the notification.

type AndroidOverrideWithTemplate

type AndroidOverrideWithTemplate struct {
	Template    *TemplateRef      `json:"template,omitempty"`
	Actions     *Actions          `json:"actions,omitempty"`
	Extra       map[string]string `json:"extra,omitempty"`
	Sound       string            `json:"sound,omitempty"`
	CollapseKey string            `json:"collapse_key,omitempty"`
	Category    string            `json:"category,omitempty"`
	Title       string            `json:"title,omitempty"`


type AudienceSelector

type AudienceSelector struct {
	Channels   []string `json:"channel,omitempty"`
	NamedUsers []string `json:"named_user,omitempty"`

AudienceSelector Atomic Selector variant:

type Client

type Client interface {
	InvokeEndpoint(method string, endpoint string, body interface{}) error

Client is the API for interacting with Urban Airship

func New

func New(options ...ClientOption) Client

New creates a new client instance configured with the given options. For example:

conn := airship.New(WithBasicAuth("app-key", "master-secret"))

type ClientOption

type ClientOption func(c *uaHTTPClient)

ClientOption are configuration functions that can be passed to New to configure the client.

func WithBasicAuth

func WithBasicAuth(appKey, masterSecret string) ClientOption

WithBasicAuth configures the Airship Client to use HTTP Basic Auth

func WithBearerAuth

func WithBearerAuth(token string) ClientOption

WithBearerAuth configures the Airship Client to use Bearer Auth

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient overrides the http.Client instance used by the Airship Client. This is useful for unit tests of the client itself, but not much else.

type CreateAndSend

type CreateAndSend struct {
	Audience     createAndSendAudience `json:"audience"`
	Notification NotificationObject    `json:"notification"`
	DeviceTypes  []string              `json:"device_types"`

CreateAndSend is a create-and-send request body for Urban Airship for the SMS varient

func MakeCreateAndSendSMSPayload

func MakeCreateAndSendSMSPayload(templateID string, subs map[string]string, shortenLinks bool, targets []CreateAndSendSMSTarget) (*CreateAndSend, error)

MakeCreateAndSendSMSPayload creates a new create-and-send template payload to send an SMS message to the recipients using a message template already configured in Airship.

type CreateAndSendSMSTarget

type CreateAndSendSMSTarget struct {
	MSISDN  string    `json:"ua_msisdn"`   // The phone number of a mobile device.
	OptedIn time.Time `json:"ua_opted_in"` // The date/time when the user (msisdn) opted in to messages from the sender
	Sender  string    `json:"ua_sender"`   // The long or short code your SMS messages are sent from.

CreateAndSendSMSTarget defines an audience target for where to send an SMS message

type IOSOverrideWithTemplate

type IOSOverrideWithTemplate struct {
	Template   *TemplateRef      `json:"template,omitempty"`
	Actions    *Actions          `json:"actions,omitempty"`
	Extra      map[string]string `json:"extra,omitempty"`
	Sound      string            `json:"sound,omitempty"`
	Badge      int32             `json:"badge,omitempty"`
	CollapseID string            `json:"collapse_id,omitempty"`
	Category   string            `json:"category,omitempty"`
	Title      string            `json:"title,omitempty"`


type MergeData

type MergeData struct {
	Substitutions map[string]string `json:"substitutions,omitempty"`
	TemplateID    string            `json:"template_id" validate:"required"`

MergeData is the merge_data field of a Push Template Payload

type NotificationObject

type NotificationObject struct {
	Alert   string                       `json:"alert,omitempty"`
	Actions *Actions                     `json:"actions,omitempty"`
	Android *AndroidOverrideWithTemplate `json:"android,omitempty"`
	IOS     *IOSOverrideWithTemplate     `json:"ios,omitempty"`
	Sms     *SMSOverrideWithTemplate     `json:"sms,omitempty"`


type PushNotificationOption

type PushNotificationOption = func(notif *NotificationObject)

PushNotificationOption is a mutator-function based option for sending a push notification.

func WithDeepLinkAction

func WithDeepLinkAction(deepURL, fallbackURL string) PushNotificationOption

WithDeepLinkAction adds an Open Deep Link action to the notification.

func WithExtra

func WithExtra(extra map[string]string) PushNotificationOption

WithExtra adds "extra" data to IOS & Android notification overrides.

func WithOpenURLAction

func WithOpenURLAction(url string) PushNotificationOption

WithOpenURLAction adds an Open URL action to the notification.

func WithShortenLinks(value bool) PushNotificationOption

WithShortenLinks sets the ShortenLinks value on the SMS notification overrides.

type PushObject

type PushObject struct {
	Audience         AudienceSelector   `json:"audience" validate:"required"`
	DeviceTypes      interface{}        `json:"device_types" validate:"required"` // "all" or slice of "ios", "android", etc
	GlobalAttributes map[string]string  `json:"global_attributes,omitempty"`      // will be added to the global attributes rendering namespace for this push.
	Notification     NotificationObject `json:"notification"`                     // Probably yes required unless either message or in_app is present.



func MakeSendPushPayload

func MakeSendPushPayload(templateID string, channels []string, substitutions map[string]string, options ...PushNotificationOption) PushObject

MakeSendPushPayload creates a new push template payload

type PushTemplatePayload

type PushTemplatePayload struct {
	Audience    AudienceSelector `json:"audience" validate:"required"`
	DeviceTypes []string         `json:"device_types" validate:"required"` // "ios" and/or "android"
	MergeData   MergeData        `json:"merge_data" validate:"required"`


func MakePushTemplatePayload

func MakePushTemplatePayload(templateID string, channels []string, substitutions map[string]string) PushTemplatePayload

MakePushTemplatePayload creates a new push template payload

type SMSOverrideWithTemplate

type SMSOverrideWithTemplate struct {
	Template     *TemplateRef `json:"template,omitempty"`
	ShortenLinks bool         `json:"shorten_links,omitempty"`

SMSOverrideWithTemplate specifies an SMS message template to send.

type TemplateFields

type TemplateFields struct {
	Alert     string `json:"alert,omitempty"`
	Icon      string `json:"icon,omitempty"`
	IconColor string `json:"icon_color,omitempty"`
	Summary   string `json:"summary,omitempty"`
	Title     string `json:"title,omitempty"`

TemplateFields allows specifying the template directly in the API call. Items in the field object are personalizable with handlebars.

type TemplateRef

type TemplateRef struct {
	TemplateID string          `json:"template_id,omitempty" validate:"excluded_with=Fields"`
	Fields     *TemplateFields `json:"fields,omitempty" validate:"excluded_with=TemplateID"`

TemplateRef just holds a template ID under a key. One and only one of TemplateID and Fields may be populated


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL