---title: Client---import MethodOff from ../../_common/_method_off.mdx;import MethodOn from ../../_common/_method_on.mdx;import MethodOnce from ../../_common/_method_once.mdx;import MethodRemoveAllListeners from ../../_common/_method_removealllisteners.mdx;You can use instances of this class to send or receive messages.#### Examplejavascriptimport { Messaging } from @signalwire/realtime-api;const client = new Messaging.Client({ project: , token: , contexts: [office],});client.on(message.received, (message) => { console.log(message.received, message);});await client.send({ context: office, from: +1xxx, to: +1yyy, body: Hello World!,});## Constructors### constructor• **new Client**(opts)#### Parameters| Name | Type | Description || :-------------- | :--------- | :------------------------------------------------------------------------------- || opts | Object | - || opts.contexts | string[] | SignalWire contexts, e.g. [home, office]. || opts.project | string | SignalWire Project ID, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f. || opts.token | string | SignalWire API token, e.g. PT9e5660c101cd140a1c93a0197640a369cf5f16975a0079c9. |## Methods### disconnect▸ **disconnect**(): voidDisconnects this client. The client will stop receiving events and you will need to create a new instance if you want to use it again.#### Returnsvoid#### Examplejsclient.disconnect();---### off ---### on ---### once ---### removeAllListeners ---### send▸ **send**(params): Promise<[MessagingSendResult](./messaging-messagingsendresult.md)\>Send an outbound SMS or MMS message.#### Parameters| Name | Type | Description || :---------------- | :--------- | :---------------------------------------------------------------------------------------------------------------------------- || params | Object | - || params.body? | string | The content of the message. Optional if media is present. || params.context? | string | Inbound events for the message will be received on this context. If not specified, a default context will be used. || params.from | string | The phone number to place the message from. Must be a SignalWire phone number or short code that you own. || params.media? | string[] | Array of URLs to send in the message. Optional if body is present. || params.region? | string | Region of the world to originate the message from. A default value is picked based on account preferences or device location. || params.tags? | string[] | Array of strings to tag the message with for searching in the UI. || params.to | string | The phone number to send to. |#### ReturnsPromise<[MessagingSendResult](./messaging-messagingsendresult.md)\>Asynchronously returns a result object.#### Example> Send a message.jstry { const sendResult = await client.send({ from: +1xxx, to: +1yyy, body: Hello World!, }); console.log(Message ID: , sendResult.messageId);} catch (e) { console.error(e.message);}## Events### message.received• **message.received**(message)Emitted whenever a message is received. Your event handler receives a message object. Example:javascriptconst client = new Messaging.Client(...)client.on(message.received, (message) => { console.log(Message received:, message) // message.from // message.to // message.body // ...})#### Parameters| Name | Type | Description || :-------- | :-------------------------------------------------- | :---------------------------------- || message | [MessageContract](./messaging-messagecontract.md) | The message that has been received. |---### message.updated• **message.updated**(message)Emitted when the status of a message is updated. You can use this event to track the different stages that an outbound message goes through for delivery. Example:javascriptconst client = new Messaging.Client(...)client.on(message.updated, (message) => { console.log(Message updated:, message) // message.from // message.to // message.direction // message.state // ...})client.send(...)#### Parameters| Name | Type | Description || :-------- | :-------------------------------------------------- | :----------- || message | [MessageContract](./messaging-messagecontract.md) | The message. |