Documentation
¶
Overview ¶
Package hellio is the official Go client for the Hellio Messaging API v1: SMS, OTP (SMS / voice / WhatsApp / email), voice broadcasts, number lookup (HLR), email verification, and webhooks.
Create a client with a Bearer token and call one method per endpoint. Every call returns the decoded JSON response as a map[string]any (payloads live under the "data" key); non-2xx responses return a typed *Error.
Index ¶
- Constants
- Variables
- func Recipients(values ...string) []string
- type Client
- func (c *Client) Balance(ctx context.Context) (map[string]any, error)
- func (c *Client) Campaign(ctx context.Context, id int) (map[string]any, error)
- func (c *Client) CreateWebhook(ctx context.Context, webhookURL string, events []string) (map[string]any, error)
- func (c *Client) DeleteWebhook(ctx context.Context, id int) (map[string]any, error)
- func (c *Client) Lookup(ctx context.Context, numbers []string) (map[string]any, error)
- func (c *Client) LookupResult(ctx context.Context, id int) (map[string]any, error)
- func (c *Client) Lookups(ctx context.Context) (map[string]any, error)
- func (c *Client) Message(ctx context.Context, id int) (map[string]any, error)
- func (c *Client) OTP(ctx context.Context, to, sender, channel, purpose string, length, expiry int, ...) (map[string]any, error)
- func (c *Client) Pricing(ctx context.Context, country string) (map[string]any, error)
- func (c *Client) SMS(ctx context.Context, recipients []string, message, sender, gateway string) (map[string]any, error)
- func (c *Client) Verify(ctx context.Context, to, code, channel string) (bool, error)
- func (c *Client) VerifyEmail(ctx context.Context, emails []string) (map[string]any, error)
- func (c *Client) VerifyOTP(ctx context.Context, to, code, channel string) (map[string]any, error)
- func (c *Client) Voice(ctx context.Context, recipients []string, ...) (map[string]any, error)
- func (c *Client) VoiceStatus(ctx context.Context, id int) (map[string]any, error)
- func (c *Client) Webhooks(ctx context.Context) (map[string]any, error)
- type Error
- type Kind
- type Option
Constants ¶
const ( // DefaultBaseURL is the production API root. DefaultBaseURL = "https://api.helliomessaging.com/v1" // DefaultTimeout is the per-request timeout when none is configured. DefaultTimeout = 30 * time.Second )
Variables ¶
var ( ErrInvalidApiToken = &Error{Kind: KindInvalidApiToken} ErrInsufficientBalance = &Error{Kind: KindInsufficientBalance} ErrValidation = &Error{Kind: KindValidation} ErrRateLimit = &Error{Kind: KindRateLimit} )
Sentinel errors for use with errors.Is. Each matches any Error of the same Kind.
Functions ¶
func Recipients ¶
Recipients flattens single numbers and comma-separated strings into a trimmed, non-empty list. hellio.Recipients("233...", "233...,244...") is valid.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Hellio Messaging API. Create one with NewClient and reuse it; it is safe for concurrent use.
func NewClient ¶
NewClient builds a client. The token falls back to HELLIO_API_TOKEN, the base URL to HELLIO_BASE_URL, and the default sender to HELLIO_DEFAULT_SENDER when those are left empty.
func (*Client) CreateWebhook ¶
func (c *Client) CreateWebhook(ctx context.Context, webhookURL string, events []string) (map[string]any, error)
CreateWebhook registers a webhook URL for the given events (empty events is omitted from the request). POST webhooks.
func (*Client) DeleteWebhook ¶
DeleteWebhook removes a webhook. DELETE webhooks/{id}.
func (*Client) Lookup ¶
Lookup queues an HLR lookup for the given numbers (async; poll the result with LookupResult). POST lookup.
func (*Client) LookupResult ¶
LookupResult returns a single lookup result. GET lookup/{id}.
func (*Client) Message ¶
Message returns the delivery status of a single message. GET messages/{id}.
func (*Client) OTP ¶
func (c *Client) OTP(ctx context.Context, to, sender, channel, purpose string, length, expiry int, gateway string) (map[string]any, error)
OTP sends a one-time passcode. "to" is a phone number (sms/voice/whatsapp) or an email (email). sender (a Sender ID) is required for sms/voice and ignored for whatsapp and email. channel defaults to "sms" when empty (sms/voice/whatsapp/email). Pass length or expiry as 0 to omit them, and purpose or gateway as "" to omit them. POST otp/send.
func (*Client) Pricing ¶
Pricing returns per-network SMS pricing. Pass an ISO-2 country code to narrow the result, or "" for all. GET pricing.
func (*Client) SMS ¶
func (c *Client) SMS(ctx context.Context, recipients []string, message, sender, gateway string) (map[string]any, error)
SMS sends a text message. recipients may be single numbers or comma-separated strings; they are flattened into a list. Pass sender "" to use the configured default sender, and gateway "" to omit it. POST sms/send.
func (*Client) Verify ¶
Verify is a convenience wrapper that returns true when the code is valid. A 422 validation error is treated as "not verified" and returns (false, nil); other errors are returned as-is.
func (*Client) VerifyEmail ¶
VerifyEmail validates a list of email addresses. POST email/verify.
func (*Client) VerifyOTP ¶
VerifyOTP checks a passcode and returns the full response. channel defaults to "sms" when empty. POST otp/verify.
func (*Client) Voice ¶
func (c *Client) Voice(ctx context.Context, recipients []string, callerID, text, audioURL, name string) (map[string]any, error)
Voice starts a voice broadcast. Provide text (read out with TTS) or audioURL (a hosted audio file); pass "" for the one you do not use. name is an optional label. POST voice/send.
func (*Client) VoiceStatus ¶
VoiceStatus returns the status of a voice broadcast. GET voice/{id}.
type Error ¶
type Error struct {
Kind Kind
StatusCode int
Message string
// Body is the decoded JSON response, if any.
Body map[string]any
}
Error is returned for every non-2xx response. It carries the HTTP status code, a human message (from the body "message" field or a default), the parsed body, and a Kind for convenient switching. Use errors.As to reach these fields:
var e *hellio.Error
if errors.As(err, &e) { fmt.Println(e.StatusCode, e.Message) }
Or errors.Is against a sentinel:
if errors.Is(err, hellio.ErrRateLimit) { time.Sleep(time.Second) }
type Kind ¶
type Kind int
Kind classifies a Hellio API error by its HTTP status. Callers can switch on it or use errors.Is against the exported sentinels below.
const ( // KindGeneric is any non-2xx response that is not one of the specific kinds. KindGeneric Kind = iota // KindInvalidApiToken maps to HTTP 401. KindInvalidApiToken // KindInsufficientBalance maps to HTTP 402. KindInsufficientBalance // KindValidation maps to HTTP 422. KindValidation // KindRateLimit maps to HTTP 429. KindRateLimit // or the API paused). Transient: retry later. KindServiceUnavailable )
type Option ¶
type Option func(*Client)
Option configures a Client. Pass options to NewClient.
func WithBaseURL ¶
WithBaseURL overrides the API root (default DefaultBaseURL).
func WithDefaultSender ¶
WithDefaultSender sets the Sender ID used by SMS when no sender is given.
func WithHTTPClient ¶
WithHTTPClient injects a custom *http.Client. Handy for tests and for tuning transport, proxies, or timeouts.
func WithTimeout ¶
WithTimeout sets the per-request timeout on the default HTTP client. It has no effect if you also pass WithHTTPClient; set the timeout on that client instead.