Skip to content
orvlabsPublic

About

Go client for Iris, transactional email for Senegal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Iris for Go: transactional email for Senegal

Go Reference Tests Release MIT License Go 1.23+

Website · API reference · Go docs


Send receipts, codes and notifications from your Go server in a few lines, with 221 Pay (Wave, Orange Money) payment links built in. One dependency, the official Standard Webhooks library, for verifying webhooks.

Install

go get github.com/orvlabs/iris-go

Create a key in the Iris console under API keys. Keep it on your server, never in a browser or mobile app.

Send an email

package main

import (
	"context"
	"log"
	"os"

	iris "github.com/orvlabs/iris-go"
)

func main() {
	client := iris.New(os.Getenv("IRIS_API_KEY"))

	sent, err := client.SendEmail(context.Background(), iris.SendEmailRequest{
		From:           "Boutique <commandes@boutique.sn>",
		To:             []string{"Awa <awa@example.sn>"},
		Subject:        "Votre commande",
		HTML:           "<p>Merci {{params.prenom}} !</p>",
		Data:           map[string]any{"prenom": "Awa"},
		IdempotencyKey: "commande-CMD-2041",
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Println("queued", sent.ID)
}

With the same IdempotencyKey (an order number, for example), a retry after a network timeout does not send the email twice.

Tip

Use a test key (iris_test_…) while you build. It is checked exactly like a real one, but nothing is delivered and no units are used.

Ask for a payment

sent, err := client.SendEmail(ctx, iris.SendEmailRequest{
	From:    "factures@boutique.sn",
	To:      []string{"awa@example.sn"},
	Subject: "Votre facture",
	HTML:    "<p>Votre facture est prête.</p>{{bloc_paiement}}",
	Payment: &iris.Payment{
		AmountXOF:   15000,
		Reference:   "FAC-2026-0042",
		Description: "Facture FAC-2026-0042",
		Methods:     []string{"wave", "orange_money"},
	},
})

Amounts are whole CFA francs. The same reference and amount always reuse the same link. Link your 221 Pay merchant account in the console first.

Handle errors

Every error from the API is an *iris.Error with the HTTP status, a stable Code, and Message, Fix and Docs that say what to change.

var apiErr *iris.Error
if errors.As(err, &apiErr) {
	switch {
	case apiErr.Code == "not_enough_credits":
		// top up in the console
	case apiErr.Retryable(): // 429, 502, 503
		// retry later, with an increasing delay and the same IdempotencyKey
	default:
		log.Printf("iris refused: %s: %s (%s)", apiErr.Code, apiErr.Message, apiErr.Fix)
	}
}

Lists

ListEmails, ListEvents and ListSuppressions fetch the next page as you range over them.

for email, err := range client.ListEmails(ctx, iris.ListEmailsParams{To: "awa@example.sn"}) {
	if err != nil {
		return err
	}
	log.Println(email.ID, email.Status)
}

Verify a webhook

http.HandleFunc("/webhooks/iris", func(w http.ResponseWriter, r *http.Request) {
	body, err := io.ReadAll(r.Body)
	if err != nil {
		http.Error(w, "unreadable body", http.StatusBadRequest)
		return
	}
	ev, err := iris.VerifyWebhook(os.Getenv("IRIS_WEBHOOK_SECRET"), r.Header, body) // whsec_…
	if err != nil {
		http.Error(w, "bad signature", http.StatusUnauthorized)
		return
	}
	// Deduplicate on ev.ID: a retry carries the same one.
	log.Println(ev.Type, ev.Data.Email) // email.delivered, email.bounced, email.opened…
	w.WriteHeader(http.StatusNoContent)
})

Read the raw body before parsing it: the signature covers the exact bytes.

What's in the box

iris.New(key) Client for https://iris.orvlabs.com, 30 s timeout, Iris-Version: 2026-11-23 (iris.APIVersion). Change BaseURL, Version or HTTPClient if you need to.
SendEmail POST /api/emails: send now or at SendAt, templates, attachments, one-click unsubscribe, 221 Pay links, secrets, calendar invitations.
ListEmails, GetEmail, CancelEmail GET /api/emails, GET /api/emails/{id}, POST /api/emails/{id}/cancel (a scheduled email or its BatchID).
CheckEmailAddresses POST /api/emails/check, up to 100 addresses.
ListEvents, GetStats GET /api/events, GET /api/stats.
ListSuppressions, DeleteSuppression GET /api/suppressions, DELETE /api/suppressions/{email}.
RevokeSecret POST /api/secrets/{id}/revoke.
GetInboundAttachment GET /api/inbound/{delivery}/attachments/{index}, an io.ReadCloser.
CreateVerification, CheckVerification, CancelVerification, ResendVerification /v1/verify: one-time codes by email, SMS or WhatsApp.
*iris.Error Status, Code, Message, Fix, Docs, Retryable().
iris.VerifyWebhook(secret, headers, body) Checks the signature and decodes the email event.

Every route, field and error code is in the API reference.

License

MIT, by Orvene.

About

Go client for Iris, transactional email for Senegal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages