Group Chat

The Methods below are available for Group chat:

Method Description
createGroup Allows logged-in user to create a group
renameGroup Allows Group Creator or Moderator to rename the group
inviteUser Allows logged-in user to invite other user to the group
joinGroup Allows logged-in user to join a group
getGroupMembers Gets list of the Group Members
getAllGroup Gets list of all the groups accessible to currently opened group chat
sendMessage Allows logged-in user to send a message to currently opened group chat
sendImage Allows logged-in user to send an image to currently opened group chat
sendVideo Allows logged-in user to send a video to currently opened group chat
sendAudioFile Allows logged-in user to send an audio file to currently opened group chat
sendSticker Allows logged-in user to send a sticker to currently opened group chat
sendFile Allows logged-in user to send a file to the group
getGroupHistory Gets the previous messages in currently opened group chat
getCurrentGroup Gets the id of in currently opened group chat
leaveGroup Allows logged-in user to leave currently opened group chat
deleteGroup Allows logged-in user to delete a group if he is creator or moderator of the group

createGroup

Allows logged-in user to create a group Method Signature:

- (void)createGroup:(NSString *)name
               type:(NSInteger)type
           password:(NSString *)password
            success:(void(^)(NSDictionary *response))success
            failure:(void(^)(NSError *error))failure;

Example:

[cometChat createGroup:@"Night's Watch" type:PUBLIC_GROUP password:@"" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
name Name of the group
password Password for password-protected group
type 1 indicates public group and 2 indecates password-protected group
callback Success and failure callback

Response for successCallback:

{
    group_id: 7
}

Description:

Response Property Description
group_id id of the created group

renameGroup

Allows Group Creator or Moderator to rename the group Method Signature:

- (void)renameGroup:(NSString *)groupId
          groupName:(NSString *)groupName
            success:(void(^)(NSDictionary *response))response
            failure:(void(^)(NSError *error))error;

Example:

[cometChat renameGroup:@"5" groupName:@"Starks" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
groupId id of the group to rename
groupname New name for the group
callback success and failure callback

Response for successCallback:

{
    group_id: 5
}

inviteUsers

Allows logged-in user to invite other user to the group Method Signature:

- (void)inviteUser:(NSArray *)usersArray
          groupName:(NSString *)groupName
            groupId:(NSString *)groupId
            success:(void(^)(NSDictionary *))success
            failure:(void(^)(NSError *error))failure;

Example:

NSArray *userArray = [[NSArray alloc] initWithObjects:@"1", @"2", nil];
[cometChat inviteUser:userArray toGroup:@"15" withChatroomID:@"Stark" success:^(NSDictionary *) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
usersArray JSONArray containing id of the users to invite
groupName group name in which user is invited
groupId group id in which user is invited
callback failure callbacks

Response for successCallback:

{ 
        group_id: 15
}

Description:

Response Property Description
group_id id of the deleted group

joinGroup

Allows logged-in user to join a group

- (void)joinGroup:(NSString *)name
          groupID:(NSString *)groupID
         password:(NSString *)password
          success:(void(^)(NSDictionary *response))success
          failure:(void(^)(NSError *error))failure;

Example:

[cometChat joinGroup:@"Starks" groupID:@"5" password:@"" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Agruments:

Argument Description
groupId id of a group to join
name name of the group to join
groupPassword password for password-protected group
callback success and failure callbacks

Response for successCallback:

{
    "group_id": "5",
    "push_channel": "C_c49602157105d9d6383bb30695f771e8"
}

Description:

Response Property Description
group_id id of the joined group
push_channel a unique channel to receive the mobile push notification for the joined group

getAllGroup

Gets list of all the groups accessible to currently opened group chat Method Signature:

- (void)getAllGroups:(void(^)(NSDictionary *groupList))response
                failure:(void(^)(NSError *error))failure;

Example:

[cometChat getAllGroups:^(NSDictionary *groupList) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
callback success and failure callbacks

Response for successCallback:

{
  "_4":{
    "id":"4", "name":"group1", "online":"1", "type":"0", "i":"", "s":0
    },
  "_2":{
    "id":"2", "name":"group2", "online":"0", "type":"0","i":"","s":0
   }
}

Description:

Response Property Description
id id of a group
name name of a group
online number of group participants
type type of a group. 1 indicates public group
i represents password for password protected group
s 1 indicates Owner, 2 indicates Moderator and 0 Indicates logged-in user is neither Owner nor Moderator for the group

leaveGroup

Allows logged-in user to leave currently opened group chat Method Signature:

- (void)leaveGroup:(NSDictionary *)leaveGroupParameter
           success:(void (^)(NSDictionary *))success
           failure:(void(^)(NSError *error))failure;

Example:

NSDictionary *leaveGroupDict = @{@"currentroom": @"10"};
[cometChat leaveGroup:leaveGroupDict success:^(NSDictionary *) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
currentroom id of the group to be left
callback success and failure callbacks

deleteGroup

Allows logged-in user to delete a group if he is creator or moderator of the group Method Signature:

- (void)deleteGroup:(NSString *)groupId
               success:(void(^)(NSDictionary *response))response
               failure:(void(^)(NSError *error))error;

Example:

[cometChat deleteGroup:@"15" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
groupId id of a group to delete
callback success and failure callbacks

Response for successCallback:

{ 
    group_id: 15
}

Description:

Response Property Description
group_id id of the deleted group

sendMessage

Allows logged-in user to send message to other users. Method Signature:

- (void)sendMessage:(NSString *)message
               toId:(NSString *)toId
            localID:(NSString *)localID
            isGroup:(BOOL)isGroup
            success:(void(^)(NSDictionary *response))response
            failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendMessage:@"Hi! How are you?" toId:@"15" localID:@"71" isGroup:YES success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID a parameter which is returned to you with the response to keep track of the status of the message sent
toId recipient’s user id
message text message
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{  
    "id": 71,
    "localmessageid":100,
    "m": "Hi! How are you?"
}

Description:

Response type Description
id id of the message
m The message received from the server

sendImage

Allows logged-in user to send an image using Bitmap or filepath Method Signature:

- (void)sendImageWithData:(NSData *)imageData
                     toId:(NSString *)toId
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendImageWithData:imageData toId:@"15" localID:@"50" isGroup:YES success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
imageData NSData of the image
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{ 
    "id": 23,
    "localmessageid" : 101,
    "original_file": "/Documents/IMG1049.JPG"
}

sendVideo

Allows logged-in user to send a video Method Signature:

- (void)sendVideoWithPath:(NSString *)videoPath
                     toId:(NSString *)toId
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendVideoWithPath:@"/Documents/Video.mp4" toId:@"15" localID:@"50" isGroup:YES success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
videoPath path of the file
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid:102,
    "original_file": "/Documents/Video.mp4"
}

sendAudioFile

Allows logged-in user to send an audio file or recorded audio notes Method Signature:

- (void)sendAudioWithPath:(NSString *)audioPath
                     toID:(NSString *)toID
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendAudioWithPath:@"/Documents/audio1.aac" toId:@"15" localID:@"50" isGroup:YES success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localId A unique value that is returned to you in the response to keep track of the status of the message
audioPath audio file from storage
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid" : 104,
    "original_file": "/Documents/audio1.aac"
}

sendSticker

Allows the user to send a sticker.

Method signature:

- (void)sendStickers:(NSString *)stickerName
                toId:(NSString *)toId
             localID:(NSString *)localID
             isGroup:(BOOL)isGroup
             success:(void(^)(NSDictionary *response))response
             failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendStickers:@"bear_1" toId:@"15" localID:@"501" isGroup:YES success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
stickerName Sticker name
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

sendFile

Allows the logged in user to send a file to a group.

Method Signature:

- (void)sendFile:(NSString *)filePath
                     toId:(NSString *)toId
                  localId:(NSString *)localId
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendFile:@"Path of File To Be Sent" toId:@"15" localID:@"501" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Argument Description
localId A unique value that is returned to you in the response to keep track of the status of the message
filePath file to be sent
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks
  • Was this helpful?
  • Yes   No