sms.optOuts to manage that list programmatically.
Check opt-out status
Returnstrue if the number is on the opt-out list, false otherwise.
Add an opt-out
Adds a number to the opt-out list. Call this if you receive an opt-out request through a channel other than an SMS reply (e.g. a preference center, unsubscribe link, or support request).Remove an opt-out
Removes a number from the opt-out list, re-enabling messages to that number. Only do this when the user has explicitly opted back in.List phone numbers
Returns the phone numbers provisioned on your account (e.g. your toll-free number or simulator number).Error handling
The SDK throws typed errors so you can handle opt-out violations and other failures cleanly.OptedOutError
OptedOutError
Thrown when you attempt to send to a number that is on the opt-out list.
| Property | Type | Description |
|---|---|---|
phoneNumber | string | The opted-out phone number |
message | string | Human-readable error message |
ValidationError
ValidationError
Thrown when request input is invalid, such as a phone number not in E.164 format or a missing required field.
| Property | Type | Description |
|---|---|---|
field | string | The field that failed validation |
message | string | Human-readable error message |
SMSError
SMSError
Base error class for AWS End User Messaging errors. Covers quota limits, throttling, and infrastructure errors.
| Property | Type | Description |
|---|---|---|
code | string | AWS error code |
retryable | boolean | Whether it is safe to retry the request |
message | string | Human-readable error message |
Compliance best practices
- Check before sending. Call
sms.optOuts.check()before sending to any number you do not send to regularly, especially for re-engagement campaigns. - Honor opt-outs immediately. AWS automatically blocks messages to opted-out numbers, but syncing your own database ensures you don’t attempt sends that will fail.
- Provide a clear opt-in. Only send to numbers where you have explicit written consent. Document how and when consent was obtained.
- Respect QUIET_TIME. Avoid sending promotional messages late at night or early in the morning for the recipient’s time zone.
- Identify your business. Include your company name in every message so recipients know who is contacting them.
