Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 1.31 KB

README.md

File metadata and controls

61 lines (44 loc) · 1.31 KB

exponent

Send push notifications to Expo apps using Golang

revised version of: https://github.com/oliveroneill/exponent-server-sdk-golang/tree/master

Documentation

Go Reference

Installation

go get github.com/9ssi7/exponent

Usage

package main

import (
	"context"
	"time"

	"github.com/9ssi7/exponent"
)

func main() {
	c := exponent.NewClient(exponent.WithAccessToken("your-access-token"))

	tkn := exponent.MustParseToken("ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]")
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	res, err := c.PublishSingle(ctx, &exponent.Message{
		To:       []*exponent.Token{tkn},
		Body:     "This is a test notification",
		Data:     exponent.Data{"withSome": "data"},
		Sound:    "default",
		Title:    "Notification Title",
		Priority: exponent.DefaultPriority,
	})

	if err != nil {
		panic(err)
	}

	if res.IsOk() {
		println("Notification sent successfully")
	} else {
		println("Notification failed")
	}
}

Contributing

We welcome contributions! Please see our Contribution Guidelines for details.

License

This project is licensed under the Apache License. See LICENSE for more details.