SMSTunnel
Send SMS from your own Android phone
SMSTunnel for Medusa
Copy to clipboard@narcisbodea/smstunnel-medusa: a Notification Module Provider for the Copy to clipboardsms channel. Medusa's notifications become texts that your own Android phone sends, from your own number, through SMSTunnel.
Your store hands each text to your SMSTunnel account, and your phone sends it from its own SIM, so customers see a number they know and can reply to. No SMS provider account and no sender registration: the phone runs the SMSTunnel app and is linked to your account.
SMSTunnel for Medusa is made by NARBOWEB SRL. It is not affiliated with, endorsed by, or sponsored by Medusa.
Install
1npm install @narcisbodea/smstunnel-medusa
Medusa 2 (tested with 2.22.2), Node.js 20 or newer. No other dependencies.
Get your key
- Install the SMSTunnel app from Google Play on the Android phone that will send the texts, and sign in.
- Open your dashboard at dashboard.smstunnel.io/apps. The phone shows up under Phones (or link it there with Phones → Add phone).
- Under Apps, click Add an app and copy the key it shows. A new key can send texts and look up their status.
Put it in your Medusa environment (Copy to clipboard.env, or your host's secret settings), never in your code:
1SMSTUNNEL_API_KEY=sk_live_...
Set it up
Register the provider with Medusa's Notification Module in Copy to clipboardmedusa-config.ts:
1234567891011121314151617181920module.exports = defineConfig({// ...modules: [{resolve: "@medusajs/medusa/notification",options: {providers: [{resolve: "@narcisbodea/smstunnel-medusa",id: "smstunnel",options: {channels: ["sms"],apiKey: process.env.SMSTUNNEL_API_KEY,// Optional:defaultCountryCode: "+1", // for numbers written without + or 00templates: {"order-placed": "Thanks {{ first_name }}! Your order #{{ display_id }} is confirmed.",},},},
Medusa takes one provider per channel: if another provider already handles Copy to clipboardsms, swap it for this one. Medusa won't start without an Copy to clipboardapiKey, so a missing variable shows up right away.
Option Copy to clipboardapiKey Required. Your SMSTunnel API key. Copy to clipboardchannels Required by Medusa: Copy to clipboard["sms"]. Copy to clipboardtemplates Texts by template name, with Copy to clipboard{{ placeholders }} filled from the notification's Copy to clipboarddata (dots reach inside objects: Copy to clipboard{{ customer.first_name }}). Copy to clipboarddefaultCountryCode Completes numbers written without Copy to clipboard+ or Copy to clipboard00, e.g. Copy to clipboard"+40". It wins over the phone's own country. Copy to clipboarddeviceId The phone that sends, when your account has several (its ID is under Phones, with a Copy button). Empty: your phone that is online. Copy to clipboardbaseUrl Default Copy to clipboardhttps://smstunnel.io. Copy to clipboardtimeoutMs Default Copy to clipboard30000.
Text the customer when an order is placed
Add a subscriber, Copy to clipboardsrc/subscribers/order-placed.ts:
1234567891011121314151617181920import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"// Texts the customer when an order is placed, from your own phone, through SMSTunnel.export default async function orderPlacedText({ event: { data }, container }: SubscriberArgs<{ id: string }>) {const query = container.resolve(ContainerRegistrationKeys.QUERY)const notifications = container.resolve(Modules.NOTIFICATION)const {data: [order],} = await query.graph({entity: "order",fields: ["id", "display_id", "shipping_address.first_name", "shipping_address.phone", "billing_address.phone"],filters: { id: data.id },})const phone = order?.shipping_address?.phone || order?.billing_address?.phoneif (!phone) return // the customer left no number: nothing to sendawait notifications.createNotifications({to: phone,
With the Copy to clipboardorder-placed template above, the customer gets: Thanks Ana! Your order #1042 is confirmed. The same pattern works for Copy to clipboardorder.fulfillment_created, Copy to clipboardorder.canceled, Copy to clipboarddelivery.created and the other Medusa events.
Customers type phone numbers in many ways. Ask for the international format at checkout, or set Copy to clipboarddefaultCountryCode for your country.
Send a text from your own code
From a workflow step, an API route or a scheduled job, resolve the Notification Module and pass the text in Copy to clipboardcontent.text:
123456789const notifications = container.resolve(Modules.NOTIFICATION)await notifications.createNotifications({to: "+14155550123",channel: "sms",template: "pickup-ready", // a name for your records; content.text is what's sentcontent: { text: "Your order is ready for pickup at our Market St store until 7 pm." },provider_data: { deviceId: "6ae9940bf30ce9d1447cc179" }, // optional: another phone of yours})
What a notification can carry:
Field Copy to clipboardto One number, in international format (Copy to clipboard+14155550123). For several people, create one notification each. Copy to clipboardcontent.text The text, up to 1600 characters. When it's there, it is sent as is. Copy to clipboardtemplate + Copy to clipboarddata Without Copy to clipboardcontent.text, the provider's Copy to clipboardtemplates[template] filled from Copy to clipboarddata. Copy to clipboardidempotency_key Medusa's own field. The provider also sends it to SMSTunnel (Copy to clipboardIdempotency-Key: medusa:<key>), so a retry within 24 hours gets the first text's answer instead of a second text. Copy to clipboardprovider_data.deviceId Send from this phone. Copy to clipboardprovider_data.defaultCountryCode For this text only. Copy to clipboardprovider_data.signInCode Copy to clipboardtrue sends it as a sign-in code: the text must contain a code of 4 to 10 digits on its own (Copy to clipboard482913, or Copy to clipboard123-456), 320 characters at most, and it counts against your sign-in code allowance. Copy to clipboardprovider_data.idempotencyKey Your own key instead of Copy to clipboardmedusa:<idempotency_key>.
Each notification Medusa stores keeps SMSTunnel's message id in Copy to clipboardexternal_id.
When a text doesn't go out
Copy to clipboardcreateNotifications throws, and Medusa stores the notification with status Copy to clipboardfailure. The error says why:
SMSTunnel answered What it means 401 The API key is wrong, deactivated or deleted. Create a new one under Apps → Add an app. 403 The key lacks a permission (the error carries Copy to clipboardcode: "PERMISSION_REQUIRED" and the permission), or your plan doesn't include what was asked. 429 Too many requests (30 sends a minute per key): Copy to clipboardRetry-After says how many seconds to wait. Without it, today's allowance of your plan is used up (pricing). 5xx, or no answer SMSTunnel had a problem. The text may or may not have gone out: check the Messages page in your dashboard before you send it again, or send it again with the same Copy to clipboardidempotency_key. 400 SMSTunnel refused a field, such as a number it can't read or a code text without a code.
A number that isn't one, a list of numbers in Copy to clipboardto, an empty text or one over 1600 characters is refused before anything is sent.
If your phone is offline, the text isn't lost: it waits in the queue on your account and goes out as soon as the phone is back online (up to 3 days). The provider logs that it was queued.
The provider never resends a text by itself. In a subscriber, a failure is logged by Medusa and doesn't affect the order.
Using the client directly
The package also exports the small API client it uses, for status checks or listing phones:
12345import { SmsTunnelClient, fetchTransport } from "@narcisbodea/smstunnel-medusa"const smstunnel = new SmsTunnelClient({ apiKey: process.env.SMSTUNNEL_API_KEY!, transport: fetchTransport() })const { devices } = await smstunnel.listPhones() // [{ id, name, isOnline, lastSeenAt }]const status = await smstunnel.getStatus(notification.external_id) // pending, sent, delivered, failed
Build it with an AI assistant
Paste this into Claude, ChatGPT, Cursor or Copilot and replace the part in brackets. Never paste your real API key into a prompt.
12345678910111213141516Help me send texts from my Medusa 2 store with SMSTunnel. SMSTunnel sends each text from my own Android phone, from my own number: the phone runs the SMSTunnel app and is linked to my SMSTunnel account.I installed @narcisbodea/smstunnel-medusa (npm install @narcisbodea/smstunnel-medusa), a Notification Module Provider for the "sms" channel, registered in medusa-config.ts:modules: [{ resolve: "@medusajs/medusa/notification", options: { providers: [{ resolve: "@narcisbodea/smstunnel-medusa", id: "smstunnel", options: { channels: ["sms"], apiKey: process.env.SMSTUNNEL_API_KEY, defaultCountryCode: "+1" (optional), deviceId (optional, which phone sends), templates: { "<name>": "a text with {{ placeholders }} filled from data" } (optional) } }] } }]To send, resolve Modules.NOTIFICATION in a subscriber, workflow step or API route and call createNotifications({ to: "+14155550123", channel: "sms", template: "<name>", data: {...} }), or pass content: { text: "..." } (content.text wins over the template). provider_data may carry deviceId, defaultCountryCode, signInCode: true (a sign-in code: the text must contain a code of 4 to 10 digits standing on its own, at most 320 characters) and idempotencyKey. Set idempotency_key on the notification so a retry can't send a second text. One recipient per notification: for several people, create one notification each.Behind it is the SMSTunnel API: POST https://smstunnel.io/api/v1/sms/send with the header X-API-Key and the JSON body {"to", "message", "deviceId"?, "defaultCountryCode"?}; one recipient per call; texts up to 1600 characters; 30 send requests a minute per key; defaultCountryCode (e.g. "+40") completes numbers written without + or 00. A failed send throws and Medusa stores the notification as "failure" with SMSTunnel's reason: 401 wrong key, 403 missing permission or plan (with a code such as PERMISSION_REQUIRED), 429 too many requests (Retry-After header) or today's allowance used up, 5xx SMSTunnel problem (the text may have gone out: never resend without the same idempotency key). If the phone is offline, the text waits in the queue and goes out when the phone is back online.What I want: [describe what should send a text, to whom, and when]Rules:- Keep SMSTUNNEL_API_KEY in the environment or the host's secret store, never in source code, the storefront or the admin bundle.- Take the number from the order, customer or form; validate it (international format with the country code) and skip the text when there is none.- Handle errors: a failed text must not break the order flow; log it.- Only send texts people expect (order updates, pickup notices, appointment reminders, sign-in codes).
Responsible use
Send only texts that people expect from you: order updates, pickup notices, reminders, sign-in codes. Unsolicited messages from a personal SIM break most carriers' terms of service. Make sure your use follows your carrier's terms and local rules (in the EU, GDPR and the ePrivacy rules on electronic communications).
Development
123npm installnpm run typechecknpm test # unit tests, with fetch replaced (node --test)
The end-to-end tests run only against a local SMSTunnel API, never smstunnel.io. They read Copy to clipboard{ "serverUrl", "dockerServerUrl", "deviceId", "apiKey" | "keys" } from a JSON file and, with Copy to clipboardSMSTUNNEL_E2E_MONGO_URL, check each text in the test server's database:
123export SMSTUNNEL_E2E_KEY_FILE=/path/to/test-key.json # SMSTUNNEL_E2E_KEY_NAME picks keys.<name>npm run test:local-api # the client against the local API: send, status, phones, usage, idempotencynpm run test:e2e # Docker: Postgres + a Medusa 2 app with the packed plugin; a Store API checkout texts the customer
Copy to clipboardnpm run test:e2e builds the image in Copy to clipboarde2e/, uses the compose project Copy to clipboardsmst-r3-medusa, and removes its containers and volumes at the end (Copy to clipboard--keep leaves them running).
Links: SMSTunnel docs · Dashboard: Apps · Medusa Notification Module
Issues
Report a bug or ask for a feature at https://github.com/narcisbodea/smstunnel-medusa/issues. For your SMSTunnel account, see https://smstunnel.io/docs/.
License
MIT, © NARBOWEB SRL. See LICENSE.
