notify

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 7 Imported by: 0

README

Notify Go client · CircleCI GoDoc Report card

This documentation is for developers interested in using a Go client to integrate with Notify.

Table of Contents

Installation

go get -u github.com/govau/notify-client-go

Getting started

client, err := notify.NewClient(apiKey)

Generate an API key by logging in to Notify.gov.au and going to the API integration page.

Send messages

Text message
Method
Click here to expand for more information.
resp, err := client.SendSMS(
  templateID,
  phoneNumber,
  notify.Reference("Sam's reminders"),
  notify.Personalisation{
    {"name", "Sam"},
  },
)
Response

If the request is successful, response will be a struct.

Click here to expand for more information.
{
    ID: "bfb50d92-100d-4b8b-b559-14fa3b091cda",
    Reference: "Sam's reminders",
    Content: {
        Body: "Hi Sam, just a reminder to visit the post office today.",
        FromNumber: "0400000000"
    },
    URI: "https://rest-api.notify.gov.au/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
    Template: {
        ID: "ceb50d92-100d-4b8b-b559-14fa3b091cda",
        Version: 1,
        URI: "https://rest-api.notify.gov.au/v2/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
    },
}
Arguments
Click here to expand for more information.
phoneNumber

The phone number of the recipient, only required for sms notifications.

templateID

Find by clicking API info for the template you want to send.

options
Reference

An optional identifier you generate. The Reference can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.

You can omit this argument if you do not require a reference for the notification.

Personalisation

If a template has placeholders, you need to provide their values, for example:

p := notify.Personalisation{
    {"name", "Daniel Smith"},
    {"age", "23"}
},

This does not need to be provided if your template does not contain placeholders.

SMSSenderID

Optional. Specifies the identifier of the sms sender to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Text message sender'.

If you omit this argument your default sms sender will be set for the notification.

Example usage with optional reference -

Email
Method
Click here to expand for more information.
sent, erra := client.SendEmail(
    "effc255a-d233-4f3f-949a-15915c45b6f0",
    "dan@email.com",
    notify.Personalisation{
        {"name", "Dan"},
    },
)
Response

If the request is successful, response will be a struct.

Click here to expand for more information.
{
    ID: "bfb50d92-100d-4b8b-b559-14fa3b091cda",
    Reference: "Sam's reminders",
    Content: {
        Subject: "Physio",
        Body: "Hi Sam, you have a physio appointment at 2pm.",
        FromEmail: "reminders@email.com"
    },
    URI: "https://rest-api.notify.gov.au/v2/notifications/ceb50d92-100d-4b8b-b559-14fa3b091cd",
    Template: {
        ID: "ceb50d92-100d-4b8b-b559-14fa3b091cda",
        Version: 1,
        URI: "https://rest-api.notify.gov.au/v2/templates/bfb50d92-100d-4b8b-b559-14fa3b091cda"
    },
}
Arguments
Click here to expand for more information.
emailAddress

The email address of the recipient, only required for email notifications.

templateID

Find by clicking API info for the template you want to send.

options
Reference

An optional identifier you generate. The reference can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.

You can omit this argument if you do not require a reference for the notification.

EmailReplyToID

Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.

If you omit this argument your default email reply-to address will be set for the notification.

Personalisation

If a template has placeholders, you need to provide their values, for example:

p := notify.Personalisation{
    {"name", "Daniel Smith"},
    {"age", "23"}
},

Get all templates

Method

Returns the latest version of each template

Click here to expand for more information.
templates, err := client.Templates()
Response

If the request is successful, response will be a slice of templates.

Click here to expand for more information.
[{
    ID:        "template ID",
    Name:      "template name",
    Type:      "email",
    CreatedAt: "2019-04-10T00:46:29.076570Z",
    UpdatedAt: "2019-04-10T00:46:29.076570Z",
    CreatedBy: "someone@email.com",
    Version:   1,
    Subject:   "Subject of an email or letter notification, or nil if an sms message",
    Body:      "Body of the notification",
}, {
    ...template
}]

Tests

To run the unit tests:

go test ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, options ...ClientOption) (*Client, error)

func (Client) GenerateTemplatePreview

func (c Client) GenerateTemplatePreview(id string, personalisation ...PersonalisationOption) (TemplatePreview, error)

func (Client) GetAllTemplates

func (c Client) GetAllTemplates(typ string) (Templates, error)

func (Client) GetNotificationById

func (c Client) GetNotificationById(id string) (Notification, error)

func (Client) GetTemplateByID

func (c Client) GetTemplateByID(id string) (Template, error)

func (Client) GetTemplateByIDAndVersion

func (c Client) GetTemplateByIDAndVersion(id string, version int) (Template, error)

func (Client) SendEmail

func (c Client) SendEmail(
	id string,
	emailAddress string,
	options ...SendEmailOption,
) (SentEmail, error)

func (Client) SendSMS

func (c Client) SendSMS(
	id string,
	phoneNumber string,
	options ...SendSMSOption,
) (SentSMS, error)

type ClientOption

type ClientOption func(base.Client) (base.Client, error)

func WithBaseURL

func WithBaseURL(target string) ClientOption

type CommonOption

type CommonOption interface {
	SendSMSOption
	SendEmailOption
}

func Reference

func Reference(referenceID string) CommonOption

Reference is a unique identifier you create. It identifies a single unique notification or a batch of notifications.

type Notification

type Notification struct {
	ID           string `json:"id,omitempty"`
	Subject      string `json:"subject"`
	Body         string `json:"body"`
	Reference    string `json:"reference"`
	EmailAddress string `json:"email_address"`
	PhoneNumber  string `json:"phone_number"`
	Type         string `json:"type"`
	Status       string `json:"status"`
	CreatedBy    string `json:"created_by_name"`
	CreatedAt    string `json:"created_at"`
	SentAt       string `json:"sent_at"`
	Template     struct {
		ID      string `json:"id"`
		URI     string `json:"uri"`
		Version int    `json:"version"`
	} `json:"template"`
}

type Personalisation

type Personalisation []struct {
	Key   string
	Value interface{}
}

Personalisation is a slice of structs used to define placeholder values in a template, such as name or reference number. The struct should be structured such that they key is the name of the value in your template, and the value is what you expect to be substituted in the message.

type PersonalisationOption

type PersonalisationOption interface {
	// contains filtered or unexported methods
}

type SendEmailOption

type SendEmailOption interface {
	// contains filtered or unexported methods
}

func EmailReplyToID

func EmailReplyToID(address string) SendEmailOption

EmailReplyToID is the ID of the reply-to address to receive replies from users.

type SendSMSOption

type SendSMSOption interface {
	// contains filtered or unexported methods
}

func SMSSenderID

func SMSSenderID(senderID string) SendSMSOption

SMSSenderID is a unique identifier for the sender of a text message.

type SentEmail

type SentEmail struct {
	ID           string  `json:"id"`
	URI          string  `json:"uri"`
	Reference    *string `json:"reference"`
	ScheduledFor *string `json:"scheduled_for"`

	Content struct {
		Subject   string `json:"subject"`
		Body      string `json:"body"`
		FromEmail string `json:"from_email"`
	} `json:"content"`

	Template struct {
		ID      string `json:"id"`
		URI     string `json:"uri"`
		Version int    `json:"version"`
	} `json:"template"`
}

type SentSMS

type SentSMS struct {
	ID           string  `json:"id"`
	URI          string  `json:"uri"`
	Reference    *string `json:"reference"`
	ScheduledFor *string `json:"scheduled_for"`

	Content struct {
		Body       string `json:"body"`
		FromNumber string `json:"from_number"`
	} `json:"content"`

	Template struct {
		ID      string `json:"id"`
		URI     string `json:"uri"`
		Version int    `json:"version"`
	} `json:"template"`
}

type Template

type Template struct {
	ID        string `json:"id,omitempty"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	CreatedBy string `json:"created_by"`
	Version   int    `json:"version"`
	Subject   string `json:"subject"`
	Body      string `json:"body"`
}

type TemplatePreview

type TemplatePreview struct {
	ID      string `json:"id,omitempty"`
	Type    string `json:"type"`
	Version int    `json:"version"`
	Subject string `json:"subject,omitempty"`
	Body    string `json:"body"`
}

type Templates

type Templates []Template

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL