Skip to content

Latest API Documentation

rohitphogat19 edited this page May 28, 2019 · 22 revisions

APIs Related to Users

Get Users List

let getUserSearchQuery = QueryBuilder.instance.createUserListFilter()
getUserSearchQuery.searchQuery = query
getUserSearchQuery.limit = defaultLimit
getUserSearchQuery.skip = 0
CHService.main.getUsersList(queryFilter: getUserSearchQuery, completion: {(users,error) in
    // Do your Stuff here
})

Get a User with User Id

CHService.main.getUser(userId:"20456",completion:{(user,error) in
    // Do your Stuff here
})

Block a user

CHService.main.blockUser(userId:"20456",completion:{(status,error) in
    // Do your Stuff here
})

Get Blocked Users List

let blockedUsersQuery = QueryBuilder.instance.createBlockedUsersListFilter()
blockedUsersQuery.limit = 30
blockedUsersQuery.skip = 0
CHService.main.getBlockedUsers(queryFilter:blockedUsersQuery,completion:{(users,error) in
    // Do your stuff here
})

Get Friends list

let friendsFilter = QueryBuilder.createUserFriendsListFilter()
friendsFilter.online = true
friendsFilter.limit = 30
friendsFilter.skip = 0
friendsFilter.includeBlocked = true
friendsFilter.skipUserIds = "20456,20576,20789"
friendsFilter.searchQuery = "Leo"
friendsFilter.sort = .DESC
CHService.main.getFriendsList(queryFilter:friendsFilter,completion:{(users,error) in
    // Do your Stuff Here
})

Get Total Friends Count

let friendsCountFilter = QueryBuilder.instance.createUserFriendsCountFilter()
friendsCountFilter.online = false
friendsCountFilter.includeBlocked = true
friendsCountFilter.searchQuery = "James"
CHService.main.getFriendsCount(queryFilter:friendsCountQueryFilter,completion:{(count,error) in
    // Do your stuff here
})

UnBlock a User

CHService.main.unblockUser(userId:"20456",completion:{(status,error) in
    // Do your stuff here
})

Get Total Users Count

let userCountsFilter = QueryBuilder.createUserFriendsCountFilter()
userCountsFilter.includeBlocked = true
userCountsFilter.online = true
userCountsFilter.searchQuery = "James"
CHService.main.getUserCounts(queryFilter:userCountsFilter,completion:{(count,error) in
    // Do your stuff here
})

Get Blocked Users Total Count

CHService.main.getBlockedUsersCount(queryFilter:friendsCountFilter,completion:{(count,error) in
    // Do your stuff here
})

Get Online Users

let friendsQuery = QueryBuilder.instance.createUserFriendsListFilter()
friendsQuery.online = true
friendsQuery.limit = defaultLimit
friendsQuery.skip = 0
CHService.main.getOnlineUsers(queryFilter: friendsQuery, completion: {(users,error) in
    // Do your stuff here
})
                    

Change a User Visibility

let visibility = false
CHService.main.changeUserVisibility(isVisible: visibility, completion: {(user,error) in
    // Do your stuff here
})

Change Notification Settings

CHService.main.changeNotificationSetting(isNotificationOn: false, completion: {(user,error) in
    // Do your stuff here
})

APIs Related to Messages

Send a Text Message

let textBody = "Hello, How are you?"
var params = [String:Any]()
params.updateValue(UUID().uuidString,forKey:"id")
params.updateValue(Channelize.currentUserId()!,forKey:"ownerId")
if currentConversation != nil{
    params.updateValue(currentConversation.id!,forKey:"chatId")
} else{
    params.updateValue(RECIPIENT_ID,forKey:"userId")
}
CHService.main.sendTextmessage(textMessage:textBody,messageParams:params,conversation:currentConversation,completion:{(message,error) in
    // Do your Stuff here
})

Send File Messages

CHService.main.sendFileMessage(messageParams: params, fileParams: params, thumbnailData: nil, fileData: audioData, messageType: .AUDIO, conversation: self?.chat, completion: {(message,error)
    // Do your Stuff here
})

Send A Quoted Message

// quotedMessage is the message which you want to quote
let messageText = "Hello, this is a quoted message"    
var params = [String:Any]()
params.updateValue(UUID().uuidString,forKey:"id")
params.updateValue(Channelize.currentUserId()!,forKey:"ownerId")
params.updateValue(conversation.id,forKey:"chatId")
     
