- Table of Contents
- About The Project
- Features
- Getting Started
- Usage
- Configuration
- API Coverage
- Contributing
- License
- Contact
client-go provides typed clients for the SMSGate ecosystem:
smsgateway- client for the SMSGate 3rd-party API (messages, inbox, devices, health, logs, settings, webhooks, and token lifecycle).ca- client for the SMSGate Certificate Authority service (submit CSRs and poll their status).rest- shared low-level HTTP handling used by both clients.
The library supports Basic authentication (user + password) and Bearer token authentication. A token, when set, takes priority over Basic credentials.
The library is built on the Go standard library only and has zero runtime dependencies.
- Send text and data SMS messages, cancel pending messages, and track per-message and per-recipient state.
- List messages with filtering, pagination, content inclusion, and sorting.
- Read incoming messages from the device inbox and trigger inbox refreshes.
- List and delete registered devices.
- Check API health and retrieve device log entries.
- Read, partially update, and fully replace device settings.
- Register, list, and delete webhooks, with typed event constants and webhook payload types.
- Generate, refresh, and revoke API tokens with scopes and TTL.
- Submit Certificate Signing Requests and poll CSR status (
webhookandprivate_servertypes). - Inject a custom
http.Clientand override the base URL for testing or private deployments. - Classify API errors with
errors.Isand the sentinel errors from therestpackage.
- Go 1.22 or newer (see
go.mod). - An SMSGate account with device credentials (username/password) or an API token.
go get github.com/android-sms-gateway/client-gopackage main
import (
"context"
"log"
"os"
"github.com/android-sms-gateway/client-go/smsgateway"
)
func main() {
ctx := context.Background()
client := smsgateway.NewClient(smsgateway.Config{
User: os.Getenv("ASG_USERNAME"),
Password: os.Getenv("ASG_PASSWORD"),
// or use Token: os.Getenv("ASG_TOKEN"),
})
state, err := client.Send(ctx, smsgateway.Message{
TextMessage: &smsgateway.TextMessage{Text: "Hello from Go"},
PhoneNumbers: []string{
"+15555550100",
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("message queued: %s", state.ID)
}Send accepts optional SendOption values, for example smsgateway.WithSkipPhoneValidation(true) and smsgateway.WithDeviceActiveWithin(24).
limit := 50
inbox, total, err := client.ListInboxMessages(ctx, smsgateway.ListInboxOptions{
Limit: &limit,
})
if err != nil {
log.Fatal(err)
}
log.Printf("%d messages of %d total", len(inbox), total)ListMessages follows the same pattern for outgoing messages and returns the total count from the X-Total-Count response header.
package main
import (
"context"
"log"
"github.com/android-sms-gateway/client-go/ca"
)
func main() {
ctx := context.Background()
client := ca.NewClient()
resp, err := client.PostCSR(ctx, ca.PostCSRRequest{
Type: ca.CSRTypeWebhook,
Content: "-----BEGIN CERTIFICATE REQUEST-----...",
})
if err != nil {
log.Fatal(err)
}
log.Printf("request id: %s, status: %s", resp.RequestID, resp.Status)
status, err := client.GetCSRStatus(ctx, resp.RequestID)
if err != nil {
log.Fatal(err)
}
log.Printf("CSR status: %s", status.Status.Description())
}API failures are wrapped in sentinel errors. Use errors.Is with the predicates from the rest package to react to failure classes:
import (
"errors"
"github.com/android-sms-gateway/client-go/rest"
)
_, err := client.Send(ctx, msg)
switch {
case errors.Is(err, rest.ErrBadRequest):
// 400: message payload rejected
case errors.Is(err, rest.ErrConflict):
// 409: conflicts with current state
case errors.Is(err, rest.ErrServer):
// 5xx: service unavailable
default:
// other client or transport errors
}The library reads no environment variables; credentials and options are set on the config structs in code.
| Field | Type | Default | Description |
|---|---|---|---|
Client |
*http.Client |
http.DefaultClient |
HTTP client used for requests |
BaseURL |
string |
https://api.sms-gate.app/3rdparty/v1 |
API base URL (constant BaseURL) |
User |
string |
empty | Basic auth username |
Password |
string |
empty | Basic auth password |
Token |
string |
empty | Bearer token, takes priority over Basic auth |
Chained helpers are available for the same fields: Config.WithClient, Config.WithBaseURL, Config.WithBasicAuth(user, password), and Config.WithJWTAuth(token).
The CA client is configured with functional options:
| Option | Description |
|---|---|
WithClient |
Sets the HTTP client (defaults to http.DefaultClient) |
WithBaseURL |
Sets the API base URL (defaults to https://ca.sms-gate.app/api/v1) |
Override BaseURL (or use WithBaseURL) to point the clients at a private deployment or a mock server:
client := smsgateway.NewClient(smsgateway.Config{
Token: os.Getenv("ASG_TOKEN"),
BaseURL: "https://example.com/3rdparty/v1",
})Endpoint semantics and payload details: https://api.sms-gate.app/
| Area | Methods |
|---|---|
| Messages | Send, CancelMessage, GetState, ListMessages |
| Inbox | ListInboxMessages, RefreshInbox (ExportInbox is deprecated) |
| Devices | ListDevices, DeleteDevice |
| Health | CheckHealth |
| Logs | GetLogs |
| Settings | GetSettings, UpdateSettings, ReplaceSettings |
| Webhooks | ListWebhooks, RegisterWebhook, DeleteWebhook, plus event constants in smsgateway |
| Tokens | GenerateToken, RefreshToken, RevokeToken |
Typed webhook payloads (for example PushNotification, MmsReceivedPayload, SmsBatchReceivedPayload) live in the smsgateway package. The smsgateway/webhooks subpackage exists only as a deprecated compatibility alias.
| Area | Methods |
|---|---|
| CSR | PostCSR, GetCSRStatus |
Contributions are welcome. Please open an issue to discuss major changes before submitting a pull request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/my-change). - Commit your changes (
git commit -m 'Describe change'). - Push to your branch and open a pull request against
master.
Pull requests are checked by CI (see .github/workflows/go.yml): golangci-lint and go test -race with coverage, reported to Codecov.
Run the same checks locally:
make lint
make test
make coverage
make benchmarkmake help lists all available targets.
Distributed under the Apache License 2.0. See LICENSE for more information.