Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
push:
tags: ["v*"]

jobs:
release:
runs-on: ubuntu-latest
environment: rubygems
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true
- run: bundle exec rake test
- name: Check the tag matches the gem version
run: |
version=$(ruby -r ./lib/smswire/version -e 'print Smswire::VERSION')
test "v${version}" = "${GITHUB_REF_NAME}" || { echo "Tag ${GITHUB_REF_NAME} does not match version ${version}"; exit 1; }
- uses: rubygems/release-gem@v1
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ All notable changes to this project are documented here. The format follows

### Added

- Guides: getting started, migrating from twilio-ruby, migrating from
Noticed's Twilio method, compliance primer, and writing a provider.
- `Smswire.verify_credentials!` with checks for Twilio, Telnyx, and Vonage.
- `support_contact` for HELP replies and `opt_out_all_scopes`.
- Release workflow publishing to RubyGems with trusted publishing.

### Changed

- Keyword replies follow CTIA guidance: the opt-out confirmation says no
further messages will be sent, and HELP names a support contact.
- Keywords ignore internal spaces and hyphens, so "opt out" and "stop all" match.
- Noticed adapter job options are `sms_queue` and `sms_priority`, so Noticed's
own `wait` no longer delays a message twice.

- Telnyx adapter (Messaging API v2) with Ed25519 webhook verification.
- Vonage adapter (SMS API) with signed webhook verification for `md5hash` and
HMAC methods.
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ consent and STOP / HELP / START handling, quiet hours, previews, and a
[Noticed](https://github.com/excid3/noticed) delivery method are included.
See the [specification](docs/SPEC.md) for the full design.

**Status:** pre-release. Phases 1 to 5 of the spec are implemented; the
published `0.0.1.pre` gem only reserves the name.
**Status:** pre-release. All six phases of the spec are implemented; the
published `0.0.1.pre` gem only reserves the name. See
[RELEASING.md](RELEASING.md) for the release steps.

## Guides

- [Getting started](docs/guides/getting-started.md)
- [Migrating from direct twilio-ruby calls](docs/guides/migrating-from-twilio-ruby.md)
- [Migrating from Noticed's Twilio delivery method](docs/guides/migrating-from-noticed-twilio.md)
- [Compliance primer](docs/guides/compliance.md)
- [Writing a provider adapter](docs/guides/writing-a-provider.md)

## Requirements

Expand Down
47 changes: 47 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Releasing

Releases publish to RubyGems from GitHub Actions with
[trusted publishing](https://guides.rubygems.org/trusted-publishing/), so no
API key or one-time code is stored anywhere. The gem requires MFA for
manual pushes.

## One-time setup

1. On rubygems.org, open the `smswire` gem, then **Trusted publishers**, and
add a GitHub Actions publisher:
- Repository: `timimsms/smswire`
- Workflow filename: `release.yml`
- Environment: `rubygems`
2. In the GitHub repository settings, create an environment named
`rubygems`. Add required reviewers if releases should need approval.

## Before 1.0

- Merge the phase pull requests in order, so `main` holds the release.
- Confirm open decisions 4 to 6 in `docs/SPEC.md`.
- Review the known limitations listed under Phase 6 in `docs/SPEC.md`.
- Try the getting-started guide in a new Rails app against a real provider
account, including a STOP reply and a delivery status callback.

## Each release

1. Make sure CI is green on `main`.
2. Update `lib/smswire/version.rb`.
3. In `CHANGELOG.md`, rename `[Unreleased]` to the version and the release
date, and start a new empty `[Unreleased]` section.
4. Commit: `Release vX.Y.Z`.
5. Tag and push:

```
git tag -a vX.Y.Z -m "vX.Y.Z"
git push origin main vX.Y.Z
```

6. The release workflow runs the tests, builds the gem, and pushes it to
RubyGems. Check https://rubygems.org/gems/smswire afterwards.
7. Create a GitHub release from the tag with the changelog section.

## If a release goes wrong

`gem yank smswire -v X.Y.Z` removes a version from installs, but the version
number cannot be reused. Fix forward with a patch release.
40 changes: 31 additions & 9 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ class OrderShippedNotifier < Noticed::Event
config.messenger = "OrderMessenger"
config.action = :shipped
config.params = -> { {order: record} }
# Optional: config.category, config.wait, config.if
# Optional: config.args, config.kwargs, config.params, config.sms_queue;
# Noticed options such as config.wait and config.if apply to its own job
end
end
```
Expand Down Expand Up @@ -634,6 +635,23 @@ next. No phase includes a calendar estimate.
- Guides: getting started, migrating from direct twilio-ruby, migrating from
Noticed `twilio_messaging`, compliance primer, provider authoring.
- `1.0.0` once the adapter contract and schema are considered stable.
- Status: guides written in `docs/guides`, with a test that every setting,
constant, and generator they name exists. Compliance research changed the
defaults: HELP replies include `support_contact`, the opt-out confirmation
follows CTIA wording, keywords ignore spaces ("opt out"), and
`opt_out_all_scopes` prepares for the FCC revoke-all provision.
`Smswire.verify_credentials!` from section 6.8 is implemented. Release
steps are in `RELEASING.md`; publishing 1.0 is left to the maintainer.

### Known limitations at 1.0

- Free-text opt-outs ("please stop texting me") are stored but not acted on;
the compliance guide shows an observer for review.
- Rate limits can be exceeded briefly by concurrent sends.
- Vonage receipts for the second and later parts of a long message are
acknowledged but not matched to the delivery.
- Vonage uses the SMS API, not the newer Messages API, and has no MMS.
- Telnyx ignores `validity_period`.

## 10. Risks and mitigations

Expand All @@ -647,18 +665,22 @@ next. No phase includes a calendar estimate.

## 11. Open decisions

Decisions 1 to 3 are settled. The rest should be settled before 1.0.
Decisions 1 to 3 are settled. Decisions 4 to 6 are proposed as settled in
Phase 6, matching the implementation; confirm them before tagging 1.0.

1. **Name.** `smswire` is recommended; `textable` and `smsable` are the
fallbacks. Decide before the pre-release push.
2. **Body storage default.** Settled in Phase 2: `store_bodies = true`, with
`categories: { otp: { store_body: false } }` as the shipped default.
3. **UUID vs. bigint** primary keys. Settled in Phase 2: the migration follows
the app's generator `primary_key_type`, so both work without a choice here.
4. **Phone validation**: `phonelib` soft dependency vs. a vendored minimal
E.164 validator.
5. **Whether `deliver_now` should be allowed in production** or warn, given
Noticed's stance that inline delivery slows requests. Spec allows it; the
Noticed adapter always uses `deliver_later`.
6. **MMS in 1.0.** `media_urls` is on the message object; whether adapters
must support it for 1.0 is open.
4. **Phone validation.** Proposed: both. The built-in validator handles E.164
input and North American national formats with no dependency; `phonelib`
is used automatically when it is in the bundle, for other regions.
5. **`deliver_now` in production.** Proposed: allowed without a warning. It
returns a `Result`, which is useful for interactive flows such as
verification codes. Guides recommend `deliver_later`, and the Noticed
adapter always uses it.
6. **MMS in 1.0.** Proposed: a capability, not a requirement. Twilio and
Telnyx send `media_urls`; Vonage's SMS API does not and does not declare
`:mms`. The contract does not require it.
124 changes: 124 additions & 0 deletions docs/guides/compliance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Compliance primer

This primer explains what Smswire does for SMS compliance, what it leaves to
you, and which settings matter. It summarizes US rules and industry
guidance as of 2026 and is not legal advice. Have counsel review your
messaging program.

## The rules in brief

- **TCPA and FCC rules** govern automated texts in the US. Marketing texts
need prior express written consent. Consumers may revoke consent by any
reasonable means, and since April 11, 2025 a revocation must be honored
within 10 days. One confirmation text is allowed after an opt-out; it must
not contain marketing and may ask the person to clarify what they want to
stop.
- **The FCC "revoke all" provision**, which makes an opt-out from one kind of
message apply to all of a sender's unrelated messages, is delayed to
January 31, 2027.
- **Quiet hours.** Federal rules restrict telemarketing outside 8am to 9pm in
the recipient's local time. Several states are stricter.
- **CTIA Messaging Principles and Best Practices** are what carriers enforce.
They expect opt-out keywords to work regardless of case or punctuation; one
confirmation after an opt-out and then silence; HELP replies that name the
brand and give a support contact; and consent specific to the program it
was collected for.
- **Carrier registration.** US long codes need 10DLC brand and campaign
registration. Toll-free numbers need verification. Unregistered traffic is
filtered or blocked.

## What Smswire does

| Requirement | Smswire |
|---|---|
| Honor STOP-type replies | STOP, STOPALL, UNSUBSCRIBE, CANCEL, END, QUIT, OPTOUT (or "opt out"), and REVOKE opt the number out immediately |
| One confirmation, no marketing | one opt-out reply through the `compliance` category; deduplication blocks repeats inside 10 minutes |
| HELP reply with brand and contact | HELP and INFO reply with `program_name` and `support_contact` |
| Re-subscribe | START, YES, and UNSTOP opt back in |
| Refuse sends to opted-out numbers | every category except `compliance` checks consent first |
| Marketing needs opt-in | `marketing` requires `opted_in` consent |
| Quiet hours | `marketing` waits outside 9pm to 8am, recipient time |
| Carrier opt-outs | a provider "recipient opted out" error records an opt-out |
| Evidence | consent rows keep source, timestamps, last keyword, and your metadata |

## What you must do

1. **Collect and record opt-in** before marketing. Store the evidence:

```ruby
Smswire::Consent.opt_in!(user.phone, source: :web_form,
metadata: {ip: request.remote_ip, form: "checkout", copy: SMS_TERMS, at: Time.current.iso8601})
```

2. **Set your program name and support contact.**

```ruby
config.program_name = "Acme Alerts"
config.support_contact = "help@acme.example"
```

Without a contact, HELP replies omit it and Smswire logs a warning.

3. **Route incoming messages to Smswire** at `/smswire/inbound/<provider>`.
Without this, STOP replies never reach your app. If your provider handles
opt-outs itself, such as Twilio Advanced Opt-Out, Smswire still records
them and skips its own reply.

4. **Watch for free-text opt-outs.** Smswire matches keywords only when they
are the whole message. "Please stop texting me" is stored but not acted
on, yet it is a reasonable revocation. Review unmatched messages:

```ruby
class OptOutReview
def self.sms_received(message)
return if message.keyword
SupportTicket.create!(phone: message.from_number, body: message.body) if message.body.match?(/\b(stop|unsubscribe|remove me)\b/i)
end
end
Smswire.register_observer(OptOutReview)
```

5. **Honor opt-outs from other channels.** When a customer opts out by email
or phone, call `Smswire::Consent.opt_out!(phone, source: :support)`.

6. **Choose consent scopes deliberately.** By default STOP applies to the
`consent_scope` of the number that received it, so two programs on two
numbers keep separate consent. To make every STOP apply everywhere, as the
FCC revoke-all provision will require across a sender's messages, set:

```ruby
config.opt_out_all_scopes = true
```

7. **Check your categories.** Anything promotional must use
`category: :marketing`. Transactional messages skip the opt-in
requirement, so mislabeling a promotion as transactional defeats the
checks.

8. **Set time zones.** Quiet hours use `recipient.time_zone` when the
recipient object has one, and `config.default_time_zone` otherwise.

9. **Register with the carriers** and keep your messages consistent with the
registered campaign: brand name in messages, opt-out instructions at least
periodically, and content matching the sample messages.

## Settings reference

| Setting | Default | Notes |
|---|---|---|
| `enforce_consent` | `true` | turn off only if another system owns consent |
| `categories` | see README | merged per key over the shipped rules |
| `keywords` | the lists above | add synonyms, such as `ARRET` |
| `keyword_replies` | CTIA-style replies | `%{program}` and `%{contact}` are replaced; `nil` sends no reply |
| `program_name` | the app name | |
| `support_contact` | none | phone, email, or URL |
| `opt_out_all_scopes` | `false` | STOP applies to every scope |
| `default_time_zone` | `Time.zone` | for quiet hours |

## Sources

- [FCC consent revocation order, FCC 24-24](https://docs.fcc.gov/public/attachments/FCC-24-24A1.pdf)
- [FCC revocation rule effective April 11, 2025 (JD Supra)](https://www.jdsupra.com/legalnews/fcc-s-tcpa-consent-revocation-rule-8022288/)
- [Revoke-all provision delayed to January 31, 2027 (Wiley)](https://www.wiley.law/alert-FCC-Extends-Limited-Waiver-for-Part-of-the-TCPA-Consent-Revocation-Rule)
- [CTIA Messaging Principles summary (Bird)](https://bird.com/explained/compliance/what-are-the-ctia-messaging-principles)
- [Vonage 10DLC traffic compliance](https://api.support.vonage.com/hc/en-us/articles/8443130026140-10DLC-Traffic-compliance)
Loading
Loading