A Go client library for interacting with the Puzzel SMS Gateway API. This library provides a simple and efficient way to send SMS messages through Puzzel's messaging service.
- Send single or multiple SMS messages in one batch
- Comprehensive message configuration options (originator, type, scheduling, etc.)
- Flexible client options with functional options pattern
- Support for Strex and advanced SMS features
- Scheduled message delivery with time windows
- Context support for request cancellation and timeouts
- Error handling for API responses
- Thread-safe client implementation
To use this library in your Go project, run:
go get github.com/ezspot/puzzel-smsgw-client
package main
import (
"context"
"log"
"time"
smsgw "github.com/ezspot/puzzel-smsgw-client"
)
func main() {
// Initialize client with your Puzzel credentials
client := smsgw.NewClient(
"https://api.puzzel.com", // Puzzel API base URL
1000, // Service ID
"your-username", // Your Puzzel username
"your-password", // Your Puzzel password
// Optional client options
smsgw.WithBatchReference("my-batch-reference"),
smsgw.WithTimeout(15*time.Second),
)
// Prepare your message(s)
messages := []smsgw.Message{
{
Recipient: "+4712345678",
Content: "Hello from Puzzel!",
Settings: &smsgw.Settings{
OriginatorSettings: &smsgw.OriginatorSettings{
Originator: "Puzzel",
OriginatorType: "ALPHANUMERIC",
},
},
},
}
// Create a context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Send messages using the simplified Send method
response, err := client.Send(ctx, messages)
if err != nil {
log.Fatalf("Error sending messages: %v", err)
}
// Or send with an explicit batch reference
// response, err := client.SendMessages(ctx, messages, "batch-123")
log.Printf("Send response: %+v", response)
}
The Message
struct has the following fields:
Recipient
(string): The phone number of the message recipient (in international format)Content
(string): The message contentPrice
(int): Optional price for the messageClientReference
(string): Optional client-side reference IDSettings
(*Settings): Optional message settings
The Settings
struct includes:
Priority
(int): Message priority levelValidity
(int): Message validity periodDifferentiator
(string): Custom differentiator for message groupingAge
(int): Age restriction for contentNewSession
(bool): Whether to create a new sessionSessionID
(string): ID for an existing sessionInvoiceNode
(string): Invoice node for billingAutoDetectEncoding
(bool): Whether to auto-detect message encodingOriginatorSettings
: Configuration for the message senderOriginator
: The sender ID or phone numberOriginatorType
: Type of originator (e.g., "ALPHANUMERIC", "NUMERIC")
GasSettings
: Configuration for GAS (Gateway Application Services)ServiceCode
: The service codeDescription
: Optional service description
SendWindow
: Configuration for scheduled message deliveryStartDate
: Start date in YYYY-MM-DD formatStopDate
: Optional end date in YYYY-MM-DD formatStartTime
: Start time in HH:MM:SS formatStopTime
: Optional end time in HH:MM:SS format
Parameter
: Additional configuration parametersBusinessModel
: Business model identifierDcs
: Data coding schemeUdh
: User data headerPid
: Protocol identifierFlash
: Whether message is a flash SMSParsingType
: Content parsing typeSkipCustomerReportDelivery
: Whether to skip delivery reports- Various Strex-related parameters for payment services
The library returns standard Go errors for network and API-related issues. The SendMessages
function returns a SmsGatewayResponse
that includes detailed information about the operation's result.
The client supports functional options for flexible configuration:
// Create a client with custom options
client := smsgw.NewClient(
"https://api.puzzel.com",
1000,
"username",
"password",
// Optional configurations
smsgw.WithBatchReference("my-default-batch"),
smsgw.WithTimeout(15*time.Second),
)
Available options:
WithBatchReference(ref string)
: Set a default batch reference for all requestsWithTimeout(duration time.Duration)
: Set a custom HTTP client timeoutWithHTTPClient(client *http.Client)
: Use a custom HTTP client
See the example/send_sms.go
file for comprehensive examples including:
- Basic message sending
- Advanced message configuration
- Custom client options
- Scheduled message delivery
- Parameter configuration
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please contact Puzzel support or open an issue in the GitHub repository.