client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client provides a wrapper around the AhaSend SDK with enhanced functionality.

This package implements the AhaSendClient interface and provides additional features beyond the base SDK:

  • Automatic retry logic with exponential backoff
  • HTTP request/response logging for debugging
  • Structured error handling and API error translation
  • Context-aware request handling
  • Idempotency key support for message sending
  • Configuration validation and connection testing

The Client struct wraps the official AhaSend SDK while maintaining full compatibility and adding CLI-specific enhancements for better user experience. Requests through the SDK share the SDK's rate limiter; the trigger and stream-start requests the client sends itself, which the SDK does not cover, have no rate limit.

Index

Constants

View Source
const MaxSendConcurrency = 10

MaxSendConcurrency is the most send requests messages send has in flight at once, and so the most connections to the API a client keeps open for the next request.

Variables

View Source
var ErrStreamClosed = errors.New("websocket connection closed")

ErrStreamClosed is the error ReadMessage returns when the server closes the connection normally, and on every read after the connection was closed or failed.

View Source
var ErrStreamFailed = errors.New("websocket connection failed")

ErrStreamFailed is the error ReadMessage returns when the connection failed: it dropped, or the server closed it with an error code.

View Source
var ErrStreamTaken = errors.New("another websocket connection holds the stream")

ErrStreamTaken is the error ConnectWebSocket returns when another connection holds the stream of a webhook or a route. Connecting with forceReconnect drops the other connection.

View Source
var ErrUndecodableMessage = errors.New("stream message cannot be read")

ErrUndecodableMessage is the error ReadMessage returns for a message that is not a JSON text message. The connection stays open, so the next read returns the next message.

Functions

func ShortenRetryDelaysForTesting added in v0.3.0

func ShortenRetryDelaysForTesting() (restore func())

ShortenRetryDelaysForTesting makes the clients created after it retry a failed request after a millisecond, so a test of an unreachable API does not wait through the backoff. It returns the function that restores the delay.

Types

type AhaSendClient

