Skip to content

heaptracetechnology/go-urbanairship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-urbanairship : Urbanairship Library for Go

Urbanairship Push Notification Library using golang ( Go )

Features
  • Send push notification by tag
  • Send push notification by named user
  • Send push notification by channel ID
    • Install 1st Flight app in your device (android/ios)
    • Get channel ID from app
    • Add named user and tag in settings

Usage

go get github.com/heaptracetechnology/go-urbanairship

Urbanairship tutorials docs

https://docs.urbanairship.com/tutorials/getting-started/1st-flight-app/

Urbanairship create project

Create project in urbanairship:

  1. Login with https://go.urbanairship.com
  2. Select New project
  3. Create project with all details

Get App key and Master Secret key

App key and Master Secret key can be found in:

  1. Urbanairship project settings
  2. APIs and Integrations
  3. Copy the app key and click on textbox below master secret key to revel master key

Examples

Send push notification by Tag

package main

import (
	"fmt"
	"github.com/heaptracetechnology/go-urbanairship"
)

func main() {

	appKey := "APP_KEY"
	masterKey := "MASTER_KEY"

	var message urbanairship.UAMessage
	var audiance urbanairship.Audiance
	var notification urbanairship.Notification

	audiance.Tag = "tag-name" // from app setting
	notification.Alert = "Push notification with tag name" // alert message
	channelType := ""

	message.Audience = audiance
	message.Notification = notification
	message.DeviceTypes = []string{"android"}

	client := *urbanairship.NewUAClient(appKey, masterKey, channelType)
	client.Message = message

	response, err := client.Send()
	if err == nil {
		fmt.Println(response)
	} else {
		fmt.Println(err)
	}

}

Send push notification by Named User

package main

import (
	"fmt"
	"github.com/heaptracetechnology/go-urbanairship"
)

func main() {

	appKey := "APP_KEY"
	masterKey := "MASTER_KEY"

	var message urbanairship.UAMessage
	var audiance urbanairship.Audiance
	var notification urbanairship.Notification

	audiance.NamedUser = "named_user" // from app setting
	notification.Alert = "Push notification with named user" // alert message
	channelType := ""

	message.Audience = audiance
	message.Notification = notification
	message.DeviceTypes = []string{"android"}

	client := *urbanairship.NewUAClient(appKey, masterKey, channelType)
	client.Message = message

	response, err := client.Send()
	if err == nil {
		fmt.Println(response)
	} else {
		fmt.Println(err)
	}

}

Send push notification by Channel Id

package main

import (
	"fmt"
	"github.com/heaptracetechnology/go-urbanairship"
)

func main() {

	appKey := "APP_KEY"
	masterKey := "MASTER_KEY"

	var message urbanairship.UAMessage
	var audiance urbanairship.Audiance
	var notification urbanairship.Notification

	audiance.AndroidChannelId = "Channel_Id" // from app setting
	notification.Alert = "Push notification by channel id" // alert message
	channelType := "android" // required field ios/android 

	message.Audience = audiance
	message.Notification = notification
	message.DeviceTypes = []string{"android"}

	client := *urbanairship.NewUAClient(appKey, masterKey, channelType)
	client.Message = message
	response, err := client.Send()
	if err == nil {
		fmt.Println(response)
	} else {
		fmt.Println(err)
	}

}

About

Urbanairship Push Notification Library using golang ( Go )

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages