Urbanairship Push Notification Library using golang ( Go )
- 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
go get github.com/heaptracetechnology/go-urbanairship
https://docs.urbanairship.com/tutorials/getting-started/1st-flight-app/
Create project in urbanairship:
- Login with https://go.urbanairship.com
- Select New project
- Create project with all details
App key and Master Secret key can be found in:
- Urbanairship project settings
- APIs and Integrations
- Copy the app key and click on textbox below master secret key to revel master key
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)
}
}
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)
}
}
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)
}
}