Skip to content

API Integration

rohitphogat19 edited this page Apr 24, 2019 · 2 revisions

id: iosSDK-Overview title: Api SDK - Overview sidebar_label: Overview

The following documentation is built to help you with installing our iOS SDKs into your project.

The Channelize SDK can be installed using the following method

Firstly, you will need to register on Channelize: https://channelize.io/pricing

After the successful payment at https://channelize.io/pricing you'll get the API URLs and Keys to run Channelize into your app.


id: iosSDK-Dependencies title: Api SDK - Dependencies sidebar_label: Dependencies

Dependencies

Requirements Before we begin, please do make sure that

  1. Your application is built on iOS 9.0 or above.
  2. Since Channelize SDK as of now only supports Version 9.0 or higher.
  3. You have Xcode 9.4.1 or later as your IDE to install and run Channelize SDK on iOS.
  4. Swift 4 / 4.1 / 4.2

id: iosSDK-Files and Pods title: Api SDK - Files and Pods sidebar_label: Files and Pods

Pod Installation

If you've never used CocoaPods for a Xcode project, open a terminal window, move to your project directory, and then create a Podfile by running the following command.

pod init

Add the following lines to the Podfile.

platform :ios, '9.0'

target 'YourProject' do
  use_frameworks!
  pod 'ChannelizeAPI'
end

And then install the Channelize API framework through CocoaPods.

pod install

If you are already using CocoaPods then add the following pod

pod 'ChannelizeAPI'

Required Files

You need create an .plist file with name as "Channelize-Info.plist" and place following keys

<key>PUBLIC_KEY</key>
<string>xxxx PublicKey xxxx</string>
<key>API_URL</key>
<string>xxxx API URL xxxxx </string>
<key>MQTT_URL</key>
<string>xxxxxxx MQTT URL xxxxxx</string>

App Permission

Make sure following app permissions are in your app info.plist file

<key>NSAppTransportSecurity</key>
  <dict>
  	<key>NSAllowsArbitraryLoads</key>
  	<true/>
  </dict>

Using SDK Method and Properties

**Note: Where ever you want to use Channelize, please import following

import Channelize_API

id: iosSDK-Configuration title: Api SDK - Configuration sidebar_label: Configuration

Configuring and Connecting to Channelize

Configuring Channelize

To configure Channelize you need to add the following code in didFinishLaunchingWithOptions function of your project's AppDelegate.swift file

Channelize.configure()

Login to Channelize Server

You need to Login into Channelize server before using APIs. To login add following code in your app(most preferred on login button action in your app)

