/** * Message object — represents an SMS/MMS message in the RELAY messaging namespace. * * A Message tracks the lifecycle of a sent or received message via state events. * Outbound messages progress through: queued -> initiated -> sent -> delivered * (or undelivered/failed). Inbound messages arrive fully formed with state "received". */ import { RelayEvent } from './RelayEvent.js'; import type { CompletedCallback, EventHandler } from './types.js'; /** * SMS/MMS message in the RELAY messaging namespace. * * Outbound messages progress through `queued` → `initiated` → `sent` → `delivered` * (or `undelivered` / `failed`). Inbound messages arrive with state `received`. * Call {@link Message.wait} to await a terminal state. * * @example Wait for delivery confirmation * ```ts * const msg = await client.sendMessage({ * to: '+15551234567', * from: '+15557654321', * body: 'Your code is 4242', * }); * * const final = await msg.wait(30); // seconds * console.log('Final state:', final.params.message_state); * ``` */ export declare class Message { /** Unique message identifier assigned by the platform. */ messageId: string; /** RELAY context the message belongs to. */ context: string; /** `"inbound"` or `"outbound"`. */ direction: string; /** Sender phone number in E.164 format. */ fromNumber: string; /** Destination phone number in E.164 format. */ toNumber: string; /** Plain-text message body. */ body: string; /** Media URLs attached to the message (MMS). */ media: string[]; /** Number of segments the carrier split the message into. */ segments: number; /** Current message state (e.g. `"sent"`, `"delivered"`, `"failed"`). */ state: string; /** Failure / undelivery reason when `state` is non-successful. */ reason: string; /** Opaque tags attached to the message. */ tags: string[]; private _done; /** @internal */ _onCompleted: CompletedCallback | null; private _listeners; constructor(options?: { messageId?: string; context?: string; direction?: string; fromNumber?: string; toNumber?: string; body?: string; media?: string[]; segments?: number; state?: string; reason?: string; tags?: string[]; }); /** True once the message has reached a terminal state. */ get isDone(): boolean; /** Final event that terminated the message, or `null` if still in-flight. */ get result(): RelayEvent | null; private _result; /** * Register an event listener for state changes on this message. * * The handler fires every time the server emits a `messaging.state` event * for this message (multiple listeners are supported). Listener errors are * logged but do not disrupt dispatch. * * @param handler - Callback invoked for each state-change event. */ on(handler: EventHandler): void; /** * Wait for the message to reach a terminal state (`delivered`, `failed`, * `undelivered`, etc.). * * @param timeout - Maximum time to wait in **seconds** (matches the Python * SDK convention — not milliseconds). * @returns The final `messaging.state` {@link RelayEvent}. * @throws {Error} When the optional timeout elapses before a terminal state. */ wait(timeout?: number): Promise; /** @internal Handle a messaging.state event for this message. */ _dispatchEvent(payload: Record): Promise; private _resolve; /** * Return a human-readable diagnostic string. * * @returns `Message(id=..., direction=..., state=..., from=..., to=...)` — * handy for log output. */ toString(): string; }