type AhaSendClient interface {
	// Authentication and account info
	GetAccountID() string
	GetAccount() (*responses.Account, error)
	Ping() (*common.SuccessResponse, error)

	// Message operations
	SendMessageWithIdempotencyKey(req requests.CreateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)
	SendTemplateMessageWithIdempotencyKey(req requests.CreateTemplateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)
	CancelMessage(messageID string) (*common.SuccessResponse, error)
	GetMessages(params requests.GetMessagesParams) (*responses.PaginatedMessagesResponse, error)
	GetMessage(messageID string) (*responses.Message, error)

	// Domain operations
	ListDomains(params requests.GetDomainsParams) (*responses.PaginatedDomainsResponse, error)
	CreateDomain(req requests.CreateDomainRequest, opts ...api.RequestOption) (*responses.Domain, error)
	GetDomain(domain string) (*responses.Domain, error)
	UpdateDomain(domain string, req requests.UpdateDomainRequest) (*responses.Domain, error)
	CheckDomainDNS(domain string) (*responses.Domain, error)
	DeleteDomain(domain string) (*common.SuccessResponse, error)

	// Webhook operations
	ListWebhooks(pagination common.PaginationParams, enabled *bool) (*responses.PaginatedWebhooksResponse, error)
	CreateWebhook(req requests.CreateWebhookRequest, opts ...api.RequestOption) (*responses.Webhook, error)
	GetWebhook(webhookID uuid.UUID) (*responses.Webhook, error)
	UpdateWebhook(webhookID uuid.UUID, req requests.UpdateWebhookRequest) (*responses.Webhook, error)
	DeleteWebhook(webhookID uuid.UUID) (*common.SuccessResponse, error)

	// Webhook streaming operations (development only)
	InitiateWebhookStream(webhookID *uuid.UUID) (*WebhookStreamResponse, error)
	ConnectWebSocket(wsURL string, forceReconnect bool) (*WebSocketClient, error)
	TriggerWebhook(webhookID uuid.UUID, events []string) (*common.SuccessResponse, error)

	// Route operations
	ListRoutes(params requests.GetRoutesParams) (*responses.PaginatedRoutesResponse, error)
	CreateRoute(req requests.CreateRouteRequest, opts ...api.RequestOption) (*responses.Route, error)
	GetRoute(routeID uuid.UUID) (*responses.Route, error)
	UpdateRoute(routeID uuid.UUID, req requests.UpdateRouteRequest) (*responses.Route, error)
	DeleteRoute(routeID uuid.UUID) (*common.SuccessResponse, error)

	// Route streaming operations (development only)
	InitiateRouteStream(routeID *uuid.UUID, recipient string) (*RouteStreamResponse, error)
	TriggerRoute(routeID uuid.UUID) (*common.SuccessResponse, error)

	// Suppression operations
	ListSuppressions(params requests.GetSuppressionsParams) (*responses.PaginatedSuppressionsResponse, error)
	CreateSuppression(req requests.CreateSuppressionRequest, opts ...api.RequestOption) (*responses.CreateSuppressionResponse, error)
	DeleteSuppression(email string, domain *string) (*common.SuccessResponse, error)
	WipeSuppressions(domains *string) (*common.SuccessResponse, error)

	// SMTP operations
	ListSMTPCredentials(pagination common.PaginationParams) (*responses.PaginatedSMTPCredentialsResponse, error)
	GetSMTPCredential(credentialID uuid.UUID) (*responses.SMTPCredential, error)
	CreateSMTPCredential(req requests.CreateSMTPCredentialRequest, opts ...api.RequestOption) (*responses.SMTPCredential, error)
	DeleteSMTPCredential(credentialID uuid.UUID) (*common.SuccessResponse, error)

	// Statistics operations
	GetDeliverabilityStatistics(params requests.GetDeliverabilityStatisticsParams) (*responses.DeliverabilityStatisticsResponse, error)
	GetBounceStatistics(params requests.GetBounceStatisticsParams) (*responses.BounceStatisticsResponse, error)
	GetDeliveryTimeStatistics(params requests.GetDeliveryTimeStatisticsParams) (*responses.DeliveryTimeStatisticsResponse, error)

	// Sub-account operations
	ListSubAccounts(pagination common.PaginationParams) (*responses.PaginatedSubAccountsResponse, error)
	CreateSubAccount(req requests.CreateSubAccountRequest, opts ...api.RequestOption) (*responses.SubAccount, error)
	GetSubAccountsUsage() (*responses.SubAccountUsageResponse, error)
	GetSubAccount(subAccountID uuid.UUID) (*responses.SubAccount, error)
	UpdateSubAccount(subAccountID uuid.UUID, req requests.UpdateSubAccountRequest) (*responses.SubAccount, error)
	DeleteSubAccount(subAccountID uuid.UUID) (*common.SuccessResponse, error)
	SuspendSubAccount(subAccountID uuid.UUID, req requests.SuspendSubAccountRequest) (*responses.SubAccount, error)
	UnsuspendSubAccount(subAccountID uuid.UUID) (*responses.SubAccount, error)
	UnpauseSubAccountDomain(subAccountID uuid.UUID, domain string) (*responses.Domain, error)

	// Sub-account API key operations
	ListSubAccountAPIKeys(subAccountID uuid.UUID, pagination common.PaginationParams) (*responses.PaginatedAPIKeysResponse, error)
	CreateSubAccountAPIKey(subAccountID uuid.UUID, req requests.CreateAPIKeyRequest, opts ...api.RequestOption) (*responses.APIKey, error)
	GetSubAccountAPIKey(subAccountID, keyID uuid.UUID) (*responses.APIKey, error)
	UpdateSubAccountAPIKey(subAccountID, keyID uuid.UUID, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)
	DeleteSubAccountAPIKey(subAccountID, keyID uuid.UUID) (*common.SuccessResponse, error)

	// API Key operations
	ListAPIKeys(pagination common.PaginationParams) (*responses.PaginatedAPIKeysResponse, error)
	GetAPIKey(keyID uuid.UUID) (*responses.APIKey, error)
	CreateAPIKey(req requests.CreateAPIKeyRequest, opts ...api.RequestOption) (*responses.APIKey, error)
	UpdateAPIKey(keyID uuid.UUID, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)
	DeleteAPIKey(keyID uuid.UUID) (*common.SuccessResponse, error)

	// Contact operations
	GetContacts(params requests.GetContactsParams) (*responses.PaginatedContactsResponse, error)
	GetContact(idOrEmail string) (*responses.Contact, error)
	CreateContact(req requests.CreateContactRequest, opts ...api.RequestOption) (*responses.Contact, error)
	UpdateContact(idOrEmail string, req requests.UpdateContactRequest) (*responses.Contact, error)
	DeleteContact(idOrEmail string) (*common.SuccessResponse, error)
	BatchUpsertContacts(req requests.BatchUpsertContactsRequest, opts ...api.RequestOption) (*responses.BatchUpsertContactsResponse, error)

	// List operations
	GetLists(params requests.GetListsParams) (*responses.PaginatedContactListsResponse, error)
	GetList(listID uuid.UUID) (*responses.ContactList, error)
	CreateList(req requests.CreateListRequest, opts ...api.RequestOption) (*responses.ContactList, error)
	UpdateList(listID uuid.UUID, req requests.UpdateListRequest) (*responses.ContactList, error)
	DeleteList(listID uuid.UUID) (*common.SuccessResponse, error)
	GetListContacts(listID uuid.UUID, params requests.GetListContactsParams) (*responses.PaginatedListContactsResponse, error)
	BatchAddListContacts(listID uuid.UUID, req requests.BatchAddListContactsRequest, opts ...api.RequestOption) (*responses.BatchAddListContactsResponse, error)
	UpsertListContact(listID uuid.UUID, idOrEmail string, req requests.UpsertListContactRequest) (*responses.ListContact, error)
	DeleteListContact(listID uuid.UUID, idOrEmail string) (*common.SuccessResponse, error)
	GetContactLists(idOrEmail string, params requests.GetContactListsParams) (*responses.PaginatedListContactsResponse, error)

	// Template operations
	GetTemplates(params requests.GetTemplatesParams) (*responses.PaginatedTemplatesResponse, error)
	GetTemplate(templateID uuid.UUID) (*responses.Template, error)
	CreateTemplate(req requests.CreateTemplateRequest, opts ...api.RequestOption) (*responses.Template, error)
	UpdateTemplate(templateID uuid.UUID, req requests.UpdateTemplateRequest, opts ...api.RequestOption) (*responses.Template, error)
	DeleteTemplate(templateID uuid.UUID) (*common.SuccessResponse, error)
	GetTemplateDraft(templateID uuid.UUID) (*responses.TemplateDraft, error)
	DiscardTemplateDraft(templateID uuid.UUID) (*responses.Template, error)
	PublishTemplate(templateID uuid.UUID, opts ...api.RequestOption) (*responses.Template, error)
	GetTemplateVersions(templateID uuid.UUID) (*responses.TemplateVersionsResponse, error)
	GetTemplateVersion(templateID, versionID uuid.UUID) (*responses.TemplateVersionDetail, error)
	RestoreTemplateVersion(templateID, versionID uuid.UUID, req requests.RestoreTemplateVersionRequest, opts ...api.RequestOption) (*responses.Template, error)

	// Campaign operations
	ListCampaigns(params requests.ListCampaignsParams) (*responses.PaginatedCampaignsResponse, error)
	GetCampaign(campaignID uuid.UUID) (*responses.Campaign, error)
	CreateCampaign(req requests.CreateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)
	UpdateCampaign(campaignID uuid.UUID, req requests.UpdateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)
	DeleteCampaign(campaignID uuid.UUID) (*common.SuccessResponse, error)
	DuplicateCampaign(campaignID uuid.UUID, req requests.DuplicateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)
	SendCampaign(campaignID uuid.UUID, req requests.SendCampaignRequest, opts ...api.RequestOption) (*responses.CampaignSend, error)
	UnscheduleCampaign(campaignID uuid.UUID, opts ...api.RequestOption) (*responses.Campaign, error)
	TestCampaign(campaignID uuid.UUID, req requests.TestCampaignRequest, opts ...api.RequestOption) (*responses.CampaignTest, error)
	GetCampaignStats(campaignID uuid.UUID) (*responses.CampaignStats, error)
	ListCampaignRecipients(campaignID uuid.UUID, params requests.ListCampaignRecipientsParams) (*responses.PaginatedCampaignRecipientsResponse, error)

	// Campaign template operations
	ListCampaignTemplates(params requests.ListCampaignTemplatesParams) (*responses.PaginatedCampaignTemplatesResponse, error)
	GetCampaignTemplate(templateID uuid.UUID) (*responses.CampaignTemplate, error)
	CreateCampaignTemplate(req requests.CreateCampaignTemplateRequest, opts ...api.RequestOption) (*responses.CampaignTemplate, error)
	UpdateCampaignTemplate(templateID uuid.UUID, req requests.UpdateCampaignTemplateRequest, opts ...api.RequestOption) (*responses.CampaignTemplate, error)
	DeleteCampaignTemplate(templateID uuid.UUID) (*common.SuccessResponse, error)
}

