Go SDK

Send SMS, WhatsApp and OTP from Go with the official SDK

envoisms-go is EnvoiSMS.ma's official Go SDK. One client built from your API key sends SMS and WhatsApp messages and runs the managed OTP flow — send a code, then check it — from any Go service.

cURL REST API
curl -X POST https://api.envoisms.ma/v1/messages \ -H "Authorization: Bearer env_live_votretoker" \ -H "Content-Type: application/json" \ -d '{ "to": "+212661234567", "message": "Votre code de confirmation est : 849201. Expire dans 3 minutes.", "from": "VOTREMARQUE" }'
● Routes locales MarocIAM • Inwi • Orange
https://api.envoisms.ma/v1
Local Routes
Maroc Telecom (IAM) • Inwi • Orange
Verified DLR Receipts
HMAC-SHA256 Signed
Clear MAD Pricing
dès 0,60 MAD/SMS • 5 MAD offerts

Install

go get github.com/n4ouri/envoisms-go, then import "github.com/n4ouri/envoisms-go" and build a client with envoisms.NewClient(os.Getenv("ENVOISMS_API_KEY")). The source lives at github.com/envoisms/envoisms-go; the module path keeps its original name.

  • client := envoisms.NewClient(os.Getenv("ENVOISMS_API_KEY"))
  • MIT licence

Send an SMS

client.Send(&envoisms.SendMessageRequest{To: "+212612345678", Message: "…", From: "MyBusiness"}) queues the message and returns its ID, its status and its cost in MAD (resp.ID, resp.Status, resp.Cost.MAD).

  • From: your validated Sender ID, or empty for your default
  • Every Send carries an Idempotency-Key — generated, or set IdempotencyKey — so a retry after a timeout never bills the same message twice

Managed OTP: send, then check

client.SendOTP(&envoisms.SendOtpRequest{To: "+212612345678", Brand: "MyBusiness"}) returns a SessionID; client.CheckOTP(otpResp.SessionID, code) returns Verified. The code is generated, delivered and expired by EnvoiSMS, so your service never stores it.

  • Channel: "whatsapp" in SendOTP sends the code over WhatsApp through the shared sender, no connection needed
  • Underlying endpoints: POST /v1/verify/send and POST /v1/verify/check

SMS or WhatsApp

Default to SMS (leave Channel empty): it reaches every Moroccan mobile with no setup beyond your API key. Channel: "whatsapp" sends from your own connected WhatsApp Business number: without one the API answers 403 WHATSAPP_NOT_CONNECTED, and free-form text outside the 24-hour customer window answers 400 OUT_OF_24H_WINDOW — send an approved Template instead. Nothing is charged in either case.

Everything you need to know about Go SDK.

Why is the module path github.com/n4ouri/envoisms-go?
That is the path the module was published under. The repository now lives at github.com/envoisms/envoisms-go; go get and your imports keep using the published module path.
Does the Go SDK return the cost of each message?
Yes. The response to Send carries the message ID, its status and its cost in MAD (resp.Cost.MAD).
How do I test without sending real SMS?
Build the client with an env_test_ sandbox key: the whole sending path is replayed without delivering or debiting anything.

Ready to integrate with Go SDK?

Create your account in under 2 minutes. Get 5 MAD of free credit instantly to test the API.