wait

View as MarkdownOpen in Claude

Await until the message reaches a terminal state (delivered, undelivered, or failed). Returns the terminal RelayEvent.

Throws an Error if timeout is specified and the message does not reach a terminal state within the given duration.

Parameters

timeout
number | undefined

Maximum seconds to wait (matches Python SDK convention). undefined waits indefinitely.

Returns

Promise<RelayEvent> — The event that caused the message to reach its terminal state. Inspect message.state for the final state value.

Example

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_TOKEN!,
contexts: ['default']
});
await client.connect();
const message = await client.sendMessage({
toNumber: '+15551234567',
fromNumber: '+15559876543',
body: 'Your verification code is 123456',
});
try {
const event = await message.wait(30);
if (message.state === 'delivered') {
console.log('Message delivered successfully');
} else {
console.log(`Message failed: ${message.reason}`);
}
} catch (err) {
console.log('Timed out waiting for delivery confirmation');
}
await client.disconnect();