Skip to content

Chat Events

Listen to native Crisp SDK events through a single broadcast stream — session loaded, chat opened/closed, and message sent/received. Useful for updating an unread badge in real time instead of polling getUnreadMessageCount.

Platform support

PlatformSupport
AndroidNative SDK: Crisp.addCallback(EventsCallback)
iOSNative SDK: CrispSDK.addCallback(Callback)
WebNot supported — the stream never emits
DesktopNot supported — the stream never emits

CrispEventType.notificationReceived is Android-only — the iOS Crisp SDK has no matching callback, so iOS never emits it.

Listening to events

dart
final subscription = FlutterCrispChat.onCrispEvent.listen((event) {
  switch (event.type) {
    case CrispEventType.sessionLoaded:
      print('Session loaded: ${event.sessionId}');
    case CrispEventType.chatOpened:
      print('Chat opened');
    case CrispEventType.chatClosed:
      print('Chat closed');
    case CrispEventType.messageSent:
    case CrispEventType.messageReceived:
      print('Message from ${event.message?.from}: ${event.message?.text}');
    case CrispEventType.notificationReceived:
      print('Notification data: ${event.notificationData}'); // Android-only
  }
});

// Later, when no longer needed:
await subscription.cancel();

onCrispEvent is a broadcast stream — the native event callback is registered on the first .listen() call and unregistered once the last listener cancels. It's safe to listen and cancel freely; there's no need to manage a single global subscription.

CrispChatEvent

FieldTypePopulated for
typeCrispEventTypeAlways
sessionIdString?sessionLoaded only
messageCrispMessage?messageSent / messageReceived only
notificationDataMap<String, String>?notificationReceived only (Android-only)

CrispMessage

CrispMessage is a minimal summary, not a full mapping of every native content type:

FieldTypeNotes
isMeboolWhether this device's visitor sent the message
fromCrispMessageSenderuser or operatorUser
originString?Raw origin string from the native SDK (e.g. "chat", "local", "network", "update") — kept as a raw string rather than a strict enum, since Android reports up to 8 distinct values and iOS only 3
timestampDateTimeWhen the message was sent
fingerprintintUnique identifier for this message within the session
contentTypeCrispMessageContentTypetext, file, animation, audio, picker, field, carousel, or unknown
textString?Only populated when contentType is text. iOS's textWithAttachment/textWithVideoAttachment cases both map to contentType: text

Rich content (carousel targets, picker choices, file/audio metadata) is not mapped in this version — only whether a message is text and what that text is.

Next Steps