Skip to main content

SMS Marketing & Notifications

Overview​

The SMS module sends text messages from the shop through Twilio. It covers three things: a subscriber list built from checkout opt-ins and inbound keywords, marketing campaigns that can be sent immediately or scheduled, and automatic order-status messages to customers who have opted in.

It is for stores that already have a Twilio account. The module holds no credentials of its own and sends nothing until an Account SID, auth token and sending number are entered.

Inbound messages are handled as well: a customer texting a registered keyword to the sending number can opt in, opt out, or be answered with a coupon code or a fixed reply.

Availability​

ItemValue
Module keysms-advanced
TierPremium
Entitlement keysms-advanced
Admin tabsms, under Marketing & Email
Enabled optionaiowc_module_enabled_sms-advanced (off until turned on)
REST namespaceaiowc/v1

Enabling the module creates the four tables below, seeds the defaults and schedules both background jobs. Disabling it unschedules them. Uninstalling drops the tables and deletes the settings row.

Every hook and every REST route is behind the entitlement: registerHooks() returns immediately when the licence does not grant sms-advanced, so on a store without it the routes are not registered at all.

Settings​

Stored in the bundled option row aiowc_sms_settings, written with autoload off; legacy per-key options aiowc_sms_<key> are migrated on first read.

Stored keyDefaultMeaning
enable_smstrueMaster switch for sending.
twilio_account_sid''Twilio Account SID.
twilio_auth_token''Twilio auth token. Write-only over REST — an empty value keeps the stored one.
from_number''The sending number, in E.164 form.
opt_in_requiredtrueOnly message numbers that subscribed through the store or a keyword.
message_retention180Days of message history kept before the cleanup job deletes it. Clamped to 1–3650 on save.

With any of the SID, token or from-number missing, SMSGatewayService::send() refuses with no_credentials and the health check reports a warning.

Admin screen​

The SMS tab is a single screen with no sub-tabs:

  • Connection — connected or not, the provider, the sending number, and a note when sending is switched off.
  • Account balance — the balance Twilio reports, or the reason it could not be read.
  • Provider configuration — a form over the six settings above, validated in the browser before it is submitted.
  • Send test SMS — a dialogue that sends one message to a number you type, to confirm the credentials work.

The screen calls four routes: GET /sms/status, GET /sms/settings, PUT /sms/settings and POST /sms/send-test. Campaigns, keywords, subscribers and analytics have no screen — see Known gaps.

Keyword actions​

A keyword row carries an action, and the inbound handler matches the first keyword found in the message body, case-insensitively:

ActionEffect
opt_inSubscribes the sending number.
opt_outOpts the sending number out.
couponReplies with the keyword's coupon code.
info / customReplies with the keyword's response template.

REST API endpoints​

All routes are on aiowc/v1. Unless stated otherwise they require manage_woocommerce — plus a REST nonce on cookie-authenticated requests — and answer with the { success, data, message } envelope.

MethodPathPurposeRequired args
GET/sms/settingsRead the settings above.–
PUT / PATCH / POST/sms/settingsUpdate the settings above; only the fields sent are written.–
GET/sms/statusConnection state, sending number and Twilio balance.–
POST/sms/send-testSend one message immediately.phone, message
GET/sms/campaignsList campaigns.–
POST/sms/campaignsCreate a campaign.–
POST/sms/campaigns/{id}/sendQueue the campaign to its segment now.id
POST/sms/campaigns/{id}/scheduleSchedule the campaign for a future time.id, scheduled_for
GET/sms/analyticsMessage statistics over days (defaults to 30).–
GET/sms/keywordsList inbound keywords.–
POST/sms/keywordsCreate a keyword.–
DELETE/sms/keywords/{id}Delete a keyword.id
POST/sms/subscribeSubscribe a number. Open to guests; REST nonce required, 30 requests a minute.phone
POST/sms/opt-outOpt a number out. Same guard as subscribe.phone
POST/sms/webhookTwilio's inbound-message webhook. Answers TwiML, not the envelope.–

The webhook route accepts unauthenticated requests because Twilio sends them, and authenticates each one by recomputing the X-Twilio-Signature HMAC with the stored auth token and comparing it in constant time. A request failing that check is refused with 403 invalid_signature.

WooCommerce integration​

HookWhat the module does
woocommerce_checkout_after_terms_and_conditionsRenders the SMS opt-in checkbox on the checkout form.
woocommerce_checkout_create_orderSubscribes the billing phone when the box was ticked, and records _aiowc_sms_opt_in on the order.
woocommerce_order_status_changedQueues a status message for the billing number when it is an active subscriber.

Order messages are produced for processing, completed, on-hold, cancelled and refunded. Any other status produces no message. Nothing is sent inline with the request — messages are queued and drained by cron.

Shortcode [aiowc_sms_subscribe] renders a subscribe form; its POST is handled on init.

Database schema​

TableHolds
{prefix}aiowc_sms_subscribersOne row per phone number: status, opt-in and opt-out timestamps, optional user id.
{prefix}aiowc_sms_campaignsCampaign text, segment, schedule, status and sent, delivered and failed counts.
{prefix}aiowc_sms_messagesEvery queued, sent and inbound message with its Twilio SID and error text.
{prefix}aiowc_sms_keywordsKeyword, action, response template and optional coupon code.

Background jobs​

HookIntervalWork
aiowc_sms_send_queue5 minutes (aiowc_every_5_minutes, added by the job)Sends up to 50 queued messages per pass and updates campaign counts.
aiowc_sms_cleanupdailyDeletes delivered messages older than message_retention days, and marks a sending or scheduled campaign complete once its counts show it has finished.

Entitlement limits​

sms-advanced is an on/off grant. It carries no message quota of its own — Twilio's account balance and pricing are the real ceiling, which is why the admin screen reads the balance. The plan-level limits in the licence (products, orders, customers, exports) are not applied by this module.

Health check​

The module reports a warning when its tables are missing, when WooCommerce is inactive, or when any of the SID, auth token and from-number is empty. Otherwise it reports that it is functioning normally.

Known gaps​

  • The admin screen covers connection, settings and a test send only. Campaigns, keywords, subscribers and the message log are reachable over REST but have no screen.
  • A campaign's segment is stored as free-form JSON on the campaign row; there is no segment builder.
  • Twilio is the only gateway. SMSGatewayService posts to Twilio's API directly and has no provider abstraction.