This Go package helps you send notifications through Courier, the smartest way to design & deliver notifications. Design your notifications once using our drag & drop editor, then deliver to any channel through one API. Email, mobile push, SMS, Slack — you name it!
APIs supported:
- Audiences API
- Audit Events API
- Automations API
- Brand API
- Messages API
- Profiles API
- Send API
- List API
For a full description of request and response payloads and properties, please see the official Courier API docs.
Download the package using go get
:
go get -u github.com/trycourier/courier-go/v2
package main
import (
"context"
"fmt"
"github.com/trycourier/courier-go/v2"
)
func main() {
client := courier.CourierClient("<YOUR_AUTH_TOKEN>", nil)
message := courier.SendMessageRequestBody{
"template": "<COURIER_TEMPLATE>",
"to": map[string]string{
"email": "test@email.com"
}
}
reqID, err := client.SendMessage(context.Background(), message)
if err != nil {
panic(err)
}
fmt.Println(reqID)
}
If you would like to send an idempotent message then be sure to use the SendMessageWithOptions method as shown below:
package main
import (
"fmt"
"time"
"context"
"github.com/trycourier/courier-go/v2"
)
func main() {
client := courier.CourierClient("<YOUR_AUTH_TOKEN>", nil)
message := map[string]interface{}{
"template": "<COURIER_TEMPLATE>",
"to": map[string]string{
"email": "test@email.com"
}
}
reqID, err := client.SendMessageWithOptions(
context.Background(),
message,
courier.WithIdempotencyKey("fake-key"),
courier.WithIdempotencyKeyExpiration(time.Now().Add(time.Hour * 30))
)
if err != nil {
panic(err)
}
fmt.Println(reqID)
}
If you need to use a base url other than the default https://api.courier.com, you can pass it in as the second paramter to the CourierClient
:
client := courier.CourierClient("<AUTH_TOKEN>", "<BASE_URL>")
For a full description of request and response payloads and properties, please see the official Courier API docs.
SendMessage(ctx context.Context, body SendMessageRequestBody) (string, error)
[?]Send(ctx context.Context, eventID, recipientID string, body interface{}) (string, error): object
[?]SendMessageWithOptions(ctx context.Context, body map[string]interface{}, method string, opts ...Option) (string, error)
[?]
GetMessage(ctx context.Context, messageID string) (*MessageResponse, error)
[?]
PutAudience(ctx context.Context, audienceId string, audience Audience) (*AudienceResponse, error)
[?]GetAudience(ctx context.Context, audienceId string) (*AudienceResponseBody, error)
[?]GetAudienceMembers(ctx context.Context, audienceId string, cursor string) (*GetAudienceMembersResponse, error)
[?]GetAudiences(ctx context.Context, cursor string) (*GetAudiencesResponse, error)
[?]DeleteAudience(ctx context.Context, audienceId string) error
[?]
GetBrands(ctx context.Context, cursor string) (*BrandsResponse, error)
[?]GetBrand(ctx context.Context, brandID string) (*BrandResponse, error)
[?]PostBrand(ctx context.Context, body PostBrandBody) (*BrandResponse, error)
[?]PutBrand(ctx context.Context, brandID string, body PutBrandBody) (*BrandResponse, error)
[?]DeleteBrand(ctx context.Context, brandID string) error
[?]
GetProfile(ctx context.Context, id string) (map[string]json.RawMessage, error): object
[?]MergeProfileBytes(ctx context.Context, id string, profile []byte) error
[?]UpdateProfileBytes(ctx context.Context, id string, profile []byte) error
[?]
GetLists(ctx context.Context, cursor string, pattern string) (*ListsResponse, error)
[?]GetList(ctx context.Context, listID string) (*ListResponse, error)
[?]PutList(ctx context.Context, listID string, body interface{}) error
[?]DeleteList(ctx context.Context, listID string) error
[?]RestoreList(ctx context.Context, listID string) error
[?]GetListSubscriptions(ctx context.Context, listID string, cursor string) (*ListSubscriptionsResponse, error)
[?]PutListSubscriptions(ctx context.Context, listID string, body interface{}) error
[?]PostListSubscriptions(ctx context.Context, listID string, body interface{}) error
[?]ListSubscribe(ctx context.Context, listID string, recipientID string, body interface{}) error
[?]ListUnsubscribe(ctx context.Context, listID string, recipientID string) error
[?]
InvokeAutomation(ctx context.Context, body interface{}) (string, error)
[?]InvokeAutomationTemplate(ctx context.Context, templateId string, body interface{}) (string, error)
[?]
GetAuditEvent(ctx context.Context, auditEventID string) (*AuditEvent, error)
[?]ListAuditEvents(ctx context.Context, cursor string) (*ListAuditEventsResponse, error)
[?]
To update this SDK to the latest version, use go get -u github.com/trycourier/courier-go
.
The package is available as open source under the terms of the MIT License. MIT License