Skip to main content

Messaging

Access the Messaging API. You can instantiate a Messaging.Client to send or receive SMS and MMS.

info

For a full list of events a Messaging.Client can subscribe to, refer to Messaging Events.

Example

The following example listens for incoming SMS messages over the office topic, and responds to them with a Hello World! message.

import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here"})

let messageClient = client.messaging;

await messageClient.listen({
topics: ["office"],
async onMessageReceived(message) {
console.log("Received message", message);
const response = await messageClient.send({
from: message.to,
to: message.from,
body: "Hello World!"
});
console.log("Sent message", await response);
}
})

In the example above:

  • We import the SignalWire library and instantiate a Messaging.Client.
  • The application uses the listen method to subscribe to incoming SMS messages on the office topic.
  • When the application receives a message, it logs the incoming message and responds with a "Hello World!" message using the send method.

Classes