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.
import { ChatUIEvents } from '@nexconn/chatui';
Add a listener
app.addEventListener(ChatUIEvents.ALERT_EVENT, (evt) => {
const { data } = evt;
console.log('Alert:', data);
});
| Argument | Type | Required | Description |
|---|---|---|---|
| eventType | string | Yes | A value from ChatUIEvents |
| listener | function | Yes | Callback receiving a concrete event object (extends ChatUIEvent) |
| target | object | No | Optional 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:
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.
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:
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
app.removeEventListener(ChatUIEvents.ALERT_EVENT, listener);
Event catalog
Primary events exported on ChatUIEvents (see @nexconn/chatui for the full list):
| Constant | Description |
|---|---|
| ALERT_EVENT | Informational alert |
| CONFIRM_EVENT | Confirmation dialog; may use sendResult with a boolean |
| MEDIA_MESSAGE_MODAL_EVENT | Media message modal |
| COMBINE_MESSAGE_MODAL_EVENT | Combined forward / chat history modal |
| FORWARDING_EVENT | Forward modal; may use ModalForwardingResult |
| TAKE_PHOTO_MODAL_EVENT | Camera capture modal |
| UNSCHEDULED_MESSAGES | Messages not handled by the default UI path |
| CHANNEL_PANEL_EXTENSION_TOUCH | Channel header extension button |
| SYSTEM_CHANNEL_OPENING | Built-in channel-list flow before opening a system channel |
| CHANNELS_MENU_ITEM_CLICK | Channel list context menu item |
| INPUT_MENU_ITEM_CLICK | Input toolbar item |
| CHANNEL_SELECTED | Active channel changed |
| CHANNEL_ICON_CLICK | Channel avatar clicked |
| CHANNEL_NAVI_CLICK | Channel navigation area clicked |
| MESSAGE_MENU_ITEM_CLICK | Message context menu item |
| MESSAGE_LINK_CLICK | Link inside a message |
| DOWNLOAD_LINK_EVENT | Media download |
| FILE_SEND_FAILED_EVENT | File send failed |
| MESSAGES_DELETED | Messages deleted notification |
| TOAST_EVENT | Toast 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.