Skip to main content

Go SDK

License: MIT

Golang client for notify.africa: Seamlessly integrate SMS and Email communications in your Go applications.

Features

  • Send SMS & Email
  • Batch & Single messaging
  • Structured error handling
  • Configuration via environment variables
  • Override base URLs for testing/staging/production

Installation

Install via go get:

# Preferred (repository org)
go get github.com/iPFSoftwares/notify-africa-go

# If the module path has not been updated yet, use:
# go get github.com/tacherasasi/notify-africa-go

Configuration

Set credentials and optional URLs via environment variables:

export SMS_APIKEY=your_sms_api_key              # Required for SMS
export SMS_SENDER_ID=your_sender_id # SMS sender name/ID
export SMS_URL=https://api.notify.africa/api/v1/api/messages/batch # Optional: override default SMS URL
export EMAIL_APIKEY=your_email_api_key # Required for Email

You may also pass API keys directly when creating clients (not recommended for production).

Quick Start (SMS)

package main

import (
"context"
"log"
"os"
"time"

"github.com/iPFSoftwares/notify-africa-go/client"
// If the module path differs, use: "github.com/tacherasasi/notify-africa-go/client"
)

func main() {
// Load configuration from environment
cfg := client.Config{
SMSApiKey: os.Getenv("SMS_APIKEY"),
EmailApiKey: os.Getenv("EMAIL_APIKEY"),
}
c := client.NewClient(cfg)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// Optionally override SMS base URL (strip the endpoint path to get the base)
if smsURL := os.Getenv("SMS_URL"); smsURL != "" {
// Expecting SMS_URL like: https://api.notify.africa/api/v1/api/messages/batch
// Base should be: https://api.notify.africa
base := smsURL[:len(smsURL)-len("/api/v1/api/messages/batch")]
c.SMS.SetBaseURL(base)
}

senderID := os.Getenv("SMS_SENDER_ID")
to := []string{"255686477074"}

batchResp, err := c.SMS.SendBatchSMS(ctx, to, "Test SMS from Notify Africa Go!", senderID)
if err != nil {
log.Fatalf("Test SMS error: %v", err)
}
log.Printf(
"Test SMS sent! Status: %d, Message: %s, Sent: %d, Credits: %d, Balance: %d",
batchResp.Status, batchResp.Message, batchResp.Data.MessageCount,
batchResp.Data.CreditsDeducted, batchResp.Data.Balance,
)
}

Direct Package Usage

For advanced/custom use cases, import individual packages:

import (
"os"
"github.com/iPFSoftwares/notify-africa-go/sms"
"github.com/iPFSoftwares/notify-africa-go/email"
// Or use the `tacherasasi` module path if that is what your version uses
)

// SMS Setup
smsClient := sms.NewClient(os.Getenv("SMS_APIKEY"))
smsClient.SetBaseURL("https://api.notify.africa") // Optional custom base URL
// smsClient.SendBatchSMS(...) or smsClient.SendSingleSMS(...)

// Email Setup
emailClient := email.NewClient(os.Getenv("EMAIL_APIKEY"))
emailClient.SetBaseURL("https://api.notify.africa/v2") // Optional custom base URL
// emailClient.Send(...)

API Reference (summary)

Client Initialization

  • client.NewClient(config) → returns a new Client.
    • Config supports SMSApiKey and EmailApiKey fields.

SMS Methods

  • SendBatchSMS(ctx, recipients, message, senderID) → send to multiple numbers.
  • SendSingleSMS(ctx, recipient, message, senderID) → send to one number.

Email Methods

  • Send(ctx, recipients, subject, body) → send an email to one or more recipients.

Optional: SetBaseURL

  • Adjust base URLs for different environments.
smsClient.SetBaseURL("https://api.notify.africa")
emailClient.SetBaseURL("https://api.notify.africa/v2")

Best Practices

  • Store API keys in environment variables (not in code).
  • Use context.Context for timeouts/cancellations.
  • Centralize and monitor error logging in production.

Troubleshooting

  • Invalid API key: verify env vars or secrets store.
  • Endpoint errors: ensure correct base URL for your environment/region.
  • Rate limits: avoid bursts; batch where possible.

Contributing

PRs and issues are welcome! See the repository and open an issue/PR with your proposal.

License

MIT License. See LICENSE in the repository.

Support