Channelize.main.login(username: email, password: password){(user,error) in 
   guard error == nil else {
       return }
  //Use User details here

Connecting User to Channelize Server

Connect user to get various event delegate calls(Please connect only logged users)

Channelize.connect()

Disconnecting User from Channelize Server

Disconnect a user from Channelize server to stop receiving further notifications, messages and event notifications

Channelize.disconnect()

Logout From Channelize Server

To logout from Channelize server, please add following code, where you want user to logout

Channelize.main.logout()

Push Notification Settings

To receive Push Notification in your app, you have to register a token to Channelize server. Configure firebase in your app and register the token

Registering FCM Token

To register fcm token, call following API Code.You can also update the token through this API Call

Channelize.updateToken(token: TOKEN_STRING)

Deleting FCM Token

To delete a token w.r.t a user, make following API Call

Channelize.deleteToken()

id: iosSDK-Conversations title: Api SDK - Conversations sidebar_label: Conversations

APIs for Conversations

Getting Number of Recent Chat Count

To get count of Recent Chats with filtering make below API call with filtering object

let convCountQueryBuilder = QueryBuilder().createConversationCountFilters()
// True if you want to include deleted Conversation, False if you do not want
convCountQueryBuilder.includeDeleted = true 
// True for group only, false for one to one conversation only. remove this for both types of conversation.
convCountQueryBuilder.isGroup = true 
// True, if include deleted conversation, false for excluding.
convCountQueryBuilder.includeDeleted = false 
// True, for active conversations(Logged-in user is active member of the conversation) only, false for excluding inactive conversations.
convCountQueryBuilder.includeOnlyActive = false 

CHService.main.getRecentChatCount(queryFilter: convCountQueryBuilder, completion: {(count,error) in
    guard error == nil else{
        return debugPrint(error.debugDescription)
    }
    // DO_YOUR_STUFF_HERE
})

Get Conversation List

To get Conversation List, Make following API Call

let convQueryBuilder = QueryBuilder().createConversationFilters()
//When you want to fetch the conversation between logged-in user and user whose id has been passed in this method.
convQueryBuilder.memberId = "USER_ID" 
// True if you want to include deleted Conversation, False if you do not want
convQueryBuilder.includeDeleted = true 
// True for group only, false for one to one conversation only. remove this for both types of conversation.
convQueryBuilder.isGroup = true 
// True, if include deleted conversation, false for excluding.
convQueryBuilder.includeDeleted = false 
// True, for active conversations(Logged-in user is active member of the conversation) only, false for excluding inactive conversations.
convCountQueryBuilder.includeOnlyActive = false 
// Sorting order Possible Values .DESC or .ASC
convQueryBuilder.sorting = .DESC 
// Data which you want to include in conversation list response.
convQueryBuilder.inclued = "membersList" 
convQueryBuilder.isGroup = true
 // Limit of result in one API Call
convQueryBuilder.limit = 30
// Next Call Index like 0,30,60
convQueryBuilder.offset = 0 

CHService.main.getChats(queryFilter: convQueryBuilder, completion: {(conversations,error) in
    guard error == nil else{
        return debugPrint(error.debugDescription)
    }
    // DO_YOUR_STUFF_HERE
})

Get Conversation With a particular user

  • To get conversation with a particular User, make following API request
CHService.main.getChat(with: USER_ID, completion: {(conversation,error) in
    if let error = error {
        return print(error.localizedDescription)
    }
    // Do your stuff here
})

Get Conversation With a chat id

  • To get conversation with a particular User, make following API request
CHService.main.getChat(of: CHAT_ID, completion: {(conversation,error) in
    if let error = error {
        return print(error.localizedDescription)
    }
    // Do your stuff here
})

Deleting a Conversation

conversation.delete(completion: {(status,error) in 
    if let error = error{
       return print(error.localizedDescription)
    }
    // DO_YOUR_STUFF_HERE
})

Clearing a Conversation

conversation.clear(completion: {(status,error) in
                        
})

Set typing Status

conversation.publishUserTypingStatus(isTyping: Bool)

Mark all Message Read of A Conversation

conversation.markAllMessagesAsRead()

Get Message Count of a Conversation

/* Params Required :- 
1.CHAT_ID(String,Required)
2.QUERY_FILTER_OBJECT(QueryBuilder.ConversationMessageCountFilters,required)*/

let messageCountQuery = QueryBuilder().createConversationMessageCountFilert()
// [Optional] Attachment type Possible Values :- text,audio,image,video,location,gif,stickers
messageCountQuery.attachmentType = "text,audio,image,video"
// [Optional] If you want to filter the message according to the owner of the messages
messageCountQuery.ownerId = "owner_Id"
// [Optional] If you want to fetch the result according to the content type only. Values :- 0,1,2,3
messageCountQuery.contentType = "1"

CHService.main.getMessageCount(queryFilter: messageCountQuery, chatId: CHAT_ID, completion: {[weak self]
    (count,error) in
    // DO_YOUR_STUFF_HERE 
})

Get Messages of a Conversation

/* Params Required :- 
1.CHAT_ID(String,Required)
2.QUERY_FILTER_OBJECT(QueryBuilder.ConversationMessageFilters,required)*/

let messageQuery = QueryBuilder().createConversationMessageFilter()
// [Optional] Attachment type Possible Values :- text,audio,image,video,location,gif,stickers
messageQuery.attachmentType = "text,audio,image,video"
// [Optional] If you want to filter the message according to the owner of the messages
messageQuery.ownerId = "owner_Id"
// [Optional] If you want to fetch the result according to the content type only. Values :- 0,1,2,3
messageQuery.contentType = "1"
messageQuery.limit = 30
// [Optional]Starting index for next call e.g. 0,30,60..
messageQuery.skip = 0 
// [Optional] Sorting Order Possible Values :- .DESC,.ASC
messageQuery.sort = .DESC

CHService.main.getMessages(queryFilter: messageQuery, chatId: CHAT_ID, completion: {[weak self]
    (count,error) in
    // DO_YOUR_STUFF_HERE 
})

Get Unread Message Count

CHService.main.getUnreadMessageCount(completion :{(count,error) in 

}

id: iosSDK-Groups title: Api SDK - Groups sidebar_label: Groups

Groups APIs

Creating a New Group

To create a new Group,make following API Call

/*Parameters Required
1. title -> (String,Required) Title of the Group
2. membersIds -> ([String],Required) A String array containing groups member Ids
3. imageData -> (Data,Optional) Group Profile Image Data
*/
CHService.main.createGroup(title: title, memberIds: [members_ids], imageData: uploadData, completion: {(conversation,error) in
    guard error == nil else {
        return }
    // DO_YOUR_STUFF_HERE
})

Adding Members to a group Conversation

Call following api with Group Conversation Object to add Members to a group

/*
Parameters Required
1. userIds : ([String],Required) A string Array containing User Ids of members to be added
*/
conversation.addMembers(userIds: [USER_IDS_OF_MEMBER], completion: {(status,error) in
    if(status){
        // Members Added
    }else{
        // Operation Failed
    }
})

Removing Members from A Group Conversation

/*
Parameters Required
1. userIds : ([String],Required) A string Array containing User Ids of members to be added
*/
conversation.removeMembers(userIds: [Members_Ids], completion: {(status,error) in
    if(status){
        // Member Removed
    }else{
        // Operation Failed
    }
})

Leaving A Conversation group

conversation.leave(completion: {(status,error) in
    guard error == nil else {
        return
    }  
})

Making A Member admin of a group Conversation

conversation.makeAdmin(userIds: "USER_ID_OF_MEMBER", completion: {(status,error) in
    if(status){
        // Operation Successful
    }else{
        // Operation Failed
    }
})

Updating a group Title

conversation.changeTitle(title: "TITLE", completion: {(chat,error) in
    guard error == nil else {
        return print(error?.localizedDescription)
    }
    // DO_YOUR_STUFF_HERE
})

id: iosSDK-Users title: Api SDK - Users sidebar_label: Users

Users Api Calls


id: androidSDK-Overview title: Api SDK - Overview sidebar_label: Overview

Getting Friends Count

/*
Parameters Required:
1. QUERY_FILTER_OBJECT :- (QueryBuilder.GetFriendsCountFilters,Required)
*/
let friendsCountQuery = QueryBuilder().createFriendsCountFilter()
friendsCountQuery.isOnline = true // If you want to fetch only those users details which are online.
friendsCountQuery.searchQuery = "QUERY" // If you want to search users in which user name contains the searched query.
friendsCountQuery.includeBlocked = true // If you want to include the blocked users in user details.
CHService.main.getFriendsCounts(queryFilter: friendsCountQuery, completion: {(count,error) in
    // DO_YOUR_STUFF_HERE
})

Getting All Users

/*
Parameters Required:
1. QUERY_FILTER_OBJECT :- (QueryBuilder.GetUserFilters,Required)
*/
let userQuery = QueryBuilder().createUserFilter()
// To include only online Users
userQuery.isOnline = true
// Serach Users query
userQuery.searchQuery = "query"
// Sorting Order .DESC or .ASC
userQuery.sort = .DESC
userQuery.limit = 30
userQuery.skip = 0
CHService.main.getUsers(queryFilter: userQuery, completion: {(users,error) in
    // DO_YOUR_STUFF_HERE
})

Getting All Friends List

/*
Parameters Required:
1. QUERY_FILTER_OBJECT :- (QueryBuilder.GetFriendsFilters,Required)
*/
let friendsQuery = QueryBuilder().createFriendsFilter()
friendsQuery.online = true
friendsQuery.searchQuery = "Query"
friendsQuery.includeBlocked = false
friendsQuery.sort = .DESC
friendsQuery.limit = 30
friendsQuery.skip = 0
friendsQuery.skipUserIds = ["67","68","69"]
CHService.main.getFriends(queryFilter: friendsQuery, completion: {(friends,error) in
    // DO_YOUR_STUFF_HERE
})

Getting Blocked User Count

/*
Parameters Required:
1. QUERY_FILTER_OBJECT :- (QueryBuilder.GetBlockedUserCountFilters,Required)
*/
let blockUserCountFilter = QueryBuilder().createBlockedUserCountFilter()
blockUserCountFilter.online = true
blockUserCountFilter.search = "Query"
CHService.main.getBlockedUsersCount(queryFilter: blockUserCountFilter, completion: {(count,error) in
// DO_YOUR_STUFF_HERE
})

Getting Blocked User

/*
Parameters Required:
1. QUERY_FILTER_OBJECT :- (QueryBuilder.GetBlockedUserFilters,Required)
*/
let blockUserFilter = QueryBuilder().createBlockedUserFilter()
// [Optional]
blockUserFilter.isOnline = true
// [Optional] Search Query
blockUserFilter.search = "Query"
// [Optional] Sorting order
blockUserFilter.sort = .DESC
// [Optional]
blockUserFilter.limit = 30
//  [Optional]
blockUserFilter.skip = 0

CHService.main.getBlockedUsers(queryFilter: blockUserFilter, completion: {(users,error) in
// DO_YOUR_STUFF_HERE
})

Blocking A User

User’s have the ability to block/unblcok other users, allowing them to have a sense of privacy and security around the kinds of people that they interact with. If User A blocks User B: - User B can not create a conversation with User A & vice versa. - User B can not send messages to User A & vice versa, if a conversation already exists between the two. - Note that these rules do not apply to Group Conversations

/*
Parameters Requires:
1. USER_ID :- (String,Required) User Id of the user to block
*/
CHService.main.blockUser(userId: USER_ID, completion: {(status,error) in
    
})

UnBlocking A User

/*
Parameters Requires:
1. USER_ID :- (String,Required) User Id of the user to block
*/
CHService.main.unblockUser(userId: USER_ID, completion: {(status,error) in
    
})

Retrieve a user using user id

You can also retrieve a user using it's user_id in Channelize application by requesting the following call.

CHService.main.getUser(with: USER_ID) {(user, error) in
   if let error = error {
      return print(error.localizedDescription)
   }    
   //Do your stuff here
}

Setting User Online

Channelize.setUserOnline(completion: {(status,error) in

})

Setting User Offline

Channelize.setUserOffline(completion: {(status,error) in

})

Updating User Settings

// Parameter Required -> UserSettingQueryFilter
let settingsQuery = QueryBuilder().createUserSettingsQuery()
// [Optional] If you want to update the user name
settingsQuery.title = "new Name"
// [Optional] New profile picture url of the user that need to be update.
settingsQuery.profileImage = imageData
// [Optional] True if you want to enable notifications otherwise false.
settingsQuery.enableNotifications = true
 // [Optional] True, if you want to make user visible otherwise false.
settingsQuery.visibility = true

Channelize.updateUserSettings(userSettingQuery: settingsQuery,completion: {(user,error) in 

})

id: iosSDK-Messages title: Api SDK - Messages sidebar_label: Messages

Messages API

Sending Messages

To Send A message make following API call

/* Params
1. MessageType -> .TEXT,.AUDIO,.VIDEO,.LOCATION,.STICKER,.GIF
2. messageParams -> [String:Any] containing keys "id" as unique message id, "ownerId" as current user id, "chatId" as Conversation id, "userId" as recipient id
3. Text -> [Optional] If you sending text message
4. ThumbnailData -> [Optional] PNG data for thumbnail in case of Video and Image Messages
5. fileData -> [Optional] Image,Video or Audio data
6. Conversation -> [Optional] Conversation Object
*/
let params:[String:Any] = [
    "id" : uniqueId,
    "ownerId": ownerId,
    "chatId" : chatId,
    "userId":recipientId
]
CHService.main.sendMessage(messageType:CHMessageType,params:[String:Any],text:String?,thumbnailData:Data?,fileData:Data?,conversation:CHConversation?,completion: {(message,error) in 

)

Forwarding A Message

To forward a Message, make API call

let params:[String:Any] = [
    "messageIds" : messageIds,
    "chatIds"    : selectedChatIds,
    "userIds"    : selectedUserIds]
CHService.main.forwardMessage(params: params, completion: {[weak self] (status) in
    if(status){
    } else {
    }
})
Clone this wiki locally