MessageContract
An object representing an SMS or MMS message.
Properties
The topic the message-object is associated with. Topic was previously called context.
The current state of the message. See MessagingMessageState.
Type Aliases
MessagingMessageState
Ƭ MessagingMessageState: "queued" | "initiated" | "sent" | "delivered" | "undelivered" | "failed"
The state a message can be in.
queued: The message has been queued in Relay.initiated: Relay has initiated the process of sending the message.sent: Relay has sent the message.delivered: The message has been successfully delivered. Due to the nature of SMS and MMS, receiving adeliveredevent is not guaranteed, even if the message is delivered successfully.undelivered: The message has not been delivered. Due to the nature of SMS and MMS, receiving aundeliveredevent is not guaranteed, even if the message fails to be delivered.failed: The request has failed.
Example
Listening for incoming and outgoing messages:
import { SignalWire } from "@signalwire/realtime-api";
const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
await client.messaging.listen({
topics: ["my-topic"],
onMessageReceived: (message) => {
console.log("Message ID:", message.id);
console.log("From:", message.from);
console.log("To:", message.to);
console.log("Body:", message.body);
console.log("Direction:", message.direction);
console.log("State:", message.state);
console.log("Segments:", message.segments);
if (message.media.length > 0) {
console.log("Media URLs:", message.media);
}
},
onMessageUpdated: (message) => {
console.log("Message updated:", message.id);
console.log("New state:", message.state);
if (message.state === "failed" && message.reason) {
console.log("Failed reason:", message.reason);
}
}
});