> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # onMessage > Register the inbound message handler. [message]: /docs/server-sdks/reference/typescript/relay/message Register the inbound SMS/MMS message handler. The provided function is called for each `messaging.receive` event on the subscribed contexts. The function receives a [`Message`][message] object with message properties and state tracking. Only one message handler can be active at a time. Calling `onMessage()` again replaces the previous handler. ## **Parameters** **`handler`** `MessageHandler` — required An async function that receives a [`Message`][message] object. Signature: `(message: Message) => void | Promise`. --- ## **Returns** `MessageHandler` — the same handler, returned to support decorator-style usage (e.g., TypeScript 5 decorators or manual composition). ## **Example** ```typescript {9} import { RelayClient } from '@signalwire/sdk'; const client = new RelayClient({ project: process.env.SIGNALWIRE_PROJECT_ID!, token: process.env.SIGNALWIRE_API_TOKEN!, contexts: ['default'] }); client.onMessage(async (message) => { console.log(`SMS from ${message.fromNumber}: ${message.body}`); }); await client.run(); ``` > Register the inbound message handler.