Documentation
¶
Index ¶
- Variables
- type Config
- type Contact
- type ContactInfo
- type ContactsCountResponse
- type CreateContactPayload
- type CustomError
- type EmailRecipient
- type Event
- type EventPayload
- type EventResponse
- type Plunk
- func (p *Plunk) CreateContact(payload CreateContactPayload) (*Contact, error)
- func (p *Plunk) DeleteContact(id string) (*Contact, error)
- func (p *Plunk) DeleteEvent(id string) (*Event, error)
- func (p *Plunk) GetContact(id string) (*Contact, error)
- func (p *Plunk) GetContacts() ([]*Contact, error)
- func (p *Plunk) GetContactsCount() (int, error)
- func (p *Plunk) SendMultipleTransactionalEmails(payload []TransactionalEmailPayload) ([]*TransactionalEmailResponse, error)
- func (p *Plunk) SendTransactionalEmail(payload TransactionalEmailPayload) (*TransactionalEmailResponse, error)
- func (p *Plunk) SubscribeContact(id string) (*Contact, error)
- func (p *Plunk) TriggerEvent(payload EventPayload) (*EventResponse, error)
- func (p *Plunk) UnsubscribeContact(id string) (*Contact, error)
- func (p *Plunk) UpdateContact(c *Contact) (*Contact, error)
- type Request
- type SendConfig
- type TransactionalEmailPayload
- type TransactionalEmailResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingContactID = errors.New("missing contact id") ErrCouldNotCreateContact = errors.New("could not create contact") ErrCouldNotGetContact = errors.New("could not get contact") ErrCouldNotGetContacts = errors.New("could not get contacts") ErrCouldNotGetCount = errors.New("could not get count") ErrCouldNotSubscribeContact = errors.New("could not subscribe contact") ErrCouldNotUnsubscribeContact = errors.New("could not unsubscribe contact") ErrCouldNotDeleteContact = errors.New("could not delete contact") ErrCouldNotUpdateContact = errors.New("could not update contact") )
var ( ErrMissingEvent = errors.New("missing event") ErrMissingEmail = errors.New("missing email") ErrMissingEventID = errors.New("missing event id") ErrCouldNotDeleteEvent = errors.New("could not delete event") )
var ( ErrEmptyResponse = errors.New("empty response") ErrMissingTo = errors.New("missing recipient") ErrMissingSubject = errors.New("missing subject") ErrMissingBody = errors.New("missing body or html") )
var (
ErrNoAPIKey = errors.New("no API key provided")
)
Functions ¶
This section is empty.
Types ¶
type Contact ¶
type ContactInfo ¶
type ContactsCountResponse ¶
type ContactsCountResponse struct {
Count int `json:"count"`
}
type CreateContactPayload ¶
type CustomError ¶
type CustomError struct {
Code int `json:"code"`
Type string `json:"error"`
Message string `json:"message"`
Time int64 `json:"time"`
}
Define a struct to represent the JSON error data
func (*CustomError) Error ¶
func (e *CustomError) Error() string
type EmailRecipient ¶
type EmailRecipient struct {
Contact ContactInfo `json:"contact"`
Email string `json:"email"`
}
type EventPayload ¶
type EventPayload struct {
Event string `json:"event"`
Email string `json:"email"`
Data map[string]any `json:"data"` // See: https://docs.useplunk.com/guides/linking-data-to-contacts#linking-data-on-event-triggers
Subscribed bool `json:"subscribed"` // When you trigger an event for a contact, they will automatically be subscribed unless you pass subscribed: false along with the event.
}
type EventResponse ¶
type Plunk ¶
type Plunk struct {
*Config
}
func NewFromEnv ¶
NewFromEnv returns a new Plunk client using the PLUNK_API_KEY environment variable.
func (*Plunk) CreateContact ¶
func (p *Plunk) CreateContact(payload CreateContactPayload) (*Contact, error)
Used to create a new contact in your Plunk project without triggering an event
func (*Plunk) DeleteContact ¶
Delete a contact from your Plunk project.
func (*Plunk) DeleteEvent ¶
Deletes an event.
func (*Plunk) GetContact ¶
Gets the details of a specific contact.
func (*Plunk) GetContacts ¶
Get a list of all contacts in your Plunk account.
func (*Plunk) GetContactsCount ¶
Gets the total number of contacts in your Plunk account. Useful for displaying the number of contacts in a dashboard, landing page or other marketing material.
func (*Plunk) SendMultipleTransactionalEmails ¶
func (p *Plunk) SendMultipleTransactionalEmails(payload []TransactionalEmailPayload) ([]*TransactionalEmailResponse, error)
func (*Plunk) SendTransactionalEmail ¶
func (p *Plunk) SendTransactionalEmail(payload TransactionalEmailPayload) (*TransactionalEmailResponse, error)
Used to send transactional emails to a single recipient or multiple recipients at once. Transactional emails are programmatically sent emails that are considered to be part of your application's workflow. This could be a password reset email, a billing email or other non-marketing emails.
Using Markdown ¶
It is possible to use Markdown when sending a transactional email. Plunk will automatically apply the same styling as the email templates you make in the editor. Any email with a body that starts with # will be treated as Markdown.
func (*Plunk) SubscribeContact ¶
Updates a contact's subscription status to subscribed.
func (*Plunk) TriggerEvent ¶
func (p *Plunk) TriggerEvent(payload EventPayload) (*EventResponse, error)
Triggers an event and creates it if it doesn't exist.
func (*Plunk) UnsubscribeContact ¶
Updates a contact's subscription status to unsubscribed.
type SendConfig ¶
type TransactionalEmailPayload ¶
type TransactionalEmailPayload struct {
To string `json:"to"`
Subject string `json:"subject,omitempty"`
Body string `json:"body,omitempty"`
From string `json:"from,omitempty"`
Name string `json:"name,omitempty"`
Template string `json:"template,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
type TransactionalEmailResponse ¶
type TransactionalEmailResponse struct {
Success bool `json:"success"`
Emails []EmailRecipient `json:"emails"`
Timestamp string `json:"timestamp"`
}