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.
The following examples show different ways to use once:
// Run handler only on first sendinstance.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 readyinstance.once('chat:ready', (event, instance) => { console.log('Performing one-time initialization'); instance.updateCustomHeaderItems([/* ... */]);});
Do you need practical examples?
Learn how to apply the features available for embedded chat into your implementation with guidance and examples.