AhaSendClient defines the interface for AhaSend API operations This interface allows for better testability and mocking

type Client

type Client struct {
	*api.APIClient
	// contains filtered or unexported fields
}

Client wraps the AhaSend SDK client with additional functionality

func NewClient

func NewClient(apiKey, accountID string, apiURL ...string) (*Client, error)

NewClient creates a new AhaSend client

func (*Client) BatchAddListContacts added in v0.3.0

BatchAddListContacts adds up to 1,000 existing contacts to a list

func (*Client) BatchUpsertContacts added in v0.3.0

BatchUpsertContacts creates or updates up to 1,000 contacts

func (*Client) CancelMessage

func (c *Client) CancelMessage(messageID string) (*common.SuccessResponse, error)

CancelMessage cancels a scheduled message, given its UUID or its Message-ID such as <uuid@example.com>

func (*Client) CheckDomainDNS

func (c *Client) CheckDomainDNS(domain string) (*responses.Domain, error)

CheckDomainDNS triggers a DNS validation check for a domain

func (*Client) ConnectWebSocket

func (c *Client) ConnectWebSocket(wsURL string, forceReconnect bool) (*WebSocketClient, error)

ConnectWebSocket connects to the stream at wsURL, sending the API key in the Authorization header. The URL must use wss, and the connection always verifies the server's TLS certificate; only a loopback host may use plain ws. The connection goes through the proxy the environment sets, as API requests do.

func (*Client) CreateAPIKey

func (c *Client) CreateAPIKey(req requests.CreateAPIKeyRequest, opts ...api.RequestOption) (*responses.APIKey, error)

CreateAPIKey creates a new API key

func (*Client) CreateCampaign added in v0.3.0

func (c *Client) CreateCampaign(req requests.CreateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)

CreateCampaign creates a draft campaign

func (*Client) CreateCampaignTemplate added in v0.3.0

func (c *Client) CreateCampaignTemplate(req requests.CreateCampaignTemplateRequest, opts ...api.RequestOption) (*responses.CampaignTemplate, error)

CreateCampaignTemplate creates a campaign template

func (*Client) CreateContact added in v0.3.0

func (c *Client) CreateContact(req requests.CreateContactRequest, opts ...api.RequestOption) (*responses.Contact, error)

CreateContact creates a contact

func (*Client) CreateDomain

func (c *Client) CreateDomain(req requests.CreateDomainRequest, opts ...api.RequestOption) (*responses.Domain, error)

CreateDomain creates a new domain

func (*Client) CreateList added in v0.3.0

func (c *Client) CreateList(req requests.CreateListRequest, opts ...api.RequestOption) (*responses.ContactList, error)

CreateList creates a contact list

func (*Client) CreateRoute

func (c *Client) CreateRoute(req requests.CreateRouteRequest, opts ...api.RequestOption) (*responses.Route, error)

CreateRoute creates a new route

func (*Client) CreateSMTPCredential

func (c *Client) CreateSMTPCredential(req requests.CreateSMTPCredentialRequest, opts ...api.RequestOption) (*responses.SMTPCredential, error)

CreateSMTPCredential creates a new SMTP credential

func (*Client) CreateSubAccount

func (c *Client) CreateSubAccount(req requests.CreateSubAccountRequest, opts ...api.RequestOption) (*responses.SubAccount, error)

CreateSubAccount creates a new sub-account

func (*Client) CreateSubAccountAPIKey

func (c *Client) CreateSubAccountAPIKey(subAccountID uuid.UUID, req requests.CreateAPIKeyRequest, opts ...api.RequestOption) (*responses.APIKey, error)

CreateSubAccountAPIKey creates a new API key for a sub-account

func (*Client) CreateSuppression

CreateSuppression creates a new suppression

func (*Client) CreateTemplate added in v0.3.0

func (c *Client) CreateTemplate(req requests.CreateTemplateRequest, opts ...api.RequestOption) (*responses.Template, error)

CreateTemplate creates a transactional template

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(req requests.CreateWebhookRequest, opts ...api.RequestOption) (*responses.Webhook, error)

CreateWebhook creates a new webhook

func (*Client) DeleteAPIKey

func (c *Client) DeleteAPIKey(keyID uuid.UUID) (*common.SuccessResponse, error)

DeleteAPIKey deletes an API key

func (*Client) DeleteCampaign added in v0.3.0

func (c *Client) DeleteCampaign(campaignID uuid.UUID) (*common.SuccessResponse, error)

DeleteCampaign deletes a draft campaign

func (*Client) DeleteCampaignTemplate added in v0.3.0

func (c *Client) DeleteCampaignTemplate(templateID uuid.UUID) (*common.SuccessResponse, error)

DeleteCampaignTemplate deletes a campaign template

func (*Client) DeleteContact added in v0.3.0

func (c *Client) DeleteContact(idOrEmail string) (*common.SuccessResponse, error)

DeleteContact permanently deletes a contact by ID or email

func (*Client) DeleteDomain

