AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Key Classes | CometChatMessageDelegate, MessagesRequest.MessageRequestBuilder |
| Key Methods | onTextMessageReceived(), onMediaMessageReceived(), onCustomMessageReceived(), fetchPrevious(), fetchNext() |
| Delegate | CometChat.messagedelegate = self |
| Prerequisites | SDK initialized, user logged in |
- Adding a real-time listener to receive messages while your app is running
- Fetching unread or historical messages when your app starts up or the user scrolls back
Real-Time Messages
Register aCometChatMessageDelegate to receive incoming messages as they arrive. Each callback receives the specific message subclass — TextMessage, MediaMessage, or CustomMessage.
- Swift
- Objective-C
viewDidLoad():
Missed Messages
Fetch messages that were sent while the app was offline usingMessagesRequest with setMessageId() set to the last delivered message ID.
Fetch Missed Messages of a particular one-on-one conversation
Fetch Missed Messages of a particular group conversation
Unread Messages
Fetch unread messages by addingsetUnread(true) to the builder. Use fetchPrevious() to retrieve them.
Message History
Fetch the full conversation history usingfetchPrevious(). Call it repeatedly on the same request object to paginate.
The list of messages received is in the form of
BaseMessage objects. A BaseMessage can be a TextMessage, MediaMessage, or CustomMessage. Use type casting to check the type.Next Steps
Delivery & Read Receipts
Track when messages are delivered and read by recipients
Typing Indicators
Show real-time typing status in conversations