Real-time Communication
Real-time communication requires listening for events related to new messages.
Types of Events
Thread events:
threadCreated
- triggers when a new Thread is created in your ContextthreadDeleted
- triggers when a Thread is deleted from your ContextthreadUpdated
- triggers when a Thread is updatedthreadStatsChanged
- triggers when a message is sent to a thread or a message has been deleted
Message events:
threadNewMessage
- triggers a message was sent to a ThreadthreadDeletedMessage
triggers when a message was deleted from a ThreadthreadMessageUpdated
- triggers when a message was updated
Handling Thread and Message Events
Before receiving Events, your application has to start an event loop and subscribe to a specific channel. Afterwards you can setup a listener.
Here is an example how to do it in your own project:
// Starting the Event Loop
await Endpoint.startEventLoop();
// Handling Thread events
const threadChannel = await Endpoint.connection().threads.subscribeToThreadEvents();
threadChannel.on('threadCreated', (payload) => console.log(payload));
//Handling message Events
const messageChannel = await Endpoint.connection().thread('THREAD_ID').subscribeToMessageEvents();
messageChannel.on('threadNewMessage', (payload) => console.log(payload));
For JavaScript reference go here.