func (c *Client) DeleteDomain(domain string) (*common.SuccessResponse, error)

DeleteDomain deletes a domain

func (*Client) DeleteList added in v0.3.0

func (c *Client) DeleteList(listID uuid.UUID) (*common.SuccessResponse, error)

DeleteList deletes a contact list

func (*Client) DeleteListContact added in v0.3.0

func (c *Client) DeleteListContact(listID uuid.UUID, idOrEmail string) (*common.SuccessResponse, error)

DeleteListContact removes a contact from a list

func (*Client) DeleteRoute

func (c *Client) DeleteRoute(routeID uuid.UUID) (*common.SuccessResponse, error)

DeleteRoute deletes a route

func (*Client) DeleteSMTPCredential

func (c *Client) DeleteSMTPCredential(credentialID uuid.UUID) (*common.SuccessResponse, error)

DeleteSMTPCredential deletes an SMTP credential by ID

func (*Client) DeleteSubAccount

func (c *Client) DeleteSubAccount(subAccountID uuid.UUID) (*common.SuccessResponse, error)

DeleteSubAccount deletes a sub-account

func (*Client) DeleteSubAccountAPIKey

func (c *Client) DeleteSubAccountAPIKey(subAccountID, keyID uuid.UUID) (*common.SuccessResponse, error)

DeleteSubAccountAPIKey deletes an API key owned by a sub-account

func (*Client) DeleteSuppression

func (c *Client) DeleteSuppression(email string, domain *string) (*common.SuccessResponse, error)

DeleteSuppression deletes a suppression by email and optional domain

func (*Client) DeleteTemplate added in v0.3.0

func (c *Client) DeleteTemplate(templateID uuid.UUID) (*common.SuccessResponse, error)

DeleteTemplate deletes a transactional template

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(webhookID uuid.UUID) (*common.SuccessResponse, error)

DeleteWebhook deletes a webhook

func (*Client) DiscardTemplateDraft added in v0.3.0

func (c *Client) DiscardTemplateDraft(templateID uuid.UUID) (*responses.Template, error)

DiscardTemplateDraft discards a template's draft

func (*Client) DuplicateCampaign added in v0.3.0

func (c *Client) DuplicateCampaign(campaignID uuid.UUID, req requests.DuplicateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)

DuplicateCampaign makes a new draft from a campaign

func (*Client) GetAPIKey

func (c *Client) GetAPIKey(keyID uuid.UUID) (*responses.APIKey, error)

GetAPIKey retrieves a specific API key by ID

func (*Client) GetAccount

func (c *Client) GetAccount() (*responses.Account, error)

GetAccount retrieves account information

func (*Client) GetAccountID

func (c *Client) GetAccountID() string

GetAccountID returns the configured account ID

func (*Client) GetBounceStatistics

GetBounceStatistics retrieves bounce statistics

func (*Client) GetCampaign added in v0.3.0

func (c *Client) GetCampaign(campaignID uuid.UUID) (*responses.Campaign, error)

GetCampaign retrieves a campaign

func (*Client) GetCampaignStats added in v0.3.0

func (c *Client) GetCampaignStats(campaignID uuid.UUID) (*responses.CampaignStats, error)

GetCampaignStats retrieves a campaign's counters, report and rates

func (*Client) GetCampaignTemplate added in v0.3.0

func (c *Client) GetCampaignTemplate(templateID uuid.UUID) (*responses.CampaignTemplate, error)

GetCampaignTemplate retrieves a campaign template

func (*Client) GetContact added in v0.3.0

func (c *Client) GetContact(idOrEmail string) (*responses.Contact, error)

GetContact retrieves a contact by ID or email

func (*Client) GetContactLists added in v0.3.0

func (c *Client) GetContactLists(idOrEmail string, params requests.GetContactListsParams) (*responses.PaginatedListContactsResponse, error)

GetContactLists retrieves a page of a contact's list memberships

func (*Client) GetContacts added in v0.3.0

GetContacts retrieves a page of contacts

func (*Client) GetDeliverabilityStatistics

GetDeliverabilityStatistics retrieves deliverability statistics

func (*Client) GetDeliveryTimeStatistics

GetDeliveryTimeStatistics retrieves delivery time statistics

func (*Client) GetDomain

func (c *Client) GetDomain(domain string) (*responses.Domain, error)

GetDomain gets a specific domain

func (*Client) GetList added in v0.3.0

func (c *Client) GetList(listID uuid.UUID) (*responses.ContactList, error)

GetList retrieves a contact list by ID

func (*Client) GetListContacts added in v0.3.0

GetListContacts retrieves a page of a list's members

func (*Client) GetLists added in v0.3.0

GetLists retrieves a page of contact lists

func (*Client) GetMessage

func (c *Client) GetMessage(messageID string) (*responses.Message, error)

GetMessage retrieves a single message by its UUID or its Message-ID, such as <uuid@example.com>

func (*Client) GetMessages

GetMessages retrieves messages with filtering and pagination

func (*Client) GetRoute

func (c *Client) GetRoute(routeID uuid.UUID) (*responses.Route, error)

GetRoute retrieves a single route by ID

func (*Client) GetSMTPCredential

func (c *Client) GetSMTPCredential(credentialID uuid.UUID) (*responses.SMTPCredential, error)

GetSMTPCredential gets a specific SMTP credential by ID

func (*Client) GetSubAccount

func (c *Client) GetSubAccount(subAccountID uuid.UUID) (*responses.SubAccount, error)

GetSubAccount retrieves a specific sub-account by ID

func (*Client) GetSubAccountAPIKey

func (c *Client) GetSubAccountAPIKey(subAccountID, keyID uuid.UUID) (*responses.APIKey, error)

GetSubAccountAPIKey retrieves a specific API key owned by a sub-account

func (*Client) GetSubAccountsUsage

func (c *Client) GetSubAccountsUsage() (*responses.SubAccountUsageResponse, error)

GetSubAccountsUsage retrieves parent and sub-account usage allocation

func (*Client) GetTemplate added in v0.3.0

func (c *Client) GetTemplate(templateID uuid.UUID) (*responses.Template, error)

GetTemplate retrieves a transactional template

func (*Client) GetTemplateDraft added in v0.3.0

func (c *Client) GetTemplateDraft(templateID uuid.UUID) (*responses.TemplateDraft, error)

GetTemplateDraft retrieves a template's unpublished draft

func (*Client) GetTemplateVersion added in v0.3.0

func (c *Client) GetTemplateVersion(templateID, versionID uuid.UUID) (*responses.TemplateVersionDetail, error)

GetTemplateVersion retrieves one published version of a template

func (*Client) GetTemplateVersions added in v0.3.0

func (c *Client) GetTemplateVersions(templateID uuid.UUID) (*responses.TemplateVersionsResponse, error)

GetTemplateVersions retrieves a template's published versions

func (*Client) GetTemplates added in v0.3.0

GetTemplates retrieves a page of transactional templates

func (*Client) GetWebhook

func (c *Client) GetWebhook(webhookID uuid.UUID) (*responses.Webhook, error)

GetWebhook retrieves a single webhook by ID

func (*Client) InitiateRouteStream

func (c *Client) InitiateRouteStream(routeID *uuid.UUID, recipient string) (*RouteStreamResponse, error)

InitiateRouteStream asks the API for a websocket URL that streams the emails of routeID, or of a temporary route for recipient. The caller sets exactly one of them.

func (*Client) InitiateWebhookStream

func (c *Client) InitiateWebhookStream(webhookID *uuid.UUID) (*WebhookStreamResponse, error)

InitiateWebhookStream asks the API for a websocket URL that streams the events of webhookID, or of a temporary webhook when webhookID is nil.

func (*Client) ListAPIKeys

func (c *Client) ListAPIKeys(pagination common.PaginationParams) (*responses.PaginatedAPIKeysResponse, error)

ListAPIKeys retrieves a page of API keys

func (*Client) ListCampaignRecipients added in v0.3.0

func (c *Client) ListCampaignRecipients(campaignID uuid.UUID, params requests.ListCampaignRecipientsParams) (*responses.PaginatedCampaignRecipientsResponse, error)

ListCampaignRecipients lists a campaign's recipients in one status or bounce classification

func (*Client) ListCampaignTemplates added in v0.3.0

ListCampaignTemplates lists the account's campaign templates

func (*Client) ListCampaigns added in v0.3.0

ListCampaigns lists the account's campaigns

func (*Client) ListDomains

ListDomains lists domains with filters and pagination

func (*Client) ListRoutes

ListRoutes retrieves a page of routes, optionally of one recipient domain

func (*Client) ListSMTPCredentials

func (c *Client) ListSMTPCredentials(pagination common.PaginationParams) (*responses.PaginatedSMTPCredentialsResponse, error)

ListSMTPCredentials lists a page of SMTP credentials

func (*Client) ListSubAccountAPIKeys

func (c *Client) ListSubAccountAPIKeys(subAccountID uuid.UUID, pagination common.PaginationParams) (*responses.PaginatedAPIKeysResponse, error)

ListSubAccountAPIKeys retrieves a page of the API keys of a sub-account

