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 number of milliseconds to wait. 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

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9await client.connect();
10
11const message = await client.sendMessage({
12 to: '+15551234567',
13 from: '+15559876543',
14 body: 'Your verification code is 123456',
15});
16
17try {
18 const event = await message.wait(30_000);
19 if (message.state === 'delivered') {
20 console.log('Message delivered successfully');
21 } else {
22 console.log(`Message failed: ${message.reason}`);
23 }
24} catch (err) {
25 console.log('Timed out waiting for delivery confirmation');
26}
27
28await client.disconnect();