Documentation
¶
Overview ¶
Package africastalking provides a simple wrapper for sending SMS via Africa's Talking API.
Example usage:
import ( "log" "github.com/tech-kenya/africastalkingsms" ) func main() { apiKey = os.Getenv("atApiKey") username = os.Getenv("atUserName") atShortCode = os.Getenv("atShortCode") sandbox = os.Getenv("sandboxEnv") client := africastalking.NewSMSClient(apiKey, username, atShortCode, sandbox) if err != nil { log.Fatal(err) } resp, err := client.SendSMS("+254712345678", "Hello from Africa's Talking!") if err != nil{ log.Fatal(err) } log.Println(resp) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SMSClient ¶
type SMSClient struct { APIKey string Username string ShortCode string HTTPClient HTTPClient // contains filtered or unexported fields }
SMSClient holds API credentials
func NewSMSClient ¶
NewSMSClient initializes a new Africa's Talking SMS client. ensure .env has the below variables
func (*SMSClient) SendSMS ¶
func (c *SMSClient) SendSMS(recipient, message string) (*SMSResponse, error)
SendSMS sends an SMS message to the specified recipient.
Example:
err := client.SendSMS("+254712345678", "Hello!") if err != nil { log.Fatal(err) }
Parameters: - recipient: Phone number of the recipient in international format (e.g., +254712345678) - message: The text message content
type SMSRequest ¶
Request payload struct
type SMSResponse ¶
type SMSResponse struct { SMSMessageData struct { Message string `json:"message"` Recipients []struct { Number string `json:"number"` Cost string `json:"cost"` Status string `json:"status"` StatusCode int `json:"statusCode"` MessageID string `json:"messageId"` } `json:"recipients"` } `json:"SMSMessageData"` }
Response struct for JSON parsing
Click to show internal directories.
Click to hide internal directories.