# MSG91 Order SMS for GoCommerce — Open-Source Module

> Text shoppers about their GoCommerce orders through MSG91’s DLT-approved flow templates: the auth key, a template per event, and what the module leaves out.

- Canonical: https://kitcommerce.store/integrations/notify-msg91/
- Last updated: 2026-09-25

---

Messaging

## MSG91 order SMS for GoCommerce

A Go package that sends GoCommerce’s order notifications as SMS through MSG91. India requires SMS wording to be registered as a DLT template, so the module sends a template id and its variables — the words live in your MSG91 account, not in the store.

- **Messaging** module
- **5** settings
- **1** test
- **ext/notify-msg91**

### What it does

The module registers as the store’s SMS backend. When an order event has a phone number on it — placed, paid, shipped, delivered, cancelled, refunded — the engine hands the module the event and a set of flat values, and the module posts them to MSG91’s flow API under the template id you gave that event. An event with no template is not sent, which the package doc calls the usual case, since most stores text about shipping and nothing else.

The design follows from Indian regulation, and the package doc says so: SMS content has to be pre-registered as a DLT template, so this module sends a template id and its variables rather than free text — the wording lives in your MSG91 account, which is where the regulator expects to find it. The engine’s own SMS wording is therefore not what this module sends.

The key and the template ids come from Config or from the admin, under Notifications › Setup SMS. Installed with neither, the module is idle and the settings say so.

### Configuration

One setting is required: the auth key. Template ids decide which events are texted at all. Set them in Config from your own main(), or under Notifications › Setup SMS in the admin, where each order event has its own field.

*MSG91 module settings — 5 settings, 1 required*

| Setting | Environment variable | Required | What it does |
| --- | --- | --- | --- |
| `AuthKey` Auth key | `MSG91_AUTH_KEY` | Yes | The MSG91 authentication key, sent as the authkey header. Needed in Config or the panel before anything is sent. |
| `Templates` Order placed, Payment received, Order shipped, Order delivered, Order cancelled, Refund issued — template ID | — | No | A DLT-approved flow template id per event. In Config, a map from event name to id; in the panel, one field for each of the six order events. An event left empty sends nothing. |
| `DefaultCountryCode` Default country code | — | No | Prefixed to a ten-digit number that lacks it; MSG91 needs the country code. The panel’s default is 91 — see the limits below for what that means for Config. |
| `BaseURL` | — | No | Overrides https://control.msg91.com, for tests. Go only; not in the panel. |
| `Client` | — | No | Replaces the HTTP client, which otherwise times out after 15 seconds. Go only; not in the panel. |

The module reads its Config struct, not the environment. The variable names are the ones the package’s own example or the reference binary uses; in your own `main()` you choose where each value comes from. Where a setting has a panel label, the admin’s settings drawer can hold it too, and a value typed there wins over Config.

### Setting it up

1. **Register the templates** — In MSG91, get a DLT-approved flow template for each message you want to send — most stores start with shipping — and note each id, and the auth key.
2. **Install the module** — Import it and pass msg91.New to gocommerce.New, as below — or run the reference binary with -msg91, which reads MSG91_AUTH_KEY.
3. **Map events to templates** — Under Notifications › Setup SMS, or in Config’s Templates map, give each event its template id. An event left empty sends nothing.
4. **Name the variables** — Each message carries the order’s values — order_number, customer_name, tracking, items_summary and more — as template variables. Use those names in the template.

main.go

```
import (
	"os"

	"github.com/itswadesh/gocommerce/core"
	msg91 "github.com/itswadesh/gocommerce/ext/notify-msg91"
)

app, err := gocommerce.New(cfg,
	msg91.New(msg91.Config{
		AuthKey: os.Getenv("MSG91_AUTH_KEY"),
		Templates: map[string]string{
			gocommerce.EventOrderShipped: "65a1b2c3d4e5f6",
		},
	}),
)
```

The package doc’s own example, with its imports; cfg is your gocommerce.Config and the template id is a placeholder. gocommerce.EventOrderShipped is the event named order.shipped. Import path `github.com/itswadesh/gocommerce/ext/notify-msg91`.

### How it works

