Skip to main content

Event listeners

ChatUI SDK dispatches events from NCChatUIApplication. Your app can subscribe to them and, for some events, override the default behavior with ChatUIEvent methods such as preventDefault and sendResult.

Event names are defined by the ChatUIEvents enum.

TypeScript
import { ChatUIEvents } from '@nexconn/chatui';

Add a listener

TypeScript
app.addEventListener(ChatUIEvents.ALERT_EVENT, (evt) => {
const { data } = evt;
console.log('Alert:', data);
});
ArgumentTypeRequiredDescription
eventTypestringYesA value from ChatUIEvents
listenerfunctionYesCallback receiving a concrete event object (extends ChatUIEvent)
targetobjectNoOptional this binding

ChatUIEvent

Callbacks receive ChatUIEvent or a subclass.

preventDefault

For events whose dispatch path checks it, blocks the SDK default behavior (for example a built-in dialog). Example with ALERT_EVENT:

TypeScript
const listener = (evt) => {
const { data } = evt;
evt.preventDefault();
alert(data);
};

app.addEventListener(ChatUIEvents.ALERT_EVENT, listener);

stopImmediatePropagation

Stops later listeners for the same event object.

TypeScript
const listener = (evt) => {
evt.stopImmediatePropagation();
};

sendResult

Some events expect a result back from your code. When that happens, call sendResult once. CONFIRM_EVENT is the most common example:

TypeScript
const listener = (evt) => {
const { data } = evt;
evt.preventDefault();
const ok = window.confirm(String(data));
evt.sendResult(ok);
};

app.addEventListener(ChatUIEvents.CONFIRM_EVENT, listener);

Only the first sendResult call is used. Later calls log an error and do not change the result.

Remove a listener

TypeScript
app.removeEventListener(ChatUIEvents.ALERT_EVENT, listener);

Event catalog

Primary events exported on ChatUIEvents (see @nexconn/chatui for the full list):

ConstantDescription
ALERT_EVENTInformational alert
CONFIRM_EVENTConfirmation dialog; may use sendResult with a boolean
MEDIA_MESSAGE_MODAL_EVENTMedia message modal
COMBINE_MESSAGE_MODAL_EVENTCombined forward / chat history modal
FORWARDING_EVENTForward modal; may use ModalForwardingResult
TAKE_PHOTO_MODAL_EVENTCamera capture modal
UNSCHEDULED_MESSAGESMessages not handled by the default UI path
CHANNEL_PANEL_EXTENSION_TOUCHChannel header extension button
SYSTEM_CHANNEL_OPENINGBuilt-in channel-list flow before opening a system channel
CHANNELS_MENU_ITEM_CLICKChannel list context menu item
INPUT_MENU_ITEM_CLICKInput toolbar item
CHANNEL_SELECTEDActive channel changed
CHANNEL_ICON_CLICKChannel avatar clicked
CHANNEL_NAVI_CLICKChannel navigation area clicked
MESSAGE_MENU_ITEM_CLICKMessage context menu item
MESSAGE_LINK_CLICKLink inside a message
DOWNLOAD_LINK_EVENTMedia download
FILE_SEND_FAILED_EVENTFile send failed
MESSAGES_DELETEDMessages deleted notification
TOAST_EVENTToast notification

System channel opening

SYSTEM_CHANNEL_OPENING is dispatched when a user opens a system channel from ChatUI's built-in channel list, before ChatUI opens the channel.

In the current implementation, treat SYSTEM_CHANNEL_OPENING as an observation event. Do not rely on preventDefault() to cancel the built-in system-channel opening flow until the SDK confirms cancellation support for this event.

Programmatic calls such as app.openChannel(new SystemChannelIdentifier(...)) do not dispatch SYSTEM_CHANNEL_OPENING. Listen to CHANNEL_SELECTED if you need to observe all channel changes, including direct calls to openChannel.