Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidWebhookEvent(e WebhookEvent) bool
- type Client
- func (c *Client) CheckHealth(ctx context.Context) (HealthResponse, error)
- func (c *Client) DeleteDevice(ctx context.Context, id string) error
- func (c *Client) DeleteWebhook(ctx context.Context, webhookID string) error
- func (c *Client) ExportInbox(ctx context.Context, req MessagesExportRequest) error
- func (c *Client) GenerateToken(ctx context.Context, req TokenRequest) (TokenResponse, error)
- func (c *Client) GetLogs(ctx context.Context, from, to time.Time) ([]LogEntry, error)
- func (c *Client) GetSettings(ctx context.Context) (DeviceSettings, error)
- func (c *Client) GetState(ctx context.Context, messageID string) (MessageState, error)
- func (c *Client) ListDevices(ctx context.Context) ([]Device, error)
- func (c *Client) ListWebhooks(ctx context.Context) ([]Webhook, error)
- func (c *Client) RefreshToken(ctx context.Context, refreshToken string) (TokenResponse, error)
- func (c *Client) RegisterWebhook(ctx context.Context, webhook Webhook) (Webhook, error)
- func (c *Client) ReplaceSettings(ctx context.Context, settings DeviceSettings) (DeviceSettings, error)
- func (c *Client) RevokeToken(ctx context.Context, jti string) error
- func (c *Client) Send(ctx context.Context, message Message, options ...SendOption) (MessageState, error)
- func (c *Client) UpdateSettings(ctx context.Context, settings DeviceSettings) (DeviceSettings, error)
- type Config
- type DataMessage
- type Device
- type DeviceSettings
- type ErrorResponse
- type GetLogsResponse
- type GetMessageResponse
- type GetMessagesResponse
- type HashedMessage
- type HealthCheck
- type HealthChecks
- type HealthResponse
- type HealthStatus
- type LimitPeriod
- type LogEntry
- type LogEntryPriority
- type Message
- type MessagePriority
- type MessageState
- type MessagesExportRequest
- type MessagesProcessingOrder
- type MobileChangePasswordRequest
- type MobileDeviceResponse
- type MobileGetMessagesResponse
- type MobileMessage
- type MobilePatchMessageItem
- type MobilePatchMessageRequest
- type MobileRegisterRequest
- type MobileRegisterResponse
- type MobileUpdateRequest
- type MobileUserCodeResponse
- type ProcessingState
- type PushEventType
- type PushNotification
- type RecipientState
- type SendOption
- type SendOptions
- type SettingsEncryption
- type SettingsGateway
- type SettingsLogs
- type SettingsMessages
- type SettingsPing
- type SettingsWebhooks
- type SimSelectionMode
- type TextMessage
- type TokenRequest
- type TokenResponse
- type UpstreamPushRequest
- type Webhook
- type WebhookEvent
Constants ¶
const ( ProcessingStatePending ProcessingState = "Pending" // Pending ProcessingStateProcessed ProcessingState = "Processed" // Processed (received by device) ProcessingStateSent ProcessingState = "Sent" // Sent ProcessingStateDelivered ProcessingState = "Delivered" // Delivered ProcessingStateFailed ProcessingState = "Failed" // Failed PriorityMinimum MessagePriority = -128 PriorityDefault MessagePriority = 0 PriorityBypassThreshold MessagePriority = 100 // Threshold at which messages bypass limits and delays PriorityMaximum MessagePriority = 127 )
const BASE_URL = BaseURL
Deprecated: BASE_URL is kept for backward compatibility. Use BaseURL instead.
const BaseURL = "https://api.sms-gate.app/3rdparty/v1"
Variables ¶
Functions ¶
func IsValidWebhookEvent ¶ added in v1.1.0
func IsValidWebhookEvent(e WebhookEvent) bool
IsValidWebhookEvent checks if the webhook event is a valid type. It takes a webhook event type and returns true if the event is valid, false otherwise.
Types ¶
type Client ¶
func (*Client) CheckHealth ¶ added in v1.9.0
func (c *Client) CheckHealth(ctx context.Context) (HealthResponse, error)
CheckHealth returns service health status.
func (*Client) DeleteDevice ¶ added in v1.9.0
DeleteDevice removes a device by ID.
func (*Client) DeleteWebhook ¶ added in v1.4.0
DeleteWebhook removes a webhook by ID Returns an error if the deletion fails.
func (*Client) ExportInbox ¶ added in v1.9.0
func (c *Client) ExportInbox(ctx context.Context, req MessagesExportRequest) error
ExportInbox exports messages via webhooks.
func (*Client) GenerateToken ¶ added in v1.10.0
func (c *Client) GenerateToken(ctx context.Context, req TokenRequest) (TokenResponse, error)
GenerateToken generates a new access token with specified scopes and ttl. Returns the generated token details or an error if the request fails.
func (*Client) GetSettings ¶ added in v1.9.0
func (c *Client) GetSettings(ctx context.Context) (DeviceSettings, error)
GetSettings returns current settings.
func (*Client) ListDevices ¶ added in v1.9.0
ListDevices returns registered devices.
func (*Client) ListWebhooks ¶ added in v1.4.0
ListWebhooks returns registered webhooks Returns a slice of Webhook objects or an error if the request fails.
func (*Client) RefreshToken ¶ added in v1.12.0
RefreshToken exchanges a refresh token for a new token pair. Returns the refreshed token details or an error if the request fails.
func (*Client) RegisterWebhook ¶ added in v1.4.0
RegisterWebhook registers or replaces a webhook Returns the registered webhook with server-assigned fields or an error if the request fails.
func (*Client) ReplaceSettings ¶ added in v1.9.0
func (c *Client) ReplaceSettings(ctx context.Context, settings DeviceSettings) (DeviceSettings, error)
ReplaceSettings replaces all settings.
func (*Client) RevokeToken ¶ added in v1.10.0
RevokeToken revokes an access token with the specified jti (token ID). Returns an error if the revocation fails.
func (*Client) Send ¶
func (c *Client) Send(ctx context.Context, message Message, options ...SendOption) (MessageState, error)
Send enqueues a message for sending.
func (*Client) UpdateSettings ¶ added in v1.9.0
func (c *Client) UpdateSettings(ctx context.Context, settings DeviceSettings) (DeviceSettings, error)
UpdateSettings partially updates settings.
type Config ¶
type Config struct {
Client *http.Client // Optional HTTP Client, defaults to `http.DefaultClient`
BaseURL string // Optional base URL, defaults to `https://api.sms-gate.app/3rdparty/v1`
User string // Basic Auth username
Password string // Basic Auth password
Token string // Bearer token, has priority over Basic Auth
}
func (Config) WithBaseURL ¶ added in v1.10.0
WithBaseURL sets the base URL for the API client. If the base URL is empty, it defaults to the constant `BaseURL`. This is useful for setting a custom base URL for the API client.
func (Config) WithBasicAuth ¶ added in v1.10.0
WithBasicAuth sets the Basic Auth credentials for the API client. This is useful for setting custom Basic Auth credentials for the API client. If the user or password is empty, it defaults to an empty string.
func (Config) WithClient ¶ added in v1.10.0
WithClient sets the HTTP client for the API client. If the client is nil, it defaults to `http.DefaultClient`. This is useful for testing or custom HTTP clients.
func (Config) WithJWTAuth ¶ added in v1.10.0
WithJWTAuth sets the Bearer token for the API client. This is useful for setting a custom Bearer token for the API client. If the token is empty, it defaults to an empty string.
type DataMessage ¶ added in v1.8.0
type DataMessage struct {
// Data is the base64-encoded payload.
Data string `json:"data" validate:"required,base64,min=4,max=65535" example:"SGVsbG8gV29ybGQh" format:"byte"`
// Port is the destination port.
Port uint16 `json:"port" validate:"required,min=1,max=65535" example:"53739"`
}
DataMessage represents an SMS message with a binary payload.
Data is the base64-encoded payload.
Port is the destination port.
type Device ¶
type Device struct {
ID string `json:"id" example:"PyDmBQZZXYmyxMwED8Fzy"` // ID
Name string `json:"name" example:"My Device"` // Name
CreatedAt time.Time `json:"createdAt" example:"2020-01-01T00:00:00Z"` // Created at (read only)
UpdatedAt time.Time `json:"updatedAt" example:"2020-01-01T00:00:00Z"` // Updated at (read only)
DeletedAt *time.Time `json:"deletedAt,omitempty" example:"2020-01-01T00:00:00Z"` // Deleted at (read only)
LastSeen time.Time `json:"lastSeen" example:"2020-01-01T00:00:00Z"` // Last seen at (read only)
}
Device represents a device registered on the server.
ID is the device ID, read only.
Name is the device name.
CreatedAt is the time at which the device was created, read only.
UpdatedAt is the time at which the device was last updated, read only.
DeletedAt is the time at which the device was deleted, read only.
LastSeen is the time at which the device was last seen, read only.
type DeviceSettings ¶ added in v1.6.0
type DeviceSettings struct {
// Encryption contains settings related to message encryption.
Encryption *SettingsEncryption `json:"encryption,omitempty"`
// Messages contains settings related to message handling.
Messages *SettingsMessages `json:"messages,omitempty"`
// Ping contains settings related to ping functionality.
Ping *SettingsPing `json:"ping,omitempty"`
// Logs contains settings related to logging.
Logs *SettingsLogs `json:"logs,omitempty"`
// Webhooks contains settings related to webhook functionality.
Webhooks *SettingsWebhooks `json:"webhooks,omitempty"`
// Gateway contains settings related to the gateway.
Gateway *SettingsGateway `json:"gateway,omitempty"`
}
DeviceSettings represents the overall configuration settings for a device.
func (DeviceSettings) Validate ¶ added in v1.6.0
func (s DeviceSettings) Validate() error
type ErrorResponse ¶
type ErrorResponse struct {
Message string `json:"message" example:"An error occurred"` // Error message
Code int32 `json:"code,omitempty"` // Error code
Data any `json:"data,omitempty"` // Error context
}
ErrorResponse represents a response to a request in case of an error.
Message is an error message.
Code is an error code, which is omitted if not specified.
Data is an error context, which is omitted if not specified.
type GetLogsResponse ¶ added in v1.0.2
type GetLogsResponse []LogEntry
type GetMessageResponse ¶ added in v1.9.1
type GetMessageResponse MessageState
type GetMessagesResponse ¶ added in v1.9.2
type GetMessagesResponse []MessageState
type HashedMessage ¶ added in v1.12.2
type HashedMessage struct {
Hash string `json:"hash" validate:"required,sha256" example:"1d4b6e3b1b6e3b1b6e3b1b6e3b1b6e3b1b6e3b1b"`
}
HashedMessage represents an SMS message with a hashed payload.
Hash is the SHA256 hash of the message content (text or data).
type HealthCheck ¶
type HealthCheck struct {
// A human-readable description of the check.
Description string `json:"description,omitempty"`
// Unit of measurement for the observed value.
ObservedUnit string `json:"observedUnit,omitempty"`
// Observed value of the check.
ObservedValue int `json:"observedValue"`
// Status of the check.
// It can be one of the following values: "pass", "warn", or "fail".
Status HealthStatus `json:"status"`
}
HealthCheck represents the result of a health check.
Description is a human-readable description of the check.
ObservedUnit is the unit of measurement for the observed value.
ObservedValue is the observed value of the check.
Status is the status of the check. It can be one of the following values: "pass", "warn", or "fail".
type HealthChecks ¶
type HealthChecks map[string]HealthCheck
HealthChecks is a map of check names to their respective details.
type HealthResponse ¶
type HealthResponse struct {
// Overall status of the application.
// It can be one of the following values: "pass", "warn", or "fail".
Status HealthStatus `json:"status"`
// Version of the application.
Version string `json:"version,omitempty"`
// Release ID of the application.
// It is used to identify the version of the application.
ReleaseID int `json:"releaseId,omitempty"`
// A map of check names to their respective details.
Checks HealthChecks `json:"checks,omitempty"`
}
HealthResponse represents the result of a health check.
Status is the overall status of the application. It can be one of the following values: "pass", "warn", or "fail".
Version is the version of the application.
ReleaseID is the release ID of the application. It is used to identify the version of the application.
Checks is a map of check names to their respective details.
type HealthStatus ¶
type HealthStatus string
const ( HealthStatusPass HealthStatus = "pass" HealthStatusWarn HealthStatus = "warn" HealthStatusFail HealthStatus = "fail" )
type LimitPeriod ¶ added in v1.6.0
type LimitPeriod string
LimitPeriod defines the period for message sending limits.
const ( // Disabled indicates no limit period. Disabled LimitPeriod = "Disabled" // PerMinute sets the limit period to per minute. PerMinute LimitPeriod = "PerMinute" // PerHour sets the limit period to per hour. PerHour LimitPeriod = "PerHour" // PerDay sets the limit period to per day. PerDay LimitPeriod = "PerDay" )
type LogEntry ¶ added in v1.0.2
type LogEntry struct {
// A unique identifier for the log entry.
ID uint64 `json:"id"`
// The priority level of the log entry.
Priority LogEntryPriority `json:"priority"`
// The module or component of the system that generated the log entry.
Module string `json:"module"`
// A message describing the log event.
Message string `json:"message"`
// Additional context information related to the log entry, typically including data relevant to the log event.
Context map[string]any `json:"context"`
// The timestamp when this log entry was created.
CreatedAt time.Time `json:"createdAt" format:"date-time"`
}
LogEntry represents a log entry.
type LogEntryPriority ¶ added in v1.0.2
type LogEntryPriority string
const ( LogEntryPriorityDebug LogEntryPriority = "DEBUG" LogEntryPriorityInfo LogEntryPriority = "INFO" LogEntryPriorityWarn LogEntryPriority = "WARN" LogEntryPriorityError LogEntryPriority = "ERROR" )
type Message ¶
type Message struct {
ID string `json:"id,omitempty" validate:"omitempty,max=36" example:"PyDmBQZZXYmyxMwED8Fzy"` // ID (if not set - will be generated)
DeviceID string `json:"deviceId,omitempty" validate:"omitempty,max=21" example:"PyDmBQZZXYmyxMwED8Fzy"` // Optional device ID for explicit selection
Message string `json:"message,omitempty" validate:"omitempty,max=65535" example:"Hello World!"` // Message content (deprecated, use TextMessage instead)
TextMessage *TextMessage `json:"textMessage,omitempty" validate:"omitempty"` // Text message
DataMessage *DataMessage `json:"dataMessage,omitempty" validate:"omitempty"` // Data message
PhoneNumbers []string `json:"phoneNumbers" validate:"required,min=1,max=100,dive,required,min=1,max=128" example:"79990001234"` // Recipients (phone numbers)
IsEncrypted bool `json:"isEncrypted,omitempty" example:"true"` // Is encrypted
SimNumber *uint8 `json:"simNumber,omitempty" validate:"omitempty,min=1,max=3" example:"1"` // SIM card number (1-3), if not set - default SIM will be used
WithDeliveryReport *bool `json:"withDeliveryReport,omitempty" example:"true"` // With delivery report
Priority MessagePriority `json:"priority,omitempty" validate:"omitempty,min=-128,max=127" example:"0" default:"0"` // Priority, messages with values greater than `99` will bypass limits and delays
TTL *uint64 `json:"ttl,omitempty" validate:"omitempty,min=5" example:"86400"` // Time to live in seconds (conflicts with `ValidUntil`)
ValidUntil *time.Time `json:"validUntil,omitempty" example:"2020-01-01T00:00:00Z"` // Valid until (conflicts with `TTL`)
}
Message represents an SMS message.
ID is the message ID (if not set - will be generated). DeviceID is the optional device ID for explicit selection. Message is the message content (deprecated, use TextMessage instead). TextMessage is the text message. DataMessage is the data message. PhoneNumbers is the list of phone numbers. IsEncrypted is true if the message is encrypted. SimNumber is the SIM card number (1-3), if not set - default SIM will be used. WithDeliveryReport is true if the message should request a delivery report. Priority is the priority of the message, messages with values greater than `99` will bypass limits and delays. TTL is the time to live in seconds (conflicts with `ValidUntil`). ValidUntil is the time until the message is valid (conflicts with `TTL`).
func (*Message) GetDataMessage ¶ added in v1.8.0
func (m *Message) GetDataMessage() *DataMessage
GetDataMessage returns the DataMessage, if it was set explicitly, or nil otherwise.
func (*Message) GetTextMessage ¶ added in v1.8.0
func (m *Message) GetTextMessage() *TextMessage
GetTextMessage returns the TextMessage, if it was set explicitly, or constructs it from the deprecated Message field and returns it. If neither TextMessage nor Message are set, returns nil.
type MessagePriority ¶ added in v1.5.7
type MessagePriority int8
MessagePriority represents the priority of a message.
type MessageState ¶
type MessageState struct {
ID string `json:"id" validate:"required,max=36" example:"PyDmBQZZXYmyxMwED8Fzy"` // Message ID
DeviceID string `json:"deviceId" validate:"required,max=21" example:"PyDmBQZZXYmyxMwED8Fzy"` // Device ID
State ProcessingState `json:"state" validate:"required" example:"Pending"` // State
IsHashed bool `json:"isHashed" example:"false"` // Hashed
IsEncrypted bool `json:"isEncrypted" example:"false"` // Encrypted
Recipients []RecipientState `json:"recipients" validate:"required,min=1,dive"` // Recipients states
States map[string]time.Time `json:"states"` // History of states
TextMessage *TextMessage `json:"textMessage,omitempty"` // Present only when `includeContent=true` and the message type is text.
DataMessage *DataMessage `json:"dataMessage,omitempty"` // Present only when `includeContent=true` and the message type is data.
HashedMessage *HashedMessage `json:"hashedMessage,omitempty"` // Hashed message content, if isHashed is true
}
MessageState represents the state of a message.
MessageState is a struct used to communicate the state of a message between the client and the server. It contains the message ID, device ID, state, and hashed and encrypted flags. Additionally, it contains a slice of RecipientState, representing the state of each recipient, and a map of states, representing the history of states for the message.
func (MessageState) Validate ¶
func (m MessageState) Validate() error
type MessagesExportRequest ¶ added in v1.3.0
type MessagesExportRequest struct {
// DeviceID is the ID of the device to export messages for.
DeviceID string `json:"deviceId" example:"PyDmBQZZXYmyxMwED8Fzy" validate:"required,max=21"`
// Since is the start of the time range to export.
Since time.Time `json:"since" example:"2024-01-01T00:00:00Z" validate:"required,ltefield=Until"`
// Until is the end of the time range to export.
Until time.Time `json:"until" example:"2024-01-01T23:59:59Z" validate:"required,gtefield=Since"`
}
MessagesExportRequest represents a request to export messages.
DeviceID is the ID of the device to export messages for.
Since is the start of the time range to export.
Until is the end of the time range to export.
type MessagesProcessingOrder ¶ added in v1.9.3
type MessagesProcessingOrder string
const ( // LIFO is the last-in-first-out order. Newer messages are processed first. LIFO MessagesProcessingOrder = "LIFO" // FIFO is the first-in-first-out order. Newer messages are processed last. FIFO MessagesProcessingOrder = "FIFO" )
type MobileChangePasswordRequest ¶ added in v1.2.0
type MobileChangePasswordRequest struct {
CurrentPassword string `json:"currentPassword" validate:"required" example:"cp2pydvxd2zwpx"` // Current password
NewPassword string `json:"newPassword" validate:"required,min=14" example:"cp2pydvxd2zwpx"` // New password, at least 14 characters
}
MobileChangePasswordRequest represents a request to change the password of a mobile device.
The CurrentPassword field contains the current password of the device.
The NewPassword field contains the new password of the device. It must be at least 14 characters long.
type MobileDeviceResponse ¶ added in v1.1.0
type MobileDeviceResponse struct {
// Device information, empty if device is not registered on the server
Device *Device `json:"device,omitempty"`
// External IP address
ExternalIP string `json:"externalIp,omitempty"`
}
MobileDeviceResponse contains device information and external IP address.
Device is empty if the device is not registered on the server.
type MobileGetMessagesResponse ¶ added in v1.5.7
type MobileGetMessagesResponse []MobileMessage
MobileGetMessagesResponse represents a collection of messages for mobile clients.
type MobileMessage ¶ added in v1.5.7
type MobileMessage struct {
Message // Message information
CreatedAt time.Time `json:"createdAt" example:"2020-01-01T00:00:00Z"` // Message creation time
}
MobileMessage represents a message for mobile clients.
It contains the message information and message creation time.
type MobilePatchMessageItem ¶ added in v1.9.1
type MobilePatchMessageItem struct {
// Message ID
ID string `json:"id" validate:"required,max=36" example:"PyDmBQZZXYmyxMwED8Fzy"`
// State
State ProcessingState `json:"state" validate:"required" example:"Pending"`
// Recipients states
Recipients []RecipientState `json:"recipients" validate:"required,min=1,dive"`
// History of states
States map[string]time.Time `json:"states"`
}
MobilePatchMessageItem represents a single message patch request.
type MobilePatchMessageRequest ¶ added in v1.9.1
type MobilePatchMessageRequest []MobilePatchMessageItem
MobilePatchMessageRequest represents a request to patch messages.
type MobileRegisterRequest ¶
type MobileRegisterRequest struct {
// Name of the device (optional)
// +optional
Name *string `json:"name,omitempty" validate:"omitempty,max=128" example:"Android Phone"`
// FCM token of the device (optional)
// +optional
PushToken *string `json:"pushToken" validate:"omitempty,max=256" example:"gHz-T6NezDlOfllr7F-Be"`
}
MobileRegisterRequest represents a request to register a mobile device.
The Name field contains the name of the device, and the PushToken field contains the FCM token of the device.
type MobileRegisterResponse ¶
type MobileRegisterResponse struct {
//nolint:revive,staticcheck // backward compatibility
Id string `json:"id" example:"QslD_GefqiYV6RQXdkM6V"` // New device ID
Token string `json:"token" example:"bP0ZdK6rC6hCYZSjzmqhQ"` // Device access token
Login string `json:"login" example:"VQ4GII"` // User login
Password string `json:"password,omitempty" example:"cp2pydvxd2zwpx"` // User password, empty for existing user
}
MobileRegisterResponse contains device registration response.
Id is the new device ID. Token is the device access token. Login is the user login. Password is the user password, empty for existing user.
type MobileUpdateRequest ¶
type MobileUpdateRequest struct {
//nolint:revive,staticcheck // backward compatibility
Id string `json:"id" example:"QslD_GefqiYV6RQXdkM6V"` // Device ID
PushToken string `json:"pushToken" example:"gHz-T6NezDlOfllr7F-Be" validate:"omitempty,max=256"` // FCM token of the device (optional)
}
MobileUpdateRequest represents a request to update a mobile device.
The Id field contains the device ID.
The PushToken field contains the FCM token of the device.
type MobileUserCodeResponse ¶ added in v1.5.6
type MobileUserCodeResponse struct {
Code string `json:"code" example:"123456"` // One-time code sent to the user
ValidUntil time.Time `json:"validUntil" example:"2020-01-01T00:00:00Z"` // One-time code expiration time
}
MobileUserCodeResponse represents a one-time code response for mobile clients.
Code is the one-time code sent to the user. ValidUntil is the one-time code expiration time.
type ProcessingState ¶
type ProcessingState string
ProcessingState represents the state of a message.
type PushEventType ¶ added in v1.0.1
type PushEventType string
PushEventType is the type of a push notification.
const ( PushMessageEnqueued PushEventType = "MessageEnqueued" // Message is enqueued. PushWebhooksUpdated PushEventType = "WebhooksUpdated" // Webhooks are updated. PushMessagesExportRequested PushEventType = "MessagesExportRequested" // Messages export is requested. PushSettingsUpdated PushEventType = "SettingsUpdated" // Settings are updated. )
type PushNotification ¶
type PushNotification struct {
Token string `` // The token of the device that receives the notification.
/* 133-byte string literal not displayed */
Event PushEventType `` // The type of event.
/* 127-byte string literal not displayed */
Data map[string]string `json:"data"` // The additional data associated with the event.
}
PushNotification represents a push notification.
The token of the device that receives the notification.
type RecipientState ¶
type RecipientState struct {
PhoneNumber string `json:"phoneNumber" validate:"required,min=1,max=128" example:"79990001234"` // Phone number or first 16 symbols of SHA256 hash
State ProcessingState `json:"state" validate:"required" example:"Pending"` // State
Error *string `json:"error,omitempty" example:"timeout"` // Error (for `Failed` state)
}
RecipientState represents the state of a recipient.
RecipientState is a struct used to communicate the state of a recipient between the client and the server. It contains the phone number or first 16 symbols of the SHA256 hash, state, and error information.
type SendOption ¶ added in v1.9.0
type SendOption func(*SendOptions)
func WithDeviceActiveWithin ¶ added in v1.9.0
func WithDeviceActiveWithin(hours uint) SendOption
WithDeviceActiveWithin returns a SendOption that filters devices that have been active within the given number of hours.
func WithSkipPhoneValidation ¶ added in v1.9.0
func WithSkipPhoneValidation(skipPhoneValidation bool) SendOption
WithSkipPhoneValidation returns a SendOption that disables phone number validation for messages. Validation is enabled by default.
type SendOptions ¶ added in v1.9.0
type SendOptions struct {
// contains filtered or unexported fields
}
func (*SendOptions) Apply ¶ added in v1.9.0
func (o *SendOptions) Apply(options ...SendOption) *SendOptions
func (*SendOptions) ToURLValues ¶ added in v1.9.0
func (o *SendOptions) ToURLValues() url.Values
ToURLValues returns the SendOptions as a URL query string in the form of url.Values. It includes only the options that have been set.
type SettingsEncryption ¶ added in v1.6.0
type SettingsEncryption struct {
// Passphrase is the encryption passphrase. If nil or empty, encryption is disabled. Must not be used with Cloud Server.
Passphrase *string `json:"passphrase,omitempty" validate:"omitempty,isdefault"`
}
SettingsEncryption contains settings related to message encryption.
type SettingsGateway ¶ added in v1.10.1
type SettingsGateway struct {
// CloudURL is the URL of the cloud server. Must not be used with Cloud Server.
CloudURL *string `json:"cloud_url,omitempty" validate:"omitempty,isdefault,url"`
// PrivateToken is the auth token for the private server. Must not be used with Cloud Server.
PrivateToken *string `json:"private_token,omitempty" validate:"omitempty,isdefault"`
// NotificationChannel is the way device receives notifications.
NotificationChannel *string `json:"notification_channel,omitempty" validate:"omitempty,oneof=AUTO SSE_ONLY"`
}
SettingsGateway contains settings related to the gateway.
type SettingsLogs ¶ added in v1.6.0
type SettingsLogs struct {
// LifetimeDays is the number of days to retain logs.
// Must be at least 1 when provided.
LifetimeDays *int `json:"lifetime_days,omitempty" validate:"omitempty,min=1"`
}
SettingsLogs contains settings related to logging.
type SettingsMessages ¶ added in v1.6.0
type SettingsMessages struct {
// SendIntervalMin is the minimum interval between message sends (in seconds).
// Must be at least 1 when provided.
SendIntervalMin *int `json:"send_interval_min,omitempty" validate:"omitempty,min=1"`
// SendIntervalMax is the maximum interval between message sends (in seconds).
// Must be at least 1 when provided and greater than or equal to SendIntervalMin.
SendIntervalMax *int `json:"send_interval_max,omitempty" validate:"omitempty,min=1"`
// LimitPeriod defines the period for message sending limits.
// Valid values are "Disabled", "PerMinute", "PerHour", or "PerDay".
LimitPeriod *LimitPeriod `json:"limit_period,omitempty" validate:"omitempty,oneof=Disabled PerMinute PerHour PerDay"`
// LimitValue is the maximum number of messages allowed per limit period.
// Must be at least 1 when provided.
LimitValue *int `json:"limit_value,omitempty" validate:"omitempty,min=1"`
// SimSelectionMode defines how SIM cards are selected for sending messages.
// Valid values are "OSDefault", "RoundRobin", or "Random".
SimSelectionMode *SimSelectionMode `json:"sim_selection_mode,omitempty" validate:"omitempty,oneof=OSDefault RoundRobin Random"`
// LogLifetimeDays is the number of days to retain message logs.
// Must be at least 1 when provided.
LogLifetimeDays *int `json:"log_lifetime_days,omitempty" validate:"omitempty,min=1"`
// MessagesProcessingOrder defines the order in which messages are processed.
// Valid values are "LIFO" or "FIFO".
ProcessingOrder *MessagesProcessingOrder `json:"processing_order,omitempty" validate:"omitempty,oneof=LIFO FIFO"`
}
SettingsMessages contains settings related to message handling.
func (SettingsMessages) Validate ¶ added in v1.6.0
func (s SettingsMessages) Validate() error
type SettingsPing ¶ added in v1.6.0
type SettingsPing struct {
// IntervalSeconds is the interval between ping requests (in seconds).
// Must be at least 1 when provided.
IntervalSeconds *int `json:"interval_seconds,omitempty" validate:"omitempty,min=1"`
}
SettingsPing contains settings related to ping functionality.
type SettingsWebhooks ¶ added in v1.6.0
type SettingsWebhooks struct {
// InternetRequired indicates whether internet access is required for webhooks.
InternetRequired *bool `json:"internet_required,omitempty"`
// RetryCount is the number of times to retry failed webhook deliveries.
// Must be at least 1 when provided.
RetryCount *int `json:"retry_count,omitempty" validate:"omitempty,min=1"`
// SigningKey is the secret key used for signing webhook payloads. Must not be used with Cloud Server.
SigningKey *string `json:"signing_key,omitempty" validate:"omitempty,isdefault"`
}
SettingsWebhooks contains settings related to webhook functionality.
type SimSelectionMode ¶ added in v1.6.0
type SimSelectionMode string
SimSelectionMode defines how SIM cards are selected for sending messages.
const ( // OSDefault uses the OS default SIM selection. OSDefault SimSelectionMode = "OSDefault" // RoundRobin cycles through SIM cards. RoundRobin SimSelectionMode = "RoundRobin" // Random selects SIM cards randomly. Random SimSelectionMode = "Random" )
type TextMessage ¶ added in v1.8.0
type TextMessage struct {
// Text is the message text.
Text string `json:"text" validate:"required,min=1,max=65535" example:"Hello World!"`
}
TextMessage represents an SMS message with a text body.
Text is the message text.
type TokenRequest ¶ added in v1.10.0
type TokenRequest struct {
TTL uint64 `json:"ttl,omitempty"` // lifetime of the access token in seconds
Scopes []string `json:"scopes" validate:"required,min=1,dive,required"` // scopes for which the access token is valid
}
TokenRequest represents a request to obtain an access token.
The TTL field defines the requested lifetime of the access token in seconds. A value of 0 will result in a token with the maximum allowed lifetime.
The Scopes field defines the scopes for which the access token is valid. At least one scope must be provided.
type TokenResponse ¶ added in v1.10.0
type TokenResponse struct {
ID string `json:"id"` // unique identifier for the access token
TokenType string `json:"token_type"` // type of the access token
AccessToken string `json:"access_token"` // actual access token
RefreshToken string `json:"refresh_token,omitempty"` // refresh token
ExpiresAt time.Time `json:"expires_at" format:"date-time"` // time at which the access token is no longer valid
}
TokenResponse represents a response to a TokenRequest.
The ID field contains a unique identifier for the access token.
The TokenType field contains the type of the access token, which is "Bearer".
The AccessToken field contains the actual access token.
The RefreshToken field contains the refresh token.
The ExpiresAt field contains the time at which the access token is no longer valid.
type UpstreamPushRequest ¶
type UpstreamPushRequest = []PushNotification
UpstreamPushRequest represents a request to push notifications.
type Webhook ¶ added in v1.0.1
type Webhook struct {
ID string `json:"id,omitempty" validate:"max=36" example:"123e4567-e89b-12d3-a456-426614174000"` // The unique identifier of the webhook.
DeviceID *string `json:"deviceId" validate:"omitempty,max=21" example:"PyDmBQZZXYmyxMwED8Fzy"` // The unique identifier of the device the webhook is associated with.
URL string `json:"url" validate:"required,http_url" example:"https://example.com/webhook"` // The URL the webhook will be sent to.
Event WebhookEvent `json:"event" validate:"required" example:"sms:received"` // The type of event the webhook is triggered for.
}
Webhook represents a webhook configuration.
ID is the unique identifier of the webhook.
DeviceID is the unique identifier of the device the webhook is associated with.
URL is the URL the webhook will be sent to.
Event is the type of event the webhook is triggered for.
type WebhookEvent ¶ added in v1.0.1
type WebhookEvent = string
const ( WebhookEventSmsReceived WebhookEvent = "sms:received" // Triggered when an SMS is received. WebhookEventSmsDataReceived WebhookEvent = "sms:data-received" // Triggered when a data SMS is received. WebhookEventSmsSent WebhookEvent = "sms:sent" // Triggered when an SMS is sent. WebhookEventSmsDelivered WebhookEvent = "sms:delivered" // Triggered when an SMS is delivered. WebhookEventSmsFailed WebhookEvent = "sms:failed" // Triggered when an SMS processing fails. WebhookEventSystemPing WebhookEvent = "system:ping" // Triggered when the device pings the server. WebhookEventMmsReceived WebhookEvent = "mms:received" // Triggered when an MMS is received. WebhookEventMmsDownloaded WebhookEvent = "mms:downloaded" // Triggered when an MMS is downloaded. )
func WebhookEventTypes ¶ added in v1.4.0
func WebhookEventTypes() []WebhookEvent
WebhookEventTypes returns a slice of all supported webhook event types.