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.

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
SettingEnvironment variableRequiredWhat 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 templatesIn 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 moduleImport 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 templatesUnder Notifications › Setup SMS, or in Config’s Templates map, give each event its template id. An event left empty sends nothing.
  4. Name the variablesEach 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

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.

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 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.

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.

Chat on WhatsApp