Documentation
¶
Overview ¶
Package sendimessage is the SendiMessage SDK — send iMessage/SMS through the SendiMessage API. Server-side use: the key pair grants full messaging access.
client := sendimessage.New(apiKey, apiSecret)
msg, err := client.SendMessage(ctx, sendimessage.SendMessageParams{
Number: "+15551234567",
Content: "Hello!",
})
Index ¶
- Constants
- func VerifyWebhookSignature(secret string, rawBody []byte, signature string) bool
- type APIError
- type Client
- func (c *Client) CreateContact(ctx context.Context, props Object) (Object, error)
- func (c *Client) CreateWebhook(ctx context.Context, params WebhookParams) (Object, error)
- func (c *Client) DeleteContact(ctx context.Context, number string) (Object, error)
- func (c *Client) DeleteWebhook(ctx context.Context, webhookURL string) (Object, error)
- func (c *Client) GetCallForwarding(ctx context.Context, lineHandle string) (Object, error)
- func (c *Client) GetContact(ctx context.Context, number string) (Object, error)
- func (c *Client) GetMessage(ctx context.Context, messageHandle string) (*HistoryMessage, error)
- func (c *Client) GetStatus(ctx context.Context, messageHandle string) (*OutboundMessage, error)
- func (c *Client) ListContacts(ctx context.Context, query url.Values) (Object, error)
- func (c *Client) ListConversationMessages(ctx context.Context, conversationHandle string, query url.Values) (Object, error)
- func (c *Client) ListConversations(ctx context.Context, query url.Values) (Object, error)
- func (c *Client) ListLines(ctx context.Context) (Object, error)
- func (c *Client) ListMessages(ctx context.Context, params ListMessagesParams) (*MessageList, error)
- func (c *Client) ListWebhooks(ctx context.Context) (Object, error)
- func (c *Client) Lookup(ctx context.Context, number string) (*LookupResult, error)
- func (c *Client) MarkConversationRead(ctx context.Context, conversationHandle string) (Object, error)
- func (c *Client) Me(ctx context.Context) (Object, error)
- func (c *Client) RecheckContact(ctx context.Context, number string) (Object, error)
- func (c *Client) ReplaceWebhooks(ctx context.Context, webhooks []WebhookParams) (Object, error)
- func (c *Client) SendMessage(ctx context.Context, params SendMessageParams) (*OutboundMessage, error)
- func (c *Client) SetCallForwarding(ctx context.Context, lineHandle string, forwardingNumber *string) (Object, error)
- func (c *Client) SetOptOut(ctx context.Context, number string, optedOut bool) (Object, error)
- func (c *Client) UpdateContact(ctx context.Context, number string, props Object) (Object, error)
- func (c *Client) UpdateLine(ctx context.Context, lineHandle string, props Object) (Object, error)
- func (c *Client) UploadMedia(ctx context.Context, path string) (string, error)
- func (c *Client) UploadMediaReader(ctx context.Context, r io.Reader, filename string) (string, error)
- type HistoryMessage
- type ListMessagesParams
- type LookupResult
- type MessageList
- type Object
- type Option
- type OutboundMessage
- type SendMessageParams
- type WebhookParams
Constants ¶
const DefaultBaseURL = "https://api.sendimessage.com/v1"
const Version = "0.1.1"
Version of this client, sent as the User-Agent.
Variables ¶
This section is empty.
Functions ¶
func VerifyWebhookSignature ¶
VerifyWebhookSignature checks the X-SMSBridge-Signature header of an incoming webhook: hex HMAC-SHA256 of the raw request body with the webhook's secret. Pass the body exactly as received.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the SendiMessage public API (X-API-Key / X-API-Secret).
func (*Client) CreateContact ¶
func (*Client) CreateWebhook ¶
func (*Client) DeleteContact ¶
func (*Client) DeleteWebhook ¶
func (*Client) GetCallForwarding ¶
func (*Client) GetContact ¶
GetContact fetches a contact; number is the E.164 number or contact_handle.
func (*Client) GetMessage ¶
GetMessage returns one history message by its handle.
func (*Client) ListContacts ¶
func (*Client) ListConversationMessages ¶
func (*Client) ListConversations ¶
func (*Client) ListMessages ¶
func (c *Client) ListMessages(ctx context.Context, params ListMessagesParams) (*MessageList, error)
ListMessages returns one page of message history.
func (*Client) MarkConversationRead ¶
func (*Client) Me ¶ added in v0.1.1
Me returns the user + company behind these credentials (GET /me).
func (*Client) RecheckContact ¶
RecheckContact re-runs the iMessage/SMS service check right now.
func (*Client) ReplaceWebhooks ¶
ReplaceWebhooks swaps the whole webhook set in one call.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, params SendMessageParams) (*OutboundMessage, error)
SendMessage queues a message; the result carries message_handle and status QUEUED.
func (*Client) SetCallForwarding ¶
func (c *Client) SetCallForwarding(ctx context.Context, lineHandle string, forwardingNumber *string) (Object, error)
SetCallForwarding queues a forwarding change for the operator (202); nil turns forwarding off.
func (*Client) UpdateContact ¶
func (*Client) UpdateLine ¶
UpdateLine changes a line's label / is_active by its line_handle. Pass a props map with "label" and/or "is_active".
func (*Client) UploadMedia ¶
UploadMedia uploads a file (image/video/audio/PDF, max 50 MiB) and returns the public URL to pass as MediaURL in SendMessageParams.
type HistoryMessage ¶
type HistoryMessage struct {
MessageHandle string `json:"message_handle"`
Number string `json:"number"`
Content string `json:"content"`
MediaURL string `json:"media_url"`
Service string `json:"service"`
IsOutbound bool `json:"is_outbound"`
Status string `json:"status"` // DELIVERED | SENT | RECEIVED
DateSent string `json:"date_sent"`
ConversationHandle string `json:"conversation_handle"`
}
HistoryMessage is one row of the message history (both directions).
type ListMessagesParams ¶
type ListMessagesParams struct {
Number string
Direction string // "in" | "out"
LineHandle string
ConversationHandle string
Service string
Since string
Until string
Limit int
Before string
}
ListMessagesParams filters the message history. Before is the cursor: pass NextBefore from the previous page.
type LookupResult ¶
type LookupResult struct {
Number string `json:"number"`
Service string `json:"service"` // iMessage | SMS; empty while pending
Cached bool `json:"cached"`
CheckedAt string `json:"checked_at"`
Status string `json:"status,omitempty"` // "pending" on a 202 — retry shortly
Unresolved bool `json:"unresolved,omitempty"` // Apple gave no verdict; "SMS" is a safe default, not knowledge
}
LookupResult answers "does this number have iMessage?".
type MessageList ¶
type MessageList struct {
Messages []HistoryMessage `json:"messages"`
NextBefore string `json:"next_before"`
}
MessageList is one page of history plus the cursor for the next one.
type Option ¶
type Option func(*Client)
Option customizes the Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (default DefaultBaseURL).
func WithHTTPClient ¶
WithHTTPClient supplies a custom *http.Client.
type OutboundMessage ¶
type OutboundMessage struct {
Status string `json:"status"` // QUEUED | SENT | ERROR
MessageHandle string `json:"message_handle"`
From string `json:"from"`
To json.RawMessage `json:"to"` // one number, or the participant list for group sends
GroupID string `json:"group_id"`
Content string `json:"content"`
MediaURL string `json:"media_url"`
Service string `json:"service"`
RequestedService string `json:"requested_service"` // "SMS" when the daemon was told to skip iMessage
IsOutbound bool `json:"is_outbound"`
ErrorMessage string `json:"error_message"`
DateCreated string `json:"date_created"`
DateUpdated string `json:"date_updated"`
DateSent string `json:"date_sent"`
}
OutboundMessage is the public shape of a queued/sent message.
type SendMessageParams ¶
type SendMessageParams struct {
Number string `json:"number"`
Content string `json:"content,omitempty"`
MediaURL string `json:"media_url,omitempty"` // from UploadMedia, or any public URL
LineHandle string `json:"line_handle,omitempty"` // route via a specific line (see ListLines)
StatusCallback string `json:"status_callback,omitempty"` // POSTed the final status
ScheduledAt string `json:"scheduled_at,omitempty"` // ISO 8601 — deliver later
Service string `json:"service,omitempty"` // "sms" = plain text, no iMessage attempt; "imessage" = default path
}
SendMessageParams describes one outbound message. Content is optional when MediaURL is set.
type WebhookParams ¶
type WebhookParams struct {
URL string `json:"url"`
Events []string `json:"events,omitempty"` // receive | outbound | line_blocked | line_unblocked
Secret string `json:"secret,omitempty"`
}
WebhookParams configures one webhook. Events defaults to every event; Secret enables the X-SMSBridge-Signature HMAC on deliveries.