> ## Documentation Index
> Fetch the complete documentation index at: https://developer.watson-orchestrate.ibm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# once()

Subscribes a handler function to an event so it runs only once when that event occurs. After the event fires, the handler is automatically removed and is not called again.

## Syntax

```javascript theme={null}
instance.once(eventName, handler);
```

## Parameters

<ParamField path="eventName" type="string" required>
  The name of the event to subscribe to.
</ParamField>

<ParamField path="handler" type="function" required>
  The callback function to run once when the event occurs. Receives `(event, instance)` as parameters.
</ParamField>

## Returns

<ResponseField name="void">
  Returns a `void` operator.
</ResponseField>

## Examples

The following examples show different ways to use once:

```javascript theme={null}
// Run handler only on first send
instance.once('pre:send', (event, instance) => {
    console.log('First message being sent');
    event.message.message.content = event.message.message.content.toUpperCase();
});

// Initialize something once when chat is ready
instance.once('chat:ready', (event, instance) => {
    console.log('Performing one-time initialization');
    instance.updateCustomHeaderItems([/* ... */]);
});
```

<Card title="Do you need practical examples?" icon="text-align-start" href="https://www.ibm.com/docs/SSAVQO/deploy/web_chat_agent/tutorials/tutorials_lp.html" arrow="true" cta="Learn with walk-throughs" horizontal>
  Learn how to apply the features available for embedded chat into your implementation with guidance and examples.
</Card>
