Skip to Content
SDKsGoLessons

Lessons

Practical patterns to apply on day one.

1. Construct the client once

Build your client at startup and reuse it across handlers — it handles connection reuse, retries, and backoff for you.

client := sendafrica.NewClient(os.Getenv("SENDAFRICA_API_KEY")) http.HandleFunc("/send", sendHandler(client))

2. Send safely: idempotency keys

_, err := client.SMS.Send(ctx, sendafrica.SendSMSRequest{ To: "0712345678", Message: "Order #42 confirmed", }, sendafrica.RequestOptions{IdempotencyKey: fmt.Sprintf("order:%d", orderID)})

If a retry fires, the API replays the stored result instead of sending twice.

3. Double-check emoji pricing

info := client.SMS.Analyze("Thanks 🙏") // UCS-2, may cost more

Analyze before you send — see SMS Calculator.

4. React to delivery, not to send

Update order state in your webhook handler, not after SMS.Send. Deduplicate on (MessageID, Type). See Webhooks.

5. Pick the right bulk tool

NeedUse
One message → many (≤100)client.SMS.Bulk
Different messages → manyclient.SMS.SendMany with RateLimitPerSec
Thousands, scheduledclient.CreateCampaign — the worker throttles for you
Last updated on