- **One flow call per message**

  Each SMS is one POST to MSG91’s /api/v5/flow/ with the template id and one recipient, whose fields are the number plus every value the engine sent with the event.

- **Values, not wording**

  The engine sends flat data — order number, status, totals in minor units, tracking, a one-line items summary — never rendered copy. The words are the DLT template’s.

- **Only what has a template**

  An event with no template id is skipped, not failed. So is every message while the module is switched off or has no key.

- **The number, normalised**

  Everything but digits is stripped. A ten-digit number without the country code gets it prefixed; one that already starts with it is left alone.

- **Rejections are not retried**

  MSG91 can answer 200 with type error. That, and any 4xx other than 429, is logged and dropped — a rejected message would only be rejected again.

- **Every message on record**

  The engine logs each notification and whether the module reported it sent. Keys and template ids are read on every message, so a change in the panel counts for the next one.

### What it does not do

Read these before an order depends on it. No store is known to run GoCommerce in production yet, so these come from the code, not from anyone’s experience.

- **Order events only** — The engine texts about order events and nothing else, and the cart-recovery module sends its reminders by email — so an abandoned basket is never texted.
- **Config’s country code is shadowed** — The panel’s country code defaults to 91 and is read before Config, so Config.DefaultCountryCode never takes effect. A store outside India changes it under Setup SMS.
- **A retry can resend the email** — A 429 or server error from MSG91 goes back to the engine, whose outbox redelivers the whole event — every subscriber runs again, the order’s email included.
- **One test** — A single test covers idle, panel set-up, one send, the number and a skipped event. MSG91’s error answers — type error, 4xx, 429 — are not exercised by it.
- **A refusal is logged as sent** — The module cannot register or check a DLT template. When MSG91 refuses a message, the refusal goes to the process log, but the engine’s notification log records the message as sent.
- **SMS only** — It registers on the SMS channel. MSG91’s email, WhatsApp and voice products are not used.

FAQ

### Questions about the MSG91 module

**Why does it send template ids instead of the message?**

Because India requires SMS content to be registered as a DLT template before it is sent. The package doc puts it plainly: the wording lives in your MSG91 account, which is where the regulator expects to find it, and the module sends a template id and its variables.

**Which variables can a template use?**

The flat values the engine sends with every order notification: order_id, order_number, order_status, payment_status, payment_method, currency, total_minor, item_count, customer_name, customer_email and items_summary — plus tracking and the parcel’s own summary on a shipment, a reason on a cancellation, and the amounts on a refund. Totals are in minor units: paise, for rupees.

**Should I use MSG91 or Twilio?**

The reference binary’s own comment answers it: Twilio works anywhere, because its wording is the store’s own; MSG91 needs every message registered with a carrier first, which is the right module in India and a week of waiting everywhere else.

**Does it text about abandoned carts?**

No. The engine notifies about order events only, and deliberately: chasing an abandoned basket is a marketing decision with opt-out obligations. That is left to the cart-recovery module, which writes by email.

**Is MSG91 a partner?**

No. The module calls MSG91’s API with a key you supply. MSG91 does not endorse GoCommerce, and no store is known to run this module in production yet.

### Source

Everything on this page is read from [`ext/notify-msg91`](https://github.com/itswadesh/gocommerce/tree/main/ext/notify-msg91) in the GoCommerce repository, MIT licensed. When this page and the code disagree, the code is right and this page is out of date.MSG91 is a trademark of its owner; this module talks to its public API and implies no endorsement. See [trademarks](https://kitcommerce.store/about/#trademarks).

- [ext/notify-msg91 on GitHub](https://github.com/itswadesh/gocommerce/tree/main/ext/notify-msg91)
- [MSG91](https://msg91.com)
- [All GoCommerce modules](https://kitcommerce.store/integrations/)

### Try it against a store of your own

The one-command stack gives you GoCommerce’s API and admin on your own machine in minutes. Add this module to it and try it on test orders before a real one depends on it.

[Deploy in minutes](https://kitcommerce.store/#one-command) · [Read the module](https://github.com/itswadesh/gocommerce/tree/main/ext/notify-msg91) · [All integrations](https://kitcommerce.store/integrations/)