func (*Client) ListSubAccounts

func (c *Client) ListSubAccounts(pagination common.PaginationParams) (*responses.PaginatedSubAccountsResponse, error)

ListSubAccounts retrieves a page of sub-accounts

func (*Client) ListSuppressions

ListSuppressions retrieves a paginated list of suppressions

func (*Client) ListWebhooks

func (c *Client) ListWebhooks(pagination common.PaginationParams, enabled *bool) (*responses.PaginatedWebhooksResponse, error)

ListWebhooks lists a page of webhooks; a non-nil enabled keeps only the webhooks with that status, filtered by the API.

func (*Client) Ping

func (c *Client) Ping() (*common.SuccessResponse, error)

Ping tests the connection and validates the API key

func (*Client) PublishTemplate added in v0.3.0

func (c *Client) PublishTemplate(templateID uuid.UUID, opts ...api.RequestOption) (*responses.Template, error)

PublishTemplate publishes a template's draft as a new version

func (*Client) RestoreTemplateVersion added in v0.3.0

func (c *Client) RestoreTemplateVersion(templateID, versionID uuid.UUID, req requests.RestoreTemplateVersionRequest, opts ...api.RequestOption) (*responses.Template, error)

RestoreTemplateVersion restores a published version into a template's draft

func (*Client) SendCampaign added in v0.3.0

func (c *Client) SendCampaign(campaignID uuid.UUID, req requests.SendCampaignRequest, opts ...api.RequestOption) (*responses.CampaignSend, error)

SendCampaign sends a draft campaign now or at a later time

func (*Client) SendMessageWithIdempotencyKey

func (c *Client) SendMessageWithIdempotencyKey(req requests.CreateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)

SendMessageWithIdempotencyKey sends a message with idempotency key support, once: the caller decides about retries. A failure after the request was written is a RequestWrittenError.

func (*Client) SendTemplateMessageWithIdempotencyKey added in v0.3.0

func (c *Client) SendTemplateMessageWithIdempotencyKey(req requests.CreateTemplateMessageRequest, idempotencyKey string) (*responses.CreateMessageResponse, error)

SendTemplateMessageWithIdempotencyKey sends a stored template with idempotency key support, once: the caller decides about retries. A failure after the request was written is a RequestWrittenError.

func (*Client) SuspendSubAccount

func (c *Client) SuspendSubAccount(subAccountID uuid.UUID, req requests.SuspendSubAccountRequest) (*responses.SubAccount, error)

SuspendSubAccount suspends a sub-account

func (*Client) TestCampaign added in v0.3.0

func (c *Client) TestCampaign(campaignID uuid.UUID, req requests.TestCampaignRequest, opts ...api.RequestOption) (*responses.CampaignTest, error)

TestCampaign sends a test of a draft campaign

func (*Client) TriggerRoute

func (c *Client) TriggerRoute(routeID uuid.UUID) (*common.SuccessResponse, error)

TriggerRoute triggers route events for development testing

func (*Client) TriggerWebhook

func (c *Client) TriggerWebhook(webhookID uuid.UUID, events []string) (*common.SuccessResponse, error)

TriggerWebhook triggers webhook events for development testing

func (*Client) UnpauseSubAccountDomain added in v0.3.0

func (c *Client) UnpauseSubAccountDomain(subAccountID uuid.UUID, domain string) (*responses.Domain, error)

UnpauseSubAccountDomain lifts the pause on a domain of a sub-account

func (*Client) UnscheduleCampaign added in v0.3.0

func (c *Client) UnscheduleCampaign(campaignID uuid.UUID, opts ...api.RequestOption) (*responses.Campaign, error)

UnscheduleCampaign returns a validating or scheduled campaign to draft

func (*Client) UnsuspendSubAccount

func (c *Client) UnsuspendSubAccount(subAccountID uuid.UUID) (*responses.SubAccount, error)

UnsuspendSubAccount unsuspends a sub-account

func (*Client) UpdateAPIKey

func (c *Client) UpdateAPIKey(keyID uuid.UUID, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)

UpdateAPIKey updates an existing API key

func (*Client) UpdateCampaign added in v0.3.0

func (c *Client) UpdateCampaign(campaignID uuid.UUID, req requests.UpdateCampaignRequest, opts ...api.RequestOption) (*responses.Campaign, error)

UpdateCampaign partially updates a draft campaign

func (*Client) UpdateCampaignTemplate added in v0.3.0

func (c *Client) UpdateCampaignTemplate(templateID uuid.UUID, req requests.UpdateCampaignTemplateRequest, opts ...api.RequestOption) (*responses.CampaignTemplate, error)

UpdateCampaignTemplate partially updates a campaign template

func (*Client) UpdateContact added in v0.3.0

func (c *Client) UpdateContact(idOrEmail string, req requests.UpdateContactRequest) (*responses.Contact, error)

UpdateContact partially updates a contact by ID or email

func (*Client) UpdateDomain

func (c *Client) UpdateDomain(domain string, req requests.UpdateDomainRequest) (*responses.Domain, error)

UpdateDomain updates domain settings

func (*Client) UpdateList added in v0.3.0

func (c *Client) UpdateList(listID uuid.UUID, req requests.UpdateListRequest) (*responses.ContactList, error)

UpdateList partially updates a contact list

func (*Client) UpdateRoute

func (c *Client) UpdateRoute(routeID uuid.UUID, req requests.UpdateRouteRequest) (*responses.Route, error)

UpdateRoute updates an existing route

func (*Client) UpdateSubAccount

func (c *Client) UpdateSubAccount(subAccountID uuid.UUID, req requests.UpdateSubAccountRequest) (*responses.SubAccount, error)

UpdateSubAccount updates an existing sub-account

func (*Client) UpdateSubAccountAPIKey

func (c *Client) UpdateSubAccountAPIKey(subAccountID, keyID uuid.UUID, req requests.UpdateAPIKeyRequest) (*responses.APIKey, error)

UpdateSubAccountAPIKey updates an API key owned by a sub-account

func (*Client) UpdateTemplate added in v0.3.0

func (c *Client) UpdateTemplate(templateID uuid.UUID, req requests.UpdateTemplateRequest, opts ...api.RequestOption) (*responses.Template, error)

UpdateTemplate partially updates a transactional template

func (*Client) UpdateWebhook

func (c *Client) UpdateWebhook(webhookID uuid.UUID, req requests.UpdateWebhookRequest) (*responses.Webhook, error)

UpdateWebhook updates an existing webhook

func (*Client) UpsertListContact added in v0.3.0

func (c *Client) UpsertListContact(listID uuid.UUID, idOrEmail string, req requests.UpsertListContactRequest) (*responses.ListContact, error)

UpsertListContact adds a contact to a list or updates its membership

func (*Client) WipeSuppressions

func (c *Client) WipeSuppressions(domain *string) (*common.SuccessResponse, error)

WipeSuppressions deletes all suppressions in the account

type Event

type Event struct {
	Type      string `json:"type"`
	StreamID  string `json:"stream_id"`
	AccountID string `json:"account_id"`
	// Data is the event's payload exactly as the server sent it, so it is
	// forwarded byte for byte.
	Data      json.RawMessage   `json:"data"`
	Metadata  map[string]string `json:"metadata"`
	Timestamp int64             `json:"timestamp"`
}

type RequestWrittenError added in v0.3.0

type RequestWrittenError struct {
	Err error
}

RequestWrittenError is a failure to get the API's answer to a request that was written in full, such as a timeout or a connection closed while waiting for the answer: the API may have received the request and acted on it. It wraps the failure, so it prints and exits the same way.

func (*RequestWrittenError) Error added in v0.3.0

func (e *RequestWrittenError) Error() string

func (*RequestWrittenError) Unwrap added in v0.3.0

func (e *RequestWrittenError) Unwrap() error

type RouteStreamResponse

type RouteStreamResponse struct {
	RouteID string `json:"route_id"`
	WsURL   string `json:"ws_url"`
}

type WebSocketClient

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

func (*WebSocketClient) Close

func (wsc *WebSocketClient) Close() error

Close sends the server a close frame, waiting at most controlWriteTimeout, and closes the connection.

func (*WebSocketClient) ReadMessage

func (wsc *WebSocketClient) ReadMessage() (*WebSocketMessage, error)

ReadMessage waits for the next message of the stream. It returns ErrStreamClosed once the server closed the connection normally, ErrStreamFailed when the connection failed, errMessageTooLarge for a message over the size limit, which ends the stream, and ErrUndecodableMessage for a message it cannot read, after which the stream goes on.

type WebSocketMessage

type WebSocketMessage struct {
	Type      string `json:"type"`
	Event     *Event `json:"event,omitempty"`
	SessionID string `json:"session_id,omitempty"`
	Stream    string `json:"stream,omitempty"`
	Timestamp int64  `json:"timestamp"`
}

type WebhookStreamResponse

type WebhookStreamResponse struct {
	WebhookID string `json:"webhook_id"`
	WsURL     string `json:"ws_url"`
}

Jump to

Keyboard shortcuts

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