> 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. # on > Register an event listener for state changes on this message. [relayevent]: /docs/server-sdks/reference/typescript/relay/events Register an event listener for state changes on this message. The handler is called each time a `messaging.state` event is received for this message, allowing you to react to intermediate states before the terminal state is reached. ## **Parameters** **`handler`** `(event: RelayEvent) => void | Promise` — required A function that receives a [`RelayEvent`][relayevent] on each state change. Both synchronous and async handlers are supported. --- ## **Returns** `void` ## **Example** ```typescript {21} import { RelayClient } from '@signalwire/sdk'; const client = new RelayClient({ project: process.env.SIGNALWIRE_PROJECT_ID!, token: process.env.SIGNALWIRE_API_TOKEN!, contexts: ['default'] }); await client.connect(); const message = await client.sendMessage({ toNumber: '+15551234567', fromNumber: '+15559876543', body: 'Order confirmed', }); const onStateChange = (event) => { console.log(`Message ${message.messageId} -> ${message.state}`); }; message.on(onStateChange); await message.wait(); await client.disconnect(); ``` > Register an event listener for state changes on this message.