Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Event Handling


The Conversations (classic) SDK is event-driven. Objects from the SDK will emit real-time events based on state changes in your Conversations (classic) instance. You can use these events to update your application's state and UI.


Which objects emit events?

which-objects-emit-events page anchor

The SDK emits events on several objects (i.e. Client, Conversation, User, etc.).

These events are emitted, for example, when:

  • A new Message is added to a Conversation that you are participating in
  • The connection state of your Client changes
  • A Participant leaves a Conversation
  • A User comes online
  • Your Access Token is about to expire
  • The friendlyName of a Conversation is updated

A full list of events and objects can be found by referring to our generated SDK documentation:

Event HandlingLink to code sample: Event Handling
1
/* event handler examples */
2
3
client.on('conversationUpdated', ({ conversation, updateReasons }) => {
4
// Fired when the attributes or the metadata of a conversation have been updated
5
});
6
7
conversation.on('messageUpdated', ({ message, updateReasons }) => {
8
// Fired when data of a message has been updated.
9
});
10
11
participant.on('updated', ({ participant, updateReasons }) => {
12
// Fired when the fields of the participant have been updated.
13
});

Best practices and tips for listening to events

best-practices-and-tips-for-listening-to-events page anchor
  • For the JavaScript SDK, you can receive most events from the Client object. This is more performant in browsers and recommended over setting up duplicate handlers on each Conversation/User. You can also set up handlers on specific objects (e.g. Conversation, User) as needed.
  • For the iOS SDK, all events are emitted at the top level TwilioConversationsClientDelegate.
  • For the Android SDK, only some events are emitted from the ConversationsClientListener. Other events are available from the ConversationListener and MediaUploadListener.

As a next step, you can visit the following guides: