SMSTunnel logo

SMSTunnel

By Narcis Bodea

Send texts from Strapi 5 through your own Android phone and number: a service and a settings page.

Latest version

v1.0.0

released November 19, 2026

npm install @narcisbodea/smstunnel-strapi

SMSTunnel for Strapi

@narcisbodea/smstunnel-strapi: send texts from Strapi 5 through your own Android phone, from your own number, with SMSTunnel. A service your code calls (lifecycles, controllers, cron jobs) and a settings page in the admin panel.

Strapi hands each text to your SMSTunnel account, and your phone sends it from its own SIM, so people 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.

Get it on Google Play

SMSTunnel for Strapi is made by NARBOWEB SRL. It is not affiliated with, endorsed by, or sponsored by Strapi Solutions SAS or the Strapi project.

Install

npm install @narcisbodea/smstunnel-strapi
npm run build   # rebuilds the admin panel with the plugin's settings page

Strapi 5 (tested with 5.60.0), Node.js 20 or newer. No other dependencies. Strapi finds the plugin by itself; restart it after installing.

Get your key

  1. Install the SMSTunnel app from Google Play on the Android phone that will send the texts, and sign in.
  2. Open your dashboard at dashboard.smstunnel.io/apps. The phone shows up under Phones (or link it there with Phones → Add phone).
  3. Under Apps, click Add an app and copy the key it shows. A new key can send texts and look up their status.

Set it up

Either way works; what config/plugins sets wins, and the settings page then shows it read-only.

In config (config/plugins.ts), with the key in an environment variable (.env, or your host's secret settings):

export default ({ env }) => ({
  smstunnel: {
    enabled: true,
    config: {
      apiKey: env('SMSTUNNEL_API_KEY'),
      deviceId: env('SMSTUNNEL_DEVICE_ID', ''), // optional: which of your phones sends
      defaultCountryCode: '+1', // optional: for numbers written without + or 00
    },
  },
});

In the admin panel: Settings → SMSTunnel → Texts from your phone. Paste the key there: it is checked with SMSTunnel first, then saved encrypted with Strapi's encryption key (ENCRYPTION_KEY in .env, which new Strapi 5 projects have) and never sent back to the browser. The page also shows your phones and whether they are online, lets you pick the phone that sends and the country code, and sends a test text.

Option
apiKeyYour SMSTunnel API key.
deviceIdThe phone that sends, when your account has several (its ID is under Phones, with a Copy button). Empty: your phone that is online.
defaultCountryCodeCompletes numbers written without + or 00, e.g. '+40'. It wins over the phone's own country.
baseUrlDefault https://smstunnel.io.
timeoutMsDefault 30000.

Who may see or change the settings: Settings → Administration panel → Roles → a role → Settings → SMSTunnel (Read the SMSTunnel settings and phones, Change the SMSTunnel settings and send a test text). The plugin adds no public API routes.

Send a text from your code

const sent = await strapi.plugin('smstunnel').service('sms').send({
  to: '+14155550123',
  message: 'Your table for 4 is ready.',
});
// sent: { messageId: '6ae9952f7f9ac207c547af90', queued: false, replayed: false }
Method
send({ to, message, deviceId?, defaultCountryCode?, idempotencyKey? })One text to one number, up to 1600 characters. For several people, call it once per number.
sendCode({ to, message, ... })A sign-in or verification code. The text must contain the code: 4 to 10 digits on their own (482913, or 123-456), 320 characters at most. It counts against your sign-in code allowance.
getStatus(messageId)pending, sent, delivered or failed (deliveryStatus: 'unconfirmed': handed to the SIM without a confirmation; it was most likely sent).
listPhones(){ devices: [{ id, name, isOnline, lastSeenAt }], online, total }.
getUsage()What your plan allows today and what is left.

idempotencyKey: a second call with the same key within 24 hours gets the first answer back (replayed: true) instead of sending a second text. Use one key per text, such as order-1042-shipped.

TypeScript: import type { SmsTunnelService } from '@narcisbodea/smstunnel-strapi/strapi-server' and cast the service to it.

Text each new entry (a lifecycle)

For example a lead collection with name and phone fields: src/api/lead/content-types/lead/lifecycles.ts

// Texts each new lead from your own phone, through SMSTunnel.
export default {
  async afterCreate(event: { result: { documentId: string; name?: string; phone?: string } }) {
    const { result } = event;
    if (!result.phone) return; // no number: nothing to send

    try {
      await strapi.plugin('smstunnel').service('sms').send({
        to: result.phone,
        message: `Thanks ${result.name ?? ''}, we got your request and will call you back today.`,
        // A retry (or a second afterCreate for the same entry) within 24 h can't send a second text.
        idempotencyKey: `lead-${result.documentId}`,
      });
    } catch (error) {
      // A text that can't go out must not undo the entry: log it.
      strapi.log.error(`SMSTunnel: ${(error as Error).message}`);
    }
  },
};

This fits a content type without Draft & Publish. With Draft & Publish on, Strapi creates a new row when an entry is published, so afterCreate runs again; use a Document Service middleware instead, which runs once per new document (src/index.ts):

import type { Core } from '@strapi/strapi';

export default {
  register({ strapi }: { strapi: Core.Strapi }) {
    // With Draft & Publish, lifecycles fire again when an entry is published: a Document Service
    // middleware on "create" texts once per new document.
    strapi.documents.use(async (context, next) => {
      const result = await next();
      if (context.uid === 'api::booking.booking' && context.action === 'create') {
        const booking = result as { documentId: string; phone?: string; date?: string };
        if (booking.phone) {
          strapi
            .plugin('smstunnel')
            .service('sms')
            .send({
              to: booking.phone,
              message: `Your booking for ${booking.date ?? 'your date'} is confirmed.`,
              idempotencyKey: `booking-${booking.documentId}`,
            })
            .catch((error: Error) => strapi.log.error(`SMSTunnel: ${error.message}`));
        }
      }
      return result;
    });
  },

  bootstrap() {},
};

Ask for numbers in the international format in your forms (+14155550123), or set defaultCountryCode. Keep the phone field a text field: a number field loses the + and leading zeros, and the plugin refuses a JavaScript number.

When a text doesn't go out

The service throws an SmsTunnelError with status, code, retryAfter and mayHaveSent:

SMSTunnel answeredWhat it means
401The API key is wrong, deactivated or deleted. Create a new one under Apps → Add an app.
403The key lacks a permission (code: 'PERMISSION_REQUIRED', with permission), or your plan doesn't include what was asked.
429Too many requests (30 sends a minute per key): retryAfter says how many seconds to wait. Without it, today's allowance of your plan is used up (pricing).
5xx, or no answerSMSTunnel had a problem. mayHaveSent is true: check the Messages page in your dashboard before you send it again, or send it again with the same idempotencyKey.
400SMSTunnel refused a field, such as a number it can't read or a code text without a code.

A number that isn't one, several numbers in to, an empty text or one over 1600 characters is refused before anything is sent. Without a key, the error says where to add one.

If your phone is offline, the text isn't lost: queued is true, it waits in the queue on your account and goes out as soon as the phone is back online (up to 3 days).

The plugin never resends a text by itself.

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.

Help me send texts from my Strapi 5 project 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 the plugin @narcisbodea/smstunnel-strapi (npm install @narcisbodea/smstunnel-strapi). Its key is in config/plugins.ts: smstunnel: { enabled: true, config: { apiKey: env('SMSTUNNEL_API_KEY'), deviceId (optional, which phone sends), defaultCountryCode: '+1' (optional) } } (or saved, encrypted, in Settings → SMSTunnel). From server code, call strapi.plugin('smstunnel').service('sms'):
- send({ to, message, deviceId?, defaultCountryCode?, idempotencyKey? }) → { messageId, queued, replayed }: one text to one number, up to 1600 characters;
- sendCode({ to, message }) for sign-in codes: the text must contain a code of 4 to 10 digits standing on its own (e.g. 482913 or 123-456), at most 320 characters;
- getStatus(messageId), listPhones(), getUsage().
It throws SmsTunnelError with status, code, retryAfter and mayHaveSent. For a new entry, use a lifecycle (afterCreate) on content types without Draft & Publish, or strapi.documents.use(...) on action "create" when Draft & Publish is on (lifecycles fire again on publish).

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 (loop for several people); 30 send requests a minute per key; defaultCountryCode (e.g. "+40") completes numbers written without + or 00. Errors: 401 wrong key, 403 missing permission or plan (code such as PERMISSION_REQUIRED), 429 too many requests (Retry-After) or today's allowance used up, 5xx SMSTunnel problem (the text may have gone out: never resend without the same idempotencyKey). If the phone is offline, the text waits in the queue (queued: true) 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 .env or the host's secret store, never in source code or anything the admin or a frontend can read.
- Store phone numbers as text in international format; validate them and skip the text when there is none.
- Handle errors: catch them, log them, and never let a failed text undo the content change.
- Pass an idempotencyKey per text (e.g. based on the documentId) so retries can't text twice.
- Only send texts people expect (confirmations, reminders, order updates, sign-in codes).

Responsible use

Send only texts that people expect from you: confirmations, reminders, order updates, 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

npm install
npm run typecheck   # server and admin
npm test            # unit tests: the service, the settings, the admin routes, with fetch replaced
npm run build       # strapi-plugin build (dist/admin, dist/server)
npm run verify      # strapi-plugin verify

The end-to-end tests run only against a local SMSTunnel API, never smstunnel.io. They read { "serverUrl", "dockerServerUrl", "deviceId", "apiKey" | "keys" } from a JSON file and, with SMSTUNNEL_E2E_MONGO_URL, check each text in the test server's database:

export 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, idempotency
npm run test:e2e         # Docker: a Strapi 5 app with the packed plugin (admin panel built), driven through its APIs

npm run test:e2e uses the compose project smst-r3-strapi and removes its containers and volumes at the end (--keep leaves them running).

Links: SMSTunnel docs · Dashboard: Apps · Strapi lifecycle functions · Document Service middlewares

Issues

Report a bug or ask for a feature at https://github.com/narcisbodea/smstunnel-strapi/issues. For your SMSTunnel account, see https://smstunnel.io/docs/.

License

MIT, © NARBOWEB SRL. See LICENSE.

Submit your content

Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.

Submit
Submit your content