narcisbodea

smstunnel payload

by narcisbodea
Notifications & messaging
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds server-side helpers that hand each text to your SMSTunnel account, and your linked Android phone sends it from its own SIM. It registers through the plugins array, adds no collections or endpoints, and stores settings in config.custom. Requires Payload 3, an SMSTunnel API key and the SMSTunnel app on an Android phone.

Features

  • sendText helper for one text of up to 1600 characters to one number
  • sendCode helper for verification and sign-in codes
  • Idempotency keys so retries do not send a second text
  • Works in collection hooks, custom endpoints and Jobs Queue tasks
  • Typed SmsTunnelError with status, retryAfter and mayHaveSent
  • Client for message status, phone listing and usage lookup

Use cases

  • Text a customer when an order is created in a collection hook
  • Queue reminder or confirmation texts through Payload's Jobs Queue
  • Send verification codes from your own number without an SMS provider account

From the author

SMSTunnel for Payload CMS 3: send texts from hooks, endpoints and jobs through your own Android phone, from your own number.

Installation

npm i @narcisbodea/smstunnel-payload

0

Stars

0

Forks

0

Open Issues

1 months ago

Last Updated

17

Weekly Downloads

v1.0.0

npm Version

51.4 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 1

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20260
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
npm weekly downloads

21+21 since Nov 21

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202621
Dec 5, 202626
Dec 4, 202627
Dec 3, 202629
Dec 2, 202628
Dec 1, 202643
Nov 30, 202643
Nov 29, 202666
Nov 28, 2026267
Nov 27, 2026264
Nov 26, 2026260
Nov 25, 2026258
Nov 24, 2026241
Nov 23, 2026236
Nov 22, 2026206
Nov 21, 20260

Each point is npm's rolling 7-day download count.

Health Score

64/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1444817755-root.svg)](https://payloaddirectory.dev/plugins/1444817755-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1444817755-root"><img src="https://payloaddirectory.dev/badge/1444817755-root.svg" alt="Payload Directory"></a>
Updated Nov 3, 2026Created Nov 3, 2026Published Nov 19, 2026

README

SMSTunnel for Payload

@narcisbodea/smstunnel-payload: send texts from your Payload 3 hooks, endpoints and jobs through your own Android phone, from your own number, with SMSTunnel.

Payload 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 Payload is made by NARBOWEB SRL. It is not affiliated with, endorsed by, or sponsored by Payload (payloadcms.com).

Install

npm install @narcisbodea/smstunnel-payload

Payload 3 (tested with 3.92.1), server side only. No other dependencies.

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.

Put it in your environment (.env, or your host's secret settings), never in your code:

SMSTUNNEL_API_KEY=sk_live_...

Set it up

Add the plugin to payload.config.ts:

import { buildConfig } from 'payload'
import { smsTunnelPlugin } from '@narcisbodea/smstunnel-payload'

export default buildConfig({
  // ...
  plugins: [smsTunnelPlugin()],
})

It adds no collections, fields or endpoints. It keeps its settings in config.custom, which Payload never sends to the admin panel, and warns at start-up when there is no key.

Option
apiKeyDefault process.env.SMSTUNNEL_API_KEY.
deviceIdThe phone that sends, when your account has several (its ID is under Phones, with a Copy button). Default process.env.SMSTUNNEL_DEVICE_ID, else your phone that is online.
defaultCountryCodeCompletes numbers written without + or 00, e.g. '+40'. It wins over the phone's own country.
baseUrlDefault process.env.SMSTUNNEL_BASE_URL, else https://smstunnel.io.
timeoutMsDefault 30000.
enabledfalse turns sending off, for example in development: the helpers then throw without calling SMSTunnel. Default true.

Text the customer when an order is created (a hook)

src/collections/Orders.ts:

import type { CollectionConfig } from 'payload'
import { sendText } from '@narcisbodea/smstunnel-payload'

export const Orders: CollectionConfig = {
  slug: 'orders',
  fields: [
    { name: 'customerName', type: 'text' },
    { name: 'phone', type: 'text' },
  ],
  hooks: {
    afterChange: [
      async ({ doc, operation, req }) => {
        // Text the customer once, when the order is created, from your own phone.
        if (operation !== 'create' || !doc.phone) return doc
        try {
          await sendText(req.payload, {
            to: doc.phone,
            message: `Thanks ${doc.customerName ?? ''}! We got your order #${doc.id}.`,
            // The id and the creation time keep the key unique, so a retry can't send a second text.
            idempotencyKey: `order-${doc.id}-${doc.createdAt}`,
          })
        } catch (error) {
          // A text that can't go out must not fail the save: log it.
          req.payload.logger.error(`SMSTunnel: ${(error as Error).message}`)
        }
        return doc
      },
    ],
  },
}

The hook waits for SMSTunnel's answer, usually well under a second. To keep saves from waiting at all, queue the text instead (below).

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

Queue the text (Payload's Jobs Queue)

src/jobs/textCustomer.ts, registered with jobs: { tasks: [textCustomer] } in payload.config.ts:

import type { TaskConfig } from 'payload'
import { sendText } from '@narcisbodea/smstunnel-payload'

// A queued text: saves don't wait for SMSTunnel. A retry of the job reuses its key, so it can't text twice;
// the creation time keeps the key unique even if job ids start over (a new database).
export const textCustomer: TaskConfig<{ input: { to: string; message: string }; output: { messageId: string } }> = {
  slug: 'textCustomer',
  inputSchema: [
    { name: 'to', type: 'text', required: true },
    { name: 'message', type: 'text', required: true },
  ],
  outputSchema: [{ name: 'messageId', type: 'text', required: true }],
  retries: 2,
  handler: async ({ input, job, req }) => {
    const sent = await sendText(req.payload, { to: input.to, message: input.message, idempotencyKey: `job-${job.id}-${job.createdAt}` })
    return { output: { messageId: sent.messageId } }
  },
}

Then, from a hook or an endpoint: await req.payload.jobs.queue({ task: 'textCustomer', input: { to: doc.phone, message: '…' } }). Jobs run when your app runs them (autoRun or a cron).

The helpers

All of them take req.payload (or the result of getPayload()), send one text to one number, and return { messageId, queued, replayed }:

sendText(payload, { to, message, deviceId?, defaultCountryCode?, idempotencyKey? })A text, up to 1600 characters. For several people, call it once per number.
sendCode(payload, { 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.
getSmsTunnel(payload)The client, for getStatus(messageId), listPhones(), getUsage().

idempotencyKey: a second call with the same key within 24 hours gets the first answer back (replayed: true) instead of a second text. Use one key per text.

When a text doesn't go out

The helpers throw 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.
422The idempotency key was already used for a different text in the last 24 hours.

A number that isn't one, several numbers in to, an empty text or one over 1600 characters is refused before anything is sent (kind: 'input'), and so is a call without a key or without the plugin.

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 helpers never resend a text by themselves.

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 Payload CMS 3 app 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-payload (npm install @narcisbodea/smstunnel-payload) and added smsTunnelPlugin() to plugins in payload.config.ts (options: apiKey, default process.env.SMSTUNNEL_API_KEY; deviceId, which phone sends; defaultCountryCode, e.g. "+40"; enabled). Server-side helpers, from '@narcisbodea/smstunnel-payload':
- sendText(req.payload, { to, message, deviceId?, defaultCountryCode?, idempotencyKey? }) → { messageId, queued, replayed }: one text to one number, up to 1600 characters;
- sendCode(req.payload, { 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;
- getSmsTunnel(req.payload) → client with getStatus(messageId), listPhones(), getUsage().
They throw SmsTunnelError with status, code, retryAfter and mayHaveSent. Use them in collection hooks (afterChange with operation === 'create'), custom endpoints, or a Jobs Queue task (pass idempotencyKey: `job-${job.id}-${job.createdAt}` so retries can't text twice).

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 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, the admin panel or client components; call the helpers only on the server.
- Store phone numbers as text fields in international format; validate them and skip the text when there is none.
- Handle errors: catch and log them; a failed text must not fail the save.
- Pass an idempotencyKey per text so retries can't text twice.
- Only send texts people expect (order updates, reminders, confirmations, sign-in codes).

Responsible use

Send only texts that people expect from you: order updates, reminders, confirmations, 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   # the plugin, and the examples in e2e/app against Payload's own types
npm test            # unit tests, with fetch replaced (node --test)
npm run build       # dist/ (ESM)

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: Payload 3 (Local API, SQLite) with the packed plugin: the hook, the helpers, a queued job

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

Links: SMSTunnel docs · Dashboard: Apps · Payload hooks · Payload Jobs Queue

Issues

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

License

MIT, © NARBOWEB SRL. See LICENSE.

Similar plugins