← All @molecule/* packages · App templates
@molecule/api-smsCore interface · sms · API (Node) · v1.0.1 · Apache-2.0
SMS core interface for molecule.dev
npm install @molecule/api-sms@molecule/api-sms is the sms core interface on the API (Node) side: the API your app calls, with no vendor inside.
Choose the implementation by bonding one of its 3 providers: @molecule/api-sms-capture, @molecule/api-sms-twilio, @molecule/api-sms-vonage.
import { setProvider, send, getStatus } from '@molecule/api-sms'
import { createProvider } from '@molecule/api-sms-twilio' // bonds export createProvider(), not a prebuilt provider
// Bond a provider at startup (credentials come from env — see the bond's docs)
setProvider(createProvider())
// Send a message
const result = await send('+1234567890', 'Hello from Molecule!')
// Check delivery status (provider-dependent — see @remarks)
const status = await getStatus(result.id)
console.log(status.status) // 'delivered'Providers (3): @molecule/api-sms-capture, @molecule/api-sms-twilio, @molecule/api-sms-vonage
Works with: @molecule/api-bond, @molecule/api-i18n
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
SMS core interface for molecule.dev.
Defines the standard interface for SMS messaging providers (Twilio, Vonage, etc.).
import { setProvider, send, getStatus } from '@molecule/api-sms'
import { createProvider } from '@molecule/api-sms-twilio' // bonds export createProvider(), not a prebuilt provider
// Bond a provider at startup (credentials come from env — see the bond's docs)
setProvider(createProvider())
// Send a message
const result = await send('+1234567890', 'Hello from Molecule!')
// Check delivery status (provider-dependent — see @remarks)
const status = await getStatus(result.id)
console.log(status.status) // 'delivered'
core
npm install @molecule/api-sms @molecule/api-bond @molecule/api-i18n
BulkSMSMessageA single message in a bulk send operation.
interface BulkSMSMessage {
/** Recipient phone number. */
to: string
/** Message body text. */
message: string
/** Per-message send options. */
options?: SMSOptions
}
BulkSMSResultResult of a bulk SMS send operation.
interface BulkSMSResult {
/** Individual results for each message in the batch. */
results: SMSResult[]
/** Total number of messages in the batch. */
total: number
/** Number of messages that were successfully queued or sent. */
successful: number
/** Number of messages that failed. */
failed: number
}
SMSOptionsOptions for sending an SMS message.
interface SMSOptions {
/** Sender phone number or alphanumeric ID. */
from?: string
/** Schedule the message for future delivery. */
scheduledAt?: Date
/** URL to receive delivery status callbacks. */
callbackUrl?: string
}
SMSProviderSMS provider interface.
All SMS providers must implement this interface to provide send, bulk send, and status query capabilities.
interface SMSProvider {
/**
* Sends a single SMS message.
*
* @param to - Recipient phone number in E.164 format.
* @param message - Message body text.
* @param options - Optional send configuration.
* @returns The send result with message ID and status.
*/
send(to: string, message: string, options?: SMSOptions): Promise<SMSResult>
/**
* Sends multiple SMS messages in a single batch.
*
* @param messages - Array of messages to send.
* @returns Aggregated results for the entire batch.
*/
sendBulk(messages: BulkSMSMessage[]): Promise<BulkSMSResult>
/**
* Retrieves the delivery status of a previously sent message.
*
* @param messageId - The provider-assigned message identifier.
* @returns Current delivery status information.
*/
getStatus(messageId: string): Promise<SMSStatus>
}
SMSResultResult of sending a single SMS message.
interface SMSResult {
/** Provider-assigned message identifier. */
id: string
/** Current delivery status. */
status: 'queued' | 'sent' | 'delivered' | 'failed'
/** Recipient phone number. */
to: string
}
SMSStatusDelivery status information for a previously sent message.
interface SMSStatus {
/** Provider-assigned message identifier. */
id: string
/** Current delivery status. */
status: 'queued' | 'sent' | 'delivered' | 'failed'
/** When the message was delivered, if applicable. */
deliveredAt?: Date
/** Error description if the message failed. */
error?: string
}
getProvider()Retrieves the bonded SMS provider, throwing if none is configured.
function getProvider(): SMSProvider
Returns: The bonded SMS provider.
getStatus(messageId)Retrieves the delivery status of a previously sent message.
function getStatus(messageId: string): Promise<SMSStatus>
messageId — The provider-assigned message identifier.Returns: Current delivery status information.
hasProvider()Checks whether an SMS provider is currently bonded.
function hasProvider(): boolean
Returns: true if an SMS provider is bonded.
send(to, message, options)Sends a single SMS message using the bonded provider.
function send(to: string, message: string, options?: SMSOptions): Promise<SMSResult>
to — Recipient phone number in E.164 format.message — Message body text.options — Optional send configuration.Returns: The send result with message ID and status.
sendBulk(messages)Sends multiple SMS messages in a single batch using the bonded provider.
function sendBulk(messages: BulkSMSMessage[]): Promise<BulkSMSResult>
messages — Array of messages to send.Returns: Aggregated results for the entire batch.
setProvider(provider)Registers an SMS provider as the active singleton. Called by bond packages during application startup.
function setProvider(provider: SMSProvider): void
provider — The SMS provider implementation to bond.| Provider | Package |
|---|---|
| Capture | @molecule/api-sms-capture |
| Sms | @molecule/api-sms-twilio |
| Sms | @molecule/api-sms-vonage |
Peer dependencies:
@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-bond@molecule/api-i18nDelivery-status polling (getStatus()) is PROVIDER-DEPENDENT, not a
universal capability — the Quick Start's getStatus() call is not safe to
assume for every bonded provider:
@molecule/api-sms-twilio: supported — polls the Twilio REST API.@molecule/api-sms-vonage: NOT supported — getStatus() always throws
'Vonage SMS API does not support message status polling.'. Vonage only
reports delivery via DLR (delivery receipt) webhooks: pass
options.callbackUrl to send()/sendBulk() and receive delivery
updates on that endpoint instead of polling.Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
read_activity tool (filter type 'sms'); the code/link is in
its payload. Never mock the flow or modify production code to expose it.