var quotedParams = [String:Any]()
quotedParams.updateValue(quotedMessage.id,forKey:"id")
quotedParams.updateValue(quotedMessage.attachmentType,forKey:"attachmentType")
quotedParams.updateValue(quotedMessage.ownerId,forKey:"ownerId")
let owner = ["displayName":quotedMessage.userDisplayName,"id":quotedMessage.ownerId]
quotedParams.updateValue(owner,forKey:"owner")
quotedParams.updateValue(quotedMessage.contentType,forKey:"contentType")
switch quotedMessage.attachmentType{
     case "text":
        quotedParams.updateValue(quotedMessage.body!, forKey: "body")
     case "image","video","audio":
        let attachment = ["fileUrl":quotedMessage.file?.fileUrl]
        quotedParams.updateValue(attachment, forKey: "attachment")
     case "sticker","gif":
        quotedParams.updateValue(quotedMessage.previewUrl!, forKey: "downsampledUrl")
     case "location":
        let data = ["latitude":quotedMessage.messageData?.latitude,"longitude":modelMessage.messageData?.longitude]
        quotedParams.updateValue(data, forKey: "data")
     }
CHService.main.sendQuotedMessage(messageParams:params,messageText:messageText,quotedMessageId:quotedMessage.id,quotedMessageParams:quotedParams,conversation:conversation,completion:{(message,error) in
     })

Send A Location Message

var params = [String:Any]()
params.updateValue(UUID().uuidString,forKey:"id")
params.updateValue(Channelize.currentUserId()!,forKey:"ownerId")
params.updateValue(conversation.id,forKey:"chatId")
     
var locationParams = [String:Any]()
locationParams.updateValue(53.2734,forKey:"latitude")
locationParams.updateValue(7.778,forKey:"longitude")
locationParams.updateValue("Madison Square Garden",forKey:"title")
locationParams.updateValue("4 Pennsylvania Plaza, New York, NY 10001, USA",forKey:"address")
  CHService.main.sendLocationMessage(messageParams:params,locationParams:locationParams,conversation:conversation,completion: {(message,error) in
    // Do your Stuff here 
})

Send GIFs and Stickers Messages

var params = [String:Any]()
params.updateValue(UUID().uuidString,forKey:"id")
params.updateValue(Channelize.currentUserId()!,forKey:"ownerId")
params.updateValue(conversation.id,forKey:"chatId")
     
var gifStickParams = [String:Any]()
gifStickParams.updateValue("https://media1.giphy.com/media/Zantw7qPmMaZZJBrzc/200.gif",forKey:"originalUrl")
gifStickParams.updateValue("https://media1.giphy.com/media/Zantw7qPmMaZZJBrzc/200_s.gif",forKey:"stillUrl")
gifStickParams.updateValue("https://media1.giphy.com/media/Zantw7qPmMaZZJBrzc/200_d.gif",forKey:"downsampledUrl")
     
CHService.main.sendGIFStickerMessage(messageParams: params, gifStickerParams: gifStickParams,messageType: .GIF conversation: conversation, completion: {(message,error) in
    // Do your Stuff here     
})

Get Total Messages Count of a conversation

let messageCountQuery = QueryBuilder.createConversationMessageCountFilter()
messageCountQuery.attachmentType = "image,video,text,location,gif,sticker,audio"
messageCountQuery.contentType = 0 // Possible Values 0,1,2,3
messageCountQuery.ownerId = 20456
CHService.main.addGroupAdmin(chatId:"2004589",userId:"55",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Get Messages of a Conversation

let getMessageQuery = QueryBuilder.instance.createConversationMessageFilter()
getMessageQuery.limit = 30
getMessageQuery.skip = 0
getMessageQuery.attachmentType = "image,audio,video"
getMessageQuery.contentType = 0
getMessageQuery.sort = .DESC
CHService.main.getMessages(queryFilter: getMessageQuery, chatId: self.chatId!, completion: {(messages,error) in
    guard error == nil else {
        print("Error in Getting Messages")
        return
    }
    "Do your stuff with Messages"
})

Delete Messages

let messageIds = ["d37175a3-1926-45f9-a302-3b5b238850ff","d37175a3-1926-45f9-a302-3b5b23885012"]
CHService.main.deleteMessages(messageIds: messageIds, completion: {(status,error) in
    if status{
        print("Messages Deleted")
    } else{
        print("Failed")
    }
})

Forward A Message

let userIds = ["20465","20573","20984"]
let groupIds = ["30465","30573","30984"]
let messageIds = ["d37175a3-1926-45f9-a302-3b5b238850ff","d37175a3-7890-45f9-a302-3b5b23885192"]
CHService.main.forwardMessages(userIds: userIds, groupIds: groupIds, messagesIds: messageIds, completion: {(status,error) in
    if status{
        print("Message Forwared")
    } else{
        print("Failed")
    }
})

Get Total Unread Messages Count

CHService.main.getUnreadMessageCounts(completion: {(count,error) in
    guard error == nil else{
    print("Error")
        return
    }
})

Mark a Message Read

let id = "d37175a3-1926-45f9-a302-3b5b238850ff"
CHService.main.markMessageAsRead(messageId:id,completion: {(status,error) in
    if status{
        print("Message Forwared")
    } else{
        print("Failed")
    }
})

APIs Related to Conversation

Get Recent Chat Count

Get Conversations

let conversationQuery = QueryBuilder.instance.createConversationListFilter()
conversationQuery.inclued = "membersList"
conversationQuery.limit = defaultLimit
conversationQuery.offset = offset
CHService.main.getChats(queryFilter: conversationQuery, completion: {(conversations,error) in
    // Do your Stuff Here
})

Add a Admin to the Group

CHService.main.addGroupAdmin(chatId:"2004589",userId:"55",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Remove a Member from Group

CHService.main.removeGroupMember(chatId:"2004589",userId:"55",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Leave A Group Conversation

CHService.main.leaveConversation(chatId:"2004589",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Clear a Conversation

CHService.main.clearConversation(chatId:"2004589",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Delete a Conversation

CHService.main.deleteConversation(chatId:"2004589",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
    "Operation Failed"
    }
})

Add Members to the Group Conversation

let chatId = "2004859"
 let usersIds = ["20456","20152"]
 CHService.main.addMembersToConversation(chatId:chatId,userIds:usersIds,completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Mark all Message as Read Of a Conversation

CHService.main.markAllMessageAsRead(chatId:"2004589",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Get Members of a Conversation

CHService.main.getConversationMembers(chatId:"2004589",completion:{(users,error) in
    guard error == nil else {
        print("Error occured")
        return
    }
    "Do your Stuff with Users List"
})

Update Title of the Group

CHService.main.updateConversationTitle(title:"New Title",chatId:"205578344",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Mute or UnMute a Conversation

To mute or unmute a conversation call muteUnmuteConversation function of CHService class. Parameters needed are chatId as id of the respective conversation, isMuted as Bool value. Completion handler will give you status as true or false and an option error

///
/// - parameter chatId: Conversation or Group Id
/// - parameter isMuted: True or False. True => Mute Conversation False => Unmute Conversation
/// - parameter completion: The closure called when the API response comes. Closure will have Bool reponse and a Optional Error
/// ## Usage:
CHService.main.muteUnmuteConversation(chatId:"2004589",userId:"55",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Get Conversation Object with a Conversation Id

Get a conversation Object with a conversation Id. Parameters needed are chatId as id of the Conversation

///
/// - parameter chatId: Conversation or Group Id
/// - parameter completion: The closure called when the API response comes. Closure will have CHConversation Object and a Optional Error
/// ## Usage:
CHService.main.getConversationWithId(chatId:"20456",completion:{(conversation,error) in
    guard error == nil else{
        print("Error in Getting Conversation")
        return
    }
    "Do your Stuff Here with Conversation object"
})

Get A conversation With A user Id.

Get a conversation Object related to a user. Parameters needed are recipientId as id of the User. Important use when you are creating a one-to-one chat with a new user.

///
/// - parameter recipientId: User Id
/// - parameter completion: The closure called when the API response comes. Closure will have CHConversation Object and a Optional Error
///
/// ## Usage:
CHService.main.getConversationWithRecipientId(recipientId:"20456",completion:{(status,error) in
    guard error == nil else{
        print("Error in Getting Conversation")
        return
    }
    "Do your Stuff Here with Conversation object"
})

Update a Group Profile Photo

To update a group Profile Photo call updateGroupProfilePhoto function of CHService class. Parameters needed are profileImageData and groupId as Group Conversation id.

///
/// - parameter profileImageData: Conversation or Group Id
/// - parameter groupId: Group Id
/// - parameter completion: The closure called when the API response comes. Closure will have Bool reponse and a Optional Error
/// ## Usage:
CHService.main.updateGroupProfilePhoto(profileImageData:imageData,groupId:"20000545938",completion:{(status,error) in
    if status{
        "Do your Stuff Here"
    } else {
        "Operation Failed"
    }
})

Create a New Group Conversation

To create a new Group Conversation call CHService class createGroup function. Parameters needed to create a group are groupTitle,profileImageData if want to create group with a profile photo, memberIds as a String Array containing members ids. Completion handler will provide a CHConversation object if group created successfully, else it will return error.

///
/// - parameter groupTitle: New Group Title
/// - parameter profileImageData: Group Profile Image Data [Optional]
/// - parameter memberIds: A string Array object containing User ids of Group
/// - parameter completion: The closure called when the API response comes. Closure will have CHConversation Object and a Optional Error
/// ## Usage:

CHService.main.createGroup(groupTitle:"New Group 51",profileImageData:imageData,memberIds:["20456","20657"],completion:{(conversation,error) in
    guard error == nil else {
        print("Error in Creating New Group")
        return
    }
    "Do you stuff with conversation Object"
})