Quick Reference for AI Agents & Developers
- Build request:
ConversationRequest.ConversationRequestBuilder(limit:).build() - Fetch conversations:
conversationsRequest.fetchNext(onSuccess:onError:) - Filters:
.setConversationType(conversationType:),.setTags(_:),.withUserAndGroupTags() - Related: Delete Conversation · Messaging Overview
Object Structures
Conversation Object
TheConversation object represents a conversation in CometChat.
For other object structures, see Send Message - Object Structures.
Retrieve List of Conversations
In other words, as a logged-in user, how do I retrieve the latest conversations that I’ve been a part of? To fetch the list of conversations, you can use theConversationsRequest class. To use this class i.e. to create an object of the ConversationsRequest class, you need to use the ConversationsRequestBuilder class. The ConversationsRequestBuilder class allows you to set the parameters based on which the conversations are to be fetched.
Set Limit
This method sets the limit i.e. the number of conversations that should be fetched in a single iteration.- Swift
A Maximum of only 50 Conversations can be fetched at once. If you want to fetch more conversations, you can use the
fetchNext() on the same conversationsRequest object.Set Conversation Type
This method can be used to fetch user or group conversations specifically. TheconversationType variable can hold one of the below two values:
CometChat.ConversationType.user- Only fetches user conversations.CometChat.ConversationType.group- Only fetches group conversations.
- Swift (User)
- Swift (Group)
With User and Group Tags
This method can be used to fetch the user/group tags in theConversation Object. By default the value is false.
- Swift
Set User Tags
This method fetches user conversations which have the specified tags.- Swift
Set Group Tags
This method fetches group conversations which have the specified tags.- Swift
With Tags
This method makes sure that the tags associated with the conversations are returned along with the other details of the conversations. The default value for this parameter isfalse.
- Swift
Set Tags
This method helps you fetch the conversations based on the specified tags.- Swift
Include Blocked Users
This method helps you fetch the conversations of users whom the logged-in user has blocked.- Swift
With Blocked Info
This method helps you fetch the blocked information in theConversation object.
- Swift
Search Conversations
This method helps you search a conversation based on User or Group name.This feature is only available with
Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)- Swift
Unread Conversations
This method helps you fetch unread conversations.This feature is only available with
Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)- Swift
Fetch Conversations
Finally, once all the parameters are set to the builder class, you need to call thebuild() method to get the object of the ConversationsRequest class.
Once you have the object of the ConversationsRequest class, you need to call the fetchNext() method. Calling this method will return a list of Conversation objects containing X number of conversations depending on the limit set.
- Swift (User)
- Swift (Group)
Conversation object consists of the following fields:
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
conversationsRequest.fetchNext(onSuccess:onError:)Object Type: ConversationRequestMore Sample Payloads
More Sample Payloads
- Group Conversation
- With Media Last Message
Tag Conversation
In other words, as a logged-in user, how do I tag a conversation? To tag a specific conversation, you can use thetagConversation() method. The tagConversation() method accepts three parameters:
conversationWith: UID/GUID of the user/group whose conversation you want to tag.conversationType: TheconversationTypevariable can hold one of the below two values:user- Only fetches user conversation.group- Only fetches group conversations.
tags: Thetagsvariable will be a list of tags you want to add to a conversation.
- Swift
The tags for conversations are one-way. This means that if user A tags a conversation with user B, that tag will be applied to that conversation only for user A.
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
CometChat.tagConversation(conversationWith:conversationType:tags:onSuccess:onError:)tags (
[String]):Retrieve Single Conversation
In other words, as a logged-in user, how do I retrieve a specific conversation? To fetch a specific conversation, you can use thegetConversation method. The getConversation method accepts two parameters:
conversationWith: UID/GUID of the user/group whose conversation you want to fetch.conversationType: TheconversationTypevariable can hold one of the below two values:user- Only fetches user conversation.group- Only fetches group conversations.
- Swift (User)
- Swift (Group)
Sample Payloads
Sample Payloads
- Request
- Success Response
- Error Response
Method:
CometChat.getConversation(conversationWith:conversationType:onSuccess:onError:)More Sample Payloads - Single Conversation
More Sample Payloads - Single Conversation
- Group Conversation
- With Custom Message
Get Conversation From Message
For real-time events, you will always receive Message objects and not Conversation objects. Thus, you will need a mechanism to convert the Message object to aConversation object. You can use the getConversationFromMessage() method of the CometChat class.
- Swift
While converting a
Message object to a Conversation object, the unreadMessageCount & tags will not be available in the Conversation object. The unread message count needs to be managed in your client-side code.Sample Payloads
Sample Payloads
- Request
- Success Response