Conversations
Channelize.io server supports two types of conversation i.e private 1-to-1 and Group conversations. This section contains what all 1-to-1 conversations related actions can be performed using Channelize.io iOS SDK functions.
Get Conversation Count
Retrieves the total number of conversations of a user.
Function
func getConversationsCount(queryBuilder: CHConversationsCountQueryBuilder, completion: @escaping (Int,String?) -> ())
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
queryBuilder | CHConversationsCountQueryBuilder | Yes | Query Builder to generate parameters to call Api |
CHConversationsCountQueryBuilder
Variables
Parameter | Type | Required | Description |
---|---|---|---|
ids | [String] | No | Specifies a comma-separated string of conversation IDs to retrieve. |
isGroup | Bool | No | Restricts the search scope to only retrieve private 1-to-1 or group conversations. Allowed values are true and false. By default, all the conversations are retrieved. |
conversationType | CHConversationType | No | Specifies the type of conversation. Allowed values are private and public. By default, all the conversations are retrieved. |
customTypes | String | No | Specifies a comma-separated string of one or more custom types to filter the conversations. |
searchQuery | String | No | Specifies the name of the conversation to retrieve. |
membersIncluded | [String] | No | Specifies string array of one or more user IDs to restrict search scope. For e.g. ["21544","21567"] |
membersExactly | [String] | No | Searches for conversations with the specified members exactly in. For e.g ["21544","21567"] |
includeDeleted | Bool | No | Determines whether to include deleted conversation in response. |
includeOnlyActive | Bool | No | Restricts the search scope to retrieve only conversations in which the user is active. |
Request Example
let queryBuilder = CHConversationsCountQueryBuilder()
queryBuilder.isGroup = false
queryBuilder.searchQuery = "Football"
queryBuilder.includeDeleted = false
queryBuilder.conversationType = .privateConversation
ChannelizeAPIService.getConversationsCount(queryBuilder: queryBuilder, completion: {(conversationCount,errorString) in
})
Completion Handler
conversationCount
: Indicates count of conversations.errorString
: OptionalString
Indicates if there is an error. It will be null if there is no error.
List Conversations
Retrieves the list of conversations of a user using getConversationsList
function of ChannelizeAPIService
class.
Function
func getConversationList(queryBuilder: CHListConversationsQueryBuilder, completion: @escaping ([CHConversation]?,String?) -> ())
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
queryBuilder | CHListConversationsQueryBuilder | Yes | Query Builder to generate parameters to call Api |
CHListConversationsQueryBuilder
Variables
Parameter | Type | Required | Description |
---|---|---|---|
ids | [String] | No | Specifies a comma-separated string of conversation IDs to retrieve. |
isGroup | Bool | No | Restricts the search scope to only retrieve private 1-to-1 or group conversations. Allowed values are true and false. By default, all the conversations are retrieved. |
conversationType | CHConversationType | No | Specifies the type of conversation. Allowed values are private and public. By default, all the conversations are retrieved. |
customTypes | String | No | Specifies a comma-separated string of one or more custom types to filter the conversations. |
searchQuery | String | No | Specifies the name of the conversation to retrieve. |
membersIncluded | [String] | No | Specifies string array of one or more user IDs to restrict search scope. For e.g. ["21544","21567"] |
membersExactly | [String] | No | Searches for conversations with the specified members exactly in. For e.g ["21544","21567"] |
includeDeleted | Bool | No | Determines whether to include deleted conversation in response. |
includeOnlyActive | Bool | No | Restricts the search scope to retrieve only conversations in which the user is active. |
sorting | CHConversationSorting | No | Specifies the sorting criteria for the returned results. Allowed values are .ASC and .DESC . |
includeMembers | Bool | No | Specifies wether you want to include members in conversation Object |
limit | Int | No | Specifies the number of results to return. |
skip | Int | No | Specifies the number of results you want to skip from the beginning. (Useful in Pagination) |
Request Example
let queryBuilder = CHListConversationsQueryBuilder()
queryBuilder.isGroup = false
queryBuilder.conversationType = .privateConversation
queryBuilder.limit = 25
queryBuilder.skip = 0
queryBuilder.includeMembers = true
ChannelizeAPIService.getConversationList(queryBuilder: queryBuilder, completion: {(conversations,errorString) in
})
Create a Conversation
Creates a new conversation.
Function
func createNewConversation(queryBuilder: CHNewConversationQueryBuilder, profileImageData: Data?, completion: @escaping (CHConversation?,String?) -> ())
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
queryBuilder | CHNewConversationQueryBuilder | Yes | Query Builder to generate parameters to call Api |
profileImageData | Data | No | Image Data for profile image. |
CHNewConversationQueryBuilder
Variables
Parameter | Type | Required | Description |
---|---|---|---|
id | String | No | The unique ID of the conversation. |
isGroup | Bool | No | Determines whether to create a group conversation or private 1-to-1 conversation. If set to true, group conversation will create. If set to false, a private 1-to-1 conversation will create. By Default value is true. |
title | String | Required for group conversation | The title of the conversation. |
conversationType | CHConversationType | No | The conversation type. Allowed values are .privateConversation and .publicConversation . |
customType | String | No | Specify the custom type of conversation which is used for grouping like messaging, live_streaming, gaming etc. |
members | [String] | Yes | Specifies an array of user IDs to add to the conversation. E.g. ["21538", "21589"] |
Request Example
let queryBuilder = CHNewConversationQueryBuilder()
queryBuilder.isGroup = true
queryBuilder.title = "Demo Group"
queryBuilder.conversationType = .publicConversation
queryBuilder.members = ["21538", "21589", "21594"]
ChannelizeAPIService.createNewConversation(queryBuilder: queryBuilder, profileImageData: , completion: {(conversation,errorString) in
guard errorString == nil else {
print("Failed to Create New Conversation")
print("Error: \(errorString)")
return
}
// Use Newly created Conversation
})
Completion Handler
conversation
: Newly Created conversation's object.errorString
: OptionalString
Indicates if there is an error. It will be null if there is no error.
Get a Conversation
Retrieves information about a conversation. You can also get additional details in the conversation object using include parameter.
Function
func getConversationWithId(conversationId: String, includeMembers: Bool = false, completion: @escaping (CHConversation?,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
includeMembers | Bool | No | Wether to include members list in response. By default it is false. |
Request Example
ChannelizeAPIService.getConversationWithId(conversationId: chatId, completion: {(conversation,errorString) in
guard errorString == nil else {
print("Error in Getting Conversation. Error: \(errorString ?? "")")
}
if let recievedConversation = conversation {
// Implement your logic
}
})
Completion Handler
conversation
: Recieved conversation's object.errorString
: OptionalString
Indicates if there is an error. It will be null if there is no error.
Get a Conversation with a user
Retrieves information about a conversation with a user.
Function
func getConversationWithUser(userId: String, completion: @escaping (CHConversation?,String?) -> ())
Request Example
ChannelizeAPIService.getConversationWithUser( userId: "21544", completion: {(conversation,errorString)
guard errorString == nil else {
print("Error in Getting Conversation. Error: \(errorString ?? "")")
}
if let recievedConversation = conversation {
// Implement your logic
}
})
Completion Handler
conversation
: Recieved conversation's object.errorString
: OptionalString
Indicates if there is an error. It will be null if there is no error.
Delete a conversation
Function
func deleteConversation(conversationId: String, completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation to delete. |
Request Example
ChannelizeAPIService.deleteConversation(conversationId: conversationId, completion: {(status,errorSting) in
if status {
print("Conversation Deleted Successfully")
} else {
print("Error in Deleting Conversation. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Clear a Conversation
Function
func clearConversation(conversationId: String, completion: @escaping (Bool,String?) -> ())
Request Example
ChannelizeAPIService.clearConversation(conversationId: conversationId, completion: {(status,errorString) in
if status {
print("Conversation Cleared Successfully")
} else {
print("Error in Clearing Conversation. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Mute or Unmute a Conversation
Function
func muteConversation(conversationId: String, isMute: Bool, completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation on which mute or unmute action to perform. |
isMute | Boolean | Yes | Determines whether to mute or unmute the conversation. If set to true , conversation will mute. If set to false , conversation will unmute. |
Request Example
ChannelizeAPIService.muteConversation(conversationId: conversationId, isMute: false, completion: {(status,errorString) in
if status {
print("Mute status updated Successfully")
} else {
print("Error in updating mute status. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Leave a conversation
Function
func leaveConversation(conversatinoId: String, completion: @escaping (Bool,String?) -> ())
Request Example
ChannelizeAPIService.leaveConversation(conversatinoId: conversationId, completion: {(status,errorString) in
if status {
print("Left conversation Successfully")
} else {
print("Error in leaving conversation. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Update a Conversation Title
Updates the title of a group conversation. Group conversation members with admin permission can perform this action.
Function
func updateConversationTitle(conversationId: String, newTitle: String, completion: @escaping (Bool,String?) ->())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
newTitle | String | Yes | Specifies the new title for the conversation. |
Request Example
ChannelizeAPIService.updateConversationTitle(conversationId: conversationId, newTitle: updatedTitle, completion: {(status,errorString) in
if status {
print("Conversation title updated Successfully")
} else {
print("Error in updating conversation title. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Update a Conversation Profile Image
Updates the profile image of a group conversation. Group conversation members with admin permission can perform this action.
Function
func updateConversationProfileImage(conversationId: String, profileImageUrl: String?, imageData: Data?, completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
profileImageUrl | String | No | Specifies new profile image url for the conversation. |
imageData | Data | No | Image Data for the new profile image. |
Please send either profileImageUrl
or imageData
.
Request Example
let imageData = UIImage(named: "example.png").jpegData(compressionQuality: 0.9)
ChannelizeAPIService.updateConversationProfileImage(conversationId: "20bf7003-7d64-11ea-818d-3feba8c6b791", profileImageUrl: nil, imageData: imageData, completion: {(status,errorString) in
if status {
print("Conversation profile image updated Successfully")
} else {
print("Error in updating conversation profile image. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Add Admin
Grants group admin permission to a user. Only an existing member/participant of the group can be admin of the group conversation. Group conversation members with admin permission can perform this action.
Function
func addAdminToConversation(conversationId: String, userId: String, completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
userId | String | Yes | The unique ID of the user who is going to be the new group conversation admin. |
Request Example
ChannelizeAPIService.addAdminToConversation(conversationId: conversationId, userId: userId, completion: {(status,errorString) in
if status {
print("New Admin added successfully")
} else {
print("Error in adding new admin. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Add Members
Adds a member to the conversation. Group conversation members with admin permission can perform this action.
Function
func addMembersToConversation(conversationId: String, userIds: [String], completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
userIds | [String] | Yes | Specifies an array of user IDs to add to the conversation. E.g. ["20236", "20697", "19116"] |
Request Example
let conversationId = "20bf7003-7d64-11ea-818d-3feba8c6b791"
let userIds = ["20236","20697","19116"]
ChannelizeAPIService.addMembersToConversation(conversationId: conversationId, userIds: userIds, completion: {(status,errorString) in
if status {
print("New Members added successfully")
} else {
print("Error in adding new members. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of result.errorString
: Optional error string if api call was unsuccessful.
Remove Members
Removes a member from the conversation. Group conversation members with admin permission can perform this action.
Function
func removeMemberFromConversation(conversationId: String, userIds: [String], completion: @escaping (Bool,String?) -> ())
Function Params
Parameter | Type | Required | Description |
---|---|---|---|
conversationId | String | yes | The unique ID of the conversation. |
userIds | [String] | Yes | Specifies an array of user IDs to add to the conversation. E.g. ["20236", "20697", "19116"] |
Request Example
let conversationId = "20bf7003-7d64-11ea-818d-3feba8c6b791"
let userIds = ["20236","20697","19116"]
ChannelizeAPIService.removeMemberFromConversation(conversationId: conversationId, userIds: userIds, completion: {(status,errorString) in
if status {
print("Members removed successfully")
} else {
print("Error in removing members. Error: \(errorSting ?? "")")
}
})
Completion Handler
status
: Bool value indicating the status of the result.errorString
: Optional error string if api call was unsuccessful.
Get Members
Retrieves the list of users who are members of the conversation.
Function
func getConversationsMembers(conversationId: String, completion: @escaping ([CHMember]?,String?) -> ())
Request Example
let conversationId = "20bf7003-7d64-11ea-818d-3feba8c6b791"
ChannelizeAPIService.getConversationsMembers(conversationId: conversationId, completion: {(members,errorString) in
guard errorString == nil else {
print("Error in getting members. Error: \(errorString ?? "")")
return
}
if let recievedMembers = mebers {
// Implement your logic.
}
})
Completion Handler
members
:[CHMember]
members array of conversation..errorString
: Optional error string if api call was unsuccessful.