Skip to content

Configuration ​

Create one client when your application starts and reuse it. It keeps connections open between requests.

OptionNode.jsPythonGoDefault
API keyapiKeyfirst argumentfirst argumentrequired
Signing secretsigningSecretsigning_secretWithSigningSecretnone
Base URLbaseUrlbase_urlWithBaseURLhttps://api.msgine.net/api/v1
Timeout per attempttimeout (ms)timeout (s)WithTimeout30 seconds
RetriesmaxRetriesmax_retriesWithMaxRetries2
HTTP clientfetchhttp_clientWithHTTPClientbuilt in
ts
const msgine = new MsGine({
  apiKey: process.env.MSGINE_API_KEY!,
  signingSecret: process.env.MSGINE_SIGNING_SECRET,
  timeout: 10_000,
  maxRetries: 3,
});
python
msgine = MsGine(
    os.environ["MSGINE_API_KEY"],
    signing_secret=os.environ.get("MSGINE_SIGNING_SECRET"),
    timeout=10.0,
    max_retries=3,
)
go
client, err := msgine.New(
	os.Getenv("MSGINE_API_KEY"),
	msgine.WithSigningSecret(os.Getenv("MSGINE_SIGNING_SECRET")),
	msgine.WithTimeout(10*time.Second),
	msgine.WithMaxRetries(3),
)

Python: sync and async ​

MsGine is synchronous. AsyncMsGine has the same methods and returns coroutines. Close either one when you are done, or use it as a context manager.

python
from msgine import AsyncMsGine

async with AsyncMsGine(os.environ["MSGINE_API_KEY"]) as msgine:
    await msgine.sms.send(to="+256701234567", message="Hello")

Go: contexts ​

Every Go method takes a context.Context first. Cancelling it stops the request, including any wait between retries.

Sandbox keys ​

Keys created in the sandbox environment go through the same validation, scopes and rate limits as production keys and are recorded in your history, but nothing is delivered and nothing is charged. The send responses carry sandbox: true. Use sandbox keys in development, tests and CI.

Scopes ​

Each key carries scopes. A call outside the key's scopes fails with status 403 and code forbidden.

ScopeAllows
SEND_SMS, SEND_WHATSAPP, SEND_EMAIL, SEND_PUSHSending on that channel and reading its history
READ_MESSAGESHistories, message lookup, analytics
MANAGE_WEBHOOKSWebhooks
READ_CONTACTS, MANAGE_CONTACTSOpt-outs and contact fields
MANAGE_WORKFLOWS, RUN_WORKFLOWSBuilding workflows; starting runs, launches and events
FULL_ACCESSEverything

Request signing ​

For extra protection, turn on signing when you create the key. MsGine then shows a signing secret once and refuses any request with that key that is not signed with it.

Pass the secret to the client and the SDK signs every request: it sends x-timestamp (Unix seconds) and x-signature, a hex HMAC-SHA256 over the method, the path with its query string, the timestamp and the SHA-256 of the body. MsGine refuses signatures more than two minutes old and any signature it has already seen, so a captured request cannot be replayed.

Released under the MIT License.