Event bus (real-time updates)

Use sdk.eventBus to receive conversation activity live: messages, conversation events and updates, and typing indicators for the conversations the signed-in person takes part in, plus occasional system broadcasts. It connects on first access and reconnects automatically after connection failures. It is not a change feed, and there are no webhooks; to keep other data in sync, poll list endpoints (the client revalidates them with ETags). See Events on the developer portal.

Accessing the event bus

The examples assume a configured sdk from Getting started. In React, get it with useSoliboApi() inside a SoliboProvider.

Read sdk.eventBus after sign-in: the first read opens the connection at once, and a connection opened before sign-in is refused until a reconnect carries the new session.

Subscribing to events

onEvent returns an unsubscribe function. Call it when the screen or component no longer needs updates.

With multiple onEvent listeners, each event reaches only one listener. Use one app-level subscription and distribute events when several screens need the same updates.

import no.solibo.oss.sdk.api.gen.models.ConversationMessagePayload

val unsubscribe = sdk.eventBus.onEvent { event ->
    val payload = event.payload
    if (payload is ConversationMessagePayload) {
        println("New message: ${payload.message.content}")
    }
}

// When leaving the screen:
// unsubscribe()
import { useEffect } from 'react';
import { ConversationMessagePayload } from '@solibo/solibo-sdk';
import { useSoliboApi } from '@solibo/solibo-react';

function ChatUpdates() {
  const { eventBus } = useSoliboApi();

  useEffect(() => eventBus.onEvent(({ payload }) => {
    if (payload instanceof ConversationMessagePayload) {
      console.log('New message:', payload.message.content);
    }
  }), [eventBus]);

  return null;
}

Sending commands

The bus accepts two commands, typing indicators and ping; connecting is the subscription. Use send in Kotlin or sendJs in TypeScript. For example, send a typing indicator:

import no.solibo.oss.sdk.api.gen.models.Typing

// Inside a coroutine:
sdk.eventBus.send(
    Typing(companyId = companyId, conversationId = conversationId, typing = true)
)
import { Typing } from '@solibo/solibo-sdk';

sdk.eventBus.sendJs(new Typing(BigInt(companyId), BigInt(conversationId), true));

Error handling

Subscribe to connection and decoding errors with onError. It also returns an unsubscribe function. onError also reports decode error: … for payload types newer than your SDK; those events are dropped, and the connection stays up.

val unsubscribeErrors = sdk.eventBus.onError { error ->
    println("Event bus error: $error")
}
const unsubscribeErrors = sdk.eventBus.onError((error) => {
  console.error('Event bus error:', error);
});

Connection lifecycle

Unsubscribing removes a listener without closing the shared connection. Use eventBus.stop() only when disposing of the SDK; it permanently closes that event bus. Call it from a Kotlin coroutine or await it in TypeScript. Create a new SDK instance if you need a connection afterward.

See the AsyncAPI viewer for available messages and commands, or download the AsyncAPI definition.


Solibo AS