Create Channel/Group

Create a Channel/Group by calling createChannel method. The callback argument ALChannel will have Channel information created by applozic server. In case you are not passing clientChannelKey, you need to store channelKey from ALChannel object for any further operations (like add member, remove member, delete group/channel etc) on Channel/Group.

Class to import : Applozic/ALChannelService.h

ALChannelService *channelService = [[ALChannelService alloc] init];

        NSMutableArray *memberArray = [[NSMutableArray alloc] init];
        [memberArray addObject:@"user1"];//pass userId of user whom you want to add in channel

        [channelService createChannel:channelName orClientChannelKey:nil andMembersList:memberArray andImageLink:imageLink channelType:PUBLIC andMetaData:nil adminUser:nil withCompletion:^(ALChannel *alChannel, NSError *error) {

            if(!error){
                NSLog(@"Group created successfully");
              // alChannel.key you can get the key of the channel
            }

        }];
let alChannelService = ALChannelService();
        let membersList = NSMutableArray()
        membersList.add("user1")//pass userId of user whom you want to add in channel

        alChannelService .createChannel(channelName, orClientChannelKey: nil, andMembersList: membersList, andImageLink: nil, channelType: Int16(PUBLIC.rawValue), andMetaData: nil, adminUser: nil) { (alChannel, error) in
            
            if((error == nil)){
                print("Channel successfully created")
            }
            
        }

Parameter

Required

Default

Description

channelName

Yes

Channel name or Group Name

clientChannelKey

NO

nil

Client channel key maintain by client. This can be any unique identifier passed by client, to identify his group/channel

memberArray

Yes

Array of group member's userId

imageLink

Yes

Group profile image link

type

PUBLIC = 2

Type of the group. Learn more about available Group types here.

metaData

Optional

Setting group meta data for messages like created group, left group, removed from group, group deleted, group icon changed and group name changed.

(void(^)(ALChannel *alChannel))completion

Completion block, once group is created successfully. This will return ALChannel object, which stores information about newly created channel.

adminUser

Optional

nil

You can pass the admin of the group while creating

📘

NOTE: Group metadata is optional and should be passed for custom group notification message only. Example method is below, how you can get custom message:

📘

Currently, 100 users can be added to a Public and Private group. This number can be increased on request.

Update Group Action Messages

There are 3 ways to customize action messages in Group/Channel:

  1. You can change the action message text as your custom message, You can set group metadata for messages like the created group, left the group, removed from the group, group deleted, group icon changed and group name changed
-(NSMutableDictionary *)getChannelMetaData
{
    NSMutableDictionary *grpMetaData = [NSMutableDictionary new];

    [grpMetaData setObject:@":adminName created group" forKey:@"CREATE_GROUP_MESSAGE"];
    [grpMetaData setObject:@":userName removed" forKey:@"REMOVE_MEMBER_MESSAGE"];
    [grpMetaData setObject:@":userName added" forKey:@"ADD_MEMBER_MESSAGE"];
    [grpMetaData setObject:@":userName joined" forKey:@"JOIN_MEMBER_MESSAGE"];
    [grpMetaData setObject:@"Group renamed to :groupName" forKey:@"GROUP_NAME_CHANGE_MESSAGE"];
    [grpMetaData setObject:@":groupName icon changed" forKey:@"GROUP_ICON_CHANGE_MESSAGE"];
    [grpMetaData setObject:@":userName left" forKey:@"GROUP_LEFT_MESSAGE"];
    [grpMetaData setObject:@":groupName deleted" forKey:@"DELETED_GROUP_MESSAGE"];

    return grpMetaData;
}
func getChannelMetaData() -> NSMutableDictionary
{
    let grpMetaData: NSMutableDictionary = NSMutableDictionary()

    grpMetaData["CREATE_GROUP_MESSAGE"] = ":adminName created group"
    grpMetaData["REMOVE_MEMBER_MESSAGE"] = ":userName removed"
    grpMetaData["ADD_MEMBER_MESSAGE"] = ":userName added"
    grpMetaData["JOIN_MEMBER_MESSAGE"] = ":userName joined"
    grpMetaData["GROUP_NAME_CHANGE_MESSAGE"] = "Group renamed to :groupName"
    grpMetaData["GROUP_ICON_CHANGE_MESSAGE"] = ":groupName icon changed"
    grpMetaData["GROUP_LEFT_MESSAGE"] = ":userName left"
    grpMetaData["DELETED_GROUP_MESSAGE"] = ":groupName deleted"

    return grpMetaData
}
  1. To hide the group action messages from the chat screen and to turn off the notifications get the metadata as shown below and pass it while creating a group or in group update
ALChannelService *channelService = [[ALChannelService alloc] init];
NSDictionary *metadataDict = [channelService metadataToHideActionMessagesAndTurnOffNotifications];
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:metadataDict];
let channelService = ALChannelService()
let metadataDict = channelService.metadataToHideActionMessagesAndTurnOffNotifications()
let metadata = NSDictionary(dictionary: metadataDict)
  1. To turn off the notification for group action messages get metadata as shown below and pass this while creating a group or in group update.
ALChannelService *channelService = [[ALChannelService alloc] init];
NSDictionary *metadataDict = [channelService metadataToTurnOffActionMessagesNotifications];
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:metadataDict];
let channelService = ALChannelService()
let metadataDict = channelService.metadataToTurnOffActionMessagesNotifications()
let metadata = NSDictionary(dictionary: metadataDict)
  1. To disable the particular group action message you need to pass the empty string as given in the following example.

Example: Disabling group member remove message

To disable the message you need to pass the empty string as shown below:

[grpMetaData setObject:@"" forKey:@"REMOVE_MEMBER_MESSAGE"];
grpMetaData["REMOVE_MEMBER_MESSAGE"] = ""

Add User to Channel/Group

ALChannelService *channelService = [[ALChannelService alloc] init];

   [channelService addMemberToChannel:userId andChannelKey:channelKey orClientChannelKey:nil withCompletion:^(NSError *error, ALAPIResponse *response)  {
        if(!error && [response.status isEqualToString:@"success"]){

            }
        }];
let alChannelService = ALChannelService();
    
        alChannelService.addMember(toChannel: userId, andChannelKey: channelKey, orClientChannelKey: nil) { (error, aLAPIResponse) in
        
          if(error == nil && aLAPIResponse != nil && aLAPIResponse?.status == "success" )
            {
                print("Added member successfully in channel")
            }
        }

Parameter

Required

Description

userId

Yes

Member's userId to be added to group

channelKey

No

Applozic channelKey. If clientChannelKey is passed, this should be passed as nil.

clientChannelKey

No

Client channel identifier. This is mandatory if applozic channelKey is not passed.

(void(^)(NSError error,ALAPIResponse response))completion

Yes

Completion block. If member added successfully, response object's status will have value as success.

📘

NOTE: For Private group only admin can add member to the group/channel and For public group any one can add a member into a group.

Remove user from Channel/Group

ALChannelService *channelService = [[ALChannelService alloc] init];

  [channelService removeMemberFromChannel:userId andChannelKey:channelKey orClientChannelKey:nil withCompletion:^(NSError *error, ALAPIResponse *response) {

        if(!error && [response.status isEqualToString:@"success"]){

                NSLog(@"User removed from channel/group")
            }
        }];
alChannelService.removeMember(fromChannel: userId, andChannelKey: channelKey, orClientChannelKey: nil) { (error, aLAPIResponse) in
            
            if(error == nil && aLAPIResponse != nil && aLAPIResponse?.status == "success" ){
                
                print(" Member removed successfully from channel")

            }
            
        }

Parameter

Required

Description

userId

Yes

Member's userId to be removed from group

channelKey

No

Applozic channelKey. If clientChannelKey is passed, this should be passed as nil.

clientChannelKey

No

Client channel identifier. This is mandatory if applozic channelKey is not passed.

(void(^)(NSError error, ALAPIResponse response))completion

Yes

Completion block.

📘

NOTE: Only admin can remove a member from group

Leave Channel/Group

ALChannelService *channelService = [[ALChannelService alloc] init];
    
    [channelService leaveChannel:channelKey andUserId:[ALUserDefaultsHandler getUserId] orClientChannelKey:nil withCompletion:^(NSError *error) {
        if(error == nil){
            NSLog(@"Leave channel success");
        }
    }];
let alChannelService = ALChannelService();

        alChannelService.leaveChannel(channelKey, andUserId: ALUserDefaultsHandler.getUserId(), orClientChannelKey: nil) { (error) in

            if(error == nil){

            }
        }

Parameter

Required

Description

channelKey

No

Applozic channelKey. If clientChannelKey is passed, this should be passed as nil.

clientChannelKey

No

Client channel identifier. This is mandatory if Applozic channelKey is not passed.

(void(^)(NSError *error))completion

Yes

Completion block. In case of success, error object will be nil

Update Channel/Group

ALChannelService *channelService = [[ALChannelService alloc] init];

[channelService updateChannel:channelKey andNewName:channelName andImageURL:nil orClientChannelKey:nil isUpdatingMetaData:NO metadata:nil orChildKeys:nil orChannelUsers:nil withCompletion:^(NSError *error) {
        
    }];
let alChannelService = ALChannelService();

 alChannelService.updateChannel(withChannelKey: channelKey, andNewName:channelName, andImageURL: nil, orClientChannelKey: nil, isUpdatingMetaData: false, metadata: nil, orChildKeys: nil, orChannelUsers: nil) {  (error) in
            
        }

channelKey

Yes

Applozic channelKey. If clientChannelKey is passed, this should be passed as nil.

newName

No

New name of channel.

imageURL

No

New Image of channel. If require to change image of channel/group

clientChannelKey

No

Client channel identifier. This is mandatory if applozic channelKey is not passed.

metaData

No

Pass in case if you want to update channel meta data

isUpdatingMetaData

No

Pass true in case if your updating meta data

childKeysList

No

To update childKeys

channelUsers

No

To update role of user in group/channel like for updating user to admin or moderator

(void(^)(NSError *error))completion

completion block. In case of success, error object will be nil

📘

NOTE: Only admin can change the roles of user, For building channelUsers for role change update

ALChannelService *channelService = [ALChannelService new];
 ALChannelUser * alChannelUsers = [ALChannelUser new];
 alChannelUsers.role = [NSNumber numberWithInt:1];//  USER = 0,ADMIN = 1,MODERATOR = 2,MEMBER = 3
 alChannelUsers.userId = userId;//user to update the role
 NSMutableArray * channelUsers = [NSMutableArray new];
 [channelUsers addObject:alChannelUsers.dictionary];
let channelService = ALChannelService()
 let alChannelUsers = ALChannelUser()
 alChannelUsers.role = 1 //  USER = 0, ADMIN = 1, MODERATOR = 2, MEMBER = 3
 alChannelUsers.userId = userId  //user to update the role
 var channelUsers = NSMutableArray  = [alChannelUsers.dictionary]

Mute/Un-mute Channel/Group (Stop Notifications)

Logged-in user can mute a group. You need to pass time in timestamp in UTC till you need to stop notifications from a particular group.

-(void) sendMuteRequestWithTime:(NSNumber*) time forChannel:(NSNumber*) channelKey{
  
    ALMuteRequest * alMuteRequest = [ALMuteRequest new];
    alMuteRequest.id = channelKey;
    alMuteRequest.notificationAfterTime= time;
    ALChannelService *alChannelService = [[ALChannelService alloc]init];
    [alChannelService muteChannel:alMuteRequest withCompletion:^(ALAPIResponse *response, NSError *error) {
        //Update your UI if any
        
    }];
  
}
  • un-mute

To un-mute pass current time in UTC in above function.

long secsUtc1970 = [[NSNumber numberWithDouble:[[NSDate date]timeIntervalSince1970] ] longValue ]*1000L;
    
[self sendMuteRequestWithTime:[NSNumber numberWithLong:secsUtc1970]];

Categorize groups chat conversation list

This section will guide you on how to create a group within some category where you can show only those group chat conversation based on some category name

You can check channel create from this doc link

Set the Category name in below NSMutableDictionary value, Pass getChannelMetaData in above link for the createChannel method

-(NSMutableDictionary *)getChannelMetaData
{
    NSMutableDictionary *grpMetaData = [NSMutableDictionary new];
    [grpMetaData setObject:@"pass CATEGORY name here " forKey:@"AL_CATEGORY"];

    return grpMetaData;
}
func getChannelMetaData() -> NSMutableDictionary{

        let metaData = NSMutableDictionary()
        metaData["AL_CATEGORY"] = "pass  CATEGORY name here "
        return metaData
    }

You also need to pass the Category name while launching a chat conversations list

Pass the Category name in below settings

[ALApplozicSettings setCategoryName:@"Pass Category Name here "];
ALApplozicSettings.setCategoryName("pass Category name here ")

Example how to use the settings while launching a chat list screen you can set the Category name and launch the chat screen

[ALApplozicSettings setCategoryName:@"Pass Category Name here "];

[chatManager launchChat:self];
ALApplozicSettings.setCategoryName("pass Category name here ")

chatManager.launchChat(self)

Context based chat in a group of two

This guides you on how to create and launch the context based chat using a group of two here. It will create a different thread conversation for a different topic with the same user.

NSMutableDictionary *groupMetaData = [NSMutableDictionary new];

    [groupMetaData setObject:@"<YOUR-TITLE-HERE>" forKey:@"title"];
    [groupMetaData setObject:@"<PRICE-OF-ITEM>" forKey:@"price"];
    [groupMetaData setObject:@"<YOUR-IMAGE-URL-OF-ITEM>" forKey:@"link"];
    [groupMetaData setObject:@"true" forKey:@"AL_CONTEXT_BASED_CHAT"];

    ALChatManager * chatManager = [[ALChatManager alloc] init];

    [chatManager launchGroupOfTwoWithClientId:@"<RECIVER-USERID>" withItemId:@"<YOUR-ITEM-ID>" withMetaData:groupMetaData andWithUser:@"<RECIVER-USERID>" andFromViewController:self];
let metadata  = NSMutableDictionary()
  metadata.setValue(<YOUR-TITLE-HERE>, forKey: "title")
  metadata.setValue(<PRICE-OF-ITEM>, forKey: "price")
  metadata.setValue(<YOUR-IMAGE-URL-OF-ITEM>, forKey: "link")
  metadata.setValue("true", forKey: "AL_CONTEXT_BASED_CHAT")

func createGroupOfTwoAndLaunchChat(receiverUserId : String, itemId : String, metadata : NSMutableDictionary) {

        if (ALUserDefaultsHandler.isLoggedIn()) {

            var usersSorted : [String] = [ALUserDefaultsHandler.getUserId(),receiverUserId]
            usersSorted = usersSorted.sorted{$0.caseInsensitiveCompare($1) == .orderedAscending}

            let clientGroupId = itemId+"_"+usersSorted[0]+"_"+usersSorted[1]
            let channelService = ALChannelService()
            let chatManager = ALChatManager()
            let pushAssist = ALPushAssist()
            channelService.getChannelInformation(nil, orClientChannelKey: "clientGroupId") { (alChannel) in
                if (alChannel != nil) {
                    chatManager.launchChatForGroup(alChannel!.key, fromController: pushAssist.topViewController)
                } else {

                    let alChannelService = ALChannelService();
                    let membersList = NSMutableArray()
                    membersList.add(receiverUserId)

                    alChannelService .createChannel(clientGroupId, orClientChannelKey: clientGroupId, andMembersList: membersList, andImageLink: nil, channelType: Int16(GROUP_OF_TWO.rawValue), andMetaData: metadata, adminUser: nil) { (alChannel, error) in

                        if(alChannel != nil){
                            chatManager.launchChatForGroup(alChannel!.key, fromController: pushAssist.topViewController)
                            print("Channel successfully created")
                        } else {
                            print("Failed to launch context chat ")
                        }
                    }
                }
            }
        }
    }

Argument

Type

Description

groupMetaData

NSMutableDictionary

In group meta data you need to pass your title, price, link

itemId

NSString

In itemId you need to pass your

RECIVER-USERID

NSString

Pass userId of receiver here

Default Group Type

You can set the group type, which will be used when a group is created through the "Create Group" button.

[ALApplozicSettings setDefaultGroupType: PRIVATE];
ALApplozicSettings.setDefaultGroupType(type: PRIVATE)

Three options are available:

PRIVATE
PUBLIC
OPEN


Did this page help you?