Documentation
¶
Overview ¶
Package esms is the official Go SDK for the eSMS Africa SMS API.
Send SMS across African countries, track delivery, schedule messages, and check your balance.
client := esms.New("esms_live_...")
res, err := client.Messages.Send(ctx, esms.SendParams{
To: "+256700000000",
Text: "Hello!",
})
Index ¶
- Constants
- type Balance
- type BalanceService
- type BulkSendParams
- type Client
- type Error
- func (e *Error) Balance() (float64, bool)
- func (e *Error) Cost() (float64, bool)
- func (e *Error) Currency() (string, bool)
- func (e *Error) Error() string
- func (e *Error) IsAuthentication() bool
- func (e *Error) IsConnection() bool
- func (e *Error) IsInsufficientBalance() bool
- func (e *Error) IsNotFound() bool
- func (e *Error) IsPermission() bool
- func (e *Error) IsRateLimit() bool
- func (e *Error) Unwrap() error
- type ListParams
- type Message
- type MessageList
- type MessageSummary
- type MessagesService
- func (s *MessagesService) Get(ctx context.Context, messageID string) (*Message, error)
- func (s *MessagesService) List(ctx context.Context, params ListParams) (*MessageList, error)
- func (s *MessagesService) Retry(ctx context.Context, messageID string) (*SendResult, error)
- func (s *MessagesService) Schedule(ctx context.Context, params SendParams) (*SendResult, error)
- func (s *MessagesService) Send(ctx context.Context, params SendParams) (*SendResult, error)
- func (s *MessagesService) SendBulk(ctx context.Context, params BulkSendParams) (map[string]any, error)
- type Option
- type Route
- type RoutesService
- type SendParams
- type SendResult
- type TimelineEvent
Constants ¶
const (
// DefaultBaseURL is the production API endpoint.
DefaultBaseURL = "https://sms.esmsafrica.io/api"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Balance ¶
type Balance struct {
Balance float64 `json:"balance"`
Currency string `json:"currency"`
SMSEstimate *int `json:"sms_estimate"`
}
Balance is the current account balance.
type BalanceService ¶
type BalanceService struct {
// contains filtered or unexported fields
}
BalanceService reads the account balance.
type BulkSendParams ¶
type BulkSendParams struct {
ContactListIDs []int `json:"contact_list_ids"`
Text string `json:"text"`
SenderID string `json:"sender_id,omitempty"`
Route string `json:"route,omitempty"`
}
BulkSendParams sends one message to every contact in the given lists.
type Client ¶
type Client struct {
// Messages sends and manages SMS messages.
Messages *MessagesService
// Balance reads the account balance.
Balance *BalanceService
// Routes lists available routes and pricing.
Routes *RoutesService
// contains filtered or unexported fields
}
Client is the eSMS Africa API client. Create one with New.
type Error ¶
type Error struct {
// Status is the HTTP status code (0 for connection failures).
Status int
// Code is the machine-readable error code, e.g. "insufficient_balance".
Code string
// Message is a human-readable description.
Message string
// Detail is the raw `detail` payload returned by the API.
Detail any
// RequestID is the X-Request-Id response header, useful for support.
RequestID string
// Err is the underlying cause for connection failures.
Err error
}
Error is returned for every failure that originates from the eSMS API. Inspect Status and Code to branch, or use errors.As with the typed helpers.
func (*Error) IsAuthentication ¶
IsAuthentication reports a 401 (missing or invalid API key).
func (*Error) IsConnection ¶
IsConnection reports a network/transport failure (never reached the API).
func (*Error) IsInsufficientBalance ¶
IsInsufficientBalance reports the 422 insufficient_balance error. When true, use Balance/Cost/Currency to read the shortfall.
func (*Error) IsPermission ¶
IsPermission reports a 403 (authenticated but not allowed).
type ListParams ¶
type ListParams struct {
Page int // zero-based page index
Limit int // page size, 1-100
Status string // optional status filter, e.g. "delivered"
}
ListParams filters a message listing.
type Message ¶
type Message struct {
MessageSummary
ErrorMessage *string `json:"error_message"`
SubmittedAt *string `json:"submitted_at"`
FailedAt *string `json:"failed_at"`
Timeline []TimelineEvent `json:"timeline"`
}
Message is a single message with its full delivery timeline.
type MessageList ¶
type MessageList struct {
Messages []MessageSummary `json:"messages"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
}
MessageList is a page of messages.
type MessageSummary ¶
type MessageSummary struct {
ID string `json:"id"`
Phone string `json:"phone"`
Text string `json:"text"`
SenderID *string `json:"sender_id"`
Route *string `json:"route"`
Country *string `json:"country"`
Segments int `json:"segments"`
Cost float64 `json:"cost"`
Currency *string `json:"currency"`
Status string `json:"status"`
ErrorCode *string `json:"error_code"`
RetryCount int `json:"retry_count"`
CreatedAt string `json:"created_at"`
DeliveredAt *string `json:"delivered_at"`
}
MessageSummary is a single row in a message listing.
type MessagesService ¶
type MessagesService struct {
// contains filtered or unexported fields
}
MessagesService handles SMS message operations.
func (*MessagesService) List ¶
func (s *MessagesService) List(ctx context.Context, params ListParams) (*MessageList, error)
List returns messages, most recent first.
func (*MessagesService) Retry ¶
func (s *MessagesService) Retry(ctx context.Context, messageID string) (*SendResult, error)
Retry retries a failed message.
func (*MessagesService) Schedule ¶
func (s *MessagesService) Schedule(ctx context.Context, params SendParams) (*SendResult, error)
Schedule sends an SMS for later delivery (5 minutes to 7 days out). The ScheduleMode field is set automatically.
func (*MessagesService) Send ¶
func (s *MessagesService) Send(ctx context.Context, params SendParams) (*SendResult, error)
Send sends a single SMS.
func (*MessagesService) SendBulk ¶
func (s *MessagesService) SendBulk(ctx context.Context, params BulkSendParams) (map[string]any, error)
SendBulk sends one message to every contact in the given contact lists.
type Option ¶
type Option func(*Client)
Option customises a Client.
func WithHTTPClient ¶
WithHTTPClient supplies a custom *http.Client (timeouts, proxies, transport).
func WithMaxRetries ¶
WithMaxRetries sets how many times transient failures (network, 429, 5xx) are retried with backoff. Default 2.
type Route ¶
type Route struct {
Code string `json:"code"`
Name string `json:"name"`
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
Currency string `json:"currency"`
PricePerSegment float64 `json:"price_per_segment"`
SenderIDDefault string `json:"sender_id_default"`
IsActive bool `json:"is_active"`
}
Route is an active SMS route (one per reachable country).
type RoutesService ¶
type RoutesService struct {
// contains filtered or unexported fields
}
RoutesService lists available routes.
type SendParams ¶
type SendParams struct {
// To is the recipient in international format, e.g. "+256700000000".
To string `json:"to"`
// Text is the message body (Unicode supported).
Text string `json:"text"`
// SenderID is an approved sender ID; defaults to the route's default.
SenderID string `json:"sender_id,omitempty"`
// Route pins an explicit route code such as "ESMS_UG".
Route string `json:"route,omitempty"`
// ScheduleMode is "now" (default) or "scheduled".
ScheduleMode string `json:"schedule_mode,omitempty"`
// ScheduledAt is an ISO-8601 UTC time; required when ScheduleMode is "scheduled".
ScheduledAt string `json:"scheduled_at,omitempty"`
}
SendParams describes a single SMS to send.
type SendResult ¶
type SendResult struct {
ID string `json:"id"`
Status string `json:"status"`
Segments int `json:"segments"`
Cost float64 `json:"cost"`
CostCurrency string `json:"cost_currency"`
RouteCost float64 `json:"route_cost"`
RouteCurr string `json:"route_currency"`
Route string `json:"route"`
BalanceAfter float64 `json:"balance_after"`
ScheduledAt *string `json:"scheduled_at"`
}
SendResult is returned when a message is accepted.