One On One Chat

The Methods below are available for One-on-one chat:

Method Description
setStatus Sets a status for logged-in user
setStatusMessage Sets a status message for logged-in user
getUserInfo Allows logged-in user to pull details of other user
getOnlineUsers Gets list of online users from the server
sendMessage Allows logged-in user to send a message to other user
sendImage Allows logged-in user to send an image to other user
sendVideo Allows logged-in user to send a video to other user
sendAudioFile Allows logged-in user to send an audio to other user
sendSticker Allows logged-in user to send a sticker to currently opened group chat
sendFile Allows logged-in user to send a file
getChatHistory Gets chat history with another user
broadcastMessage Allows logged-in Send a text message to more than one user
isTyping Sends the typing notification to other users. This feature works only with CometService
sendDeliverdReceipt Sends the message delivery receipt to the sender of the message
sendReadReceipt Sends the message read receipt to the sender of the message
getAllAnnouncements Pulls the announcements from server
blockUser Blocks a user
getBlockedUserList Gets the list of blocked users
unblockUser Unblocks a user
setTranslateLanguage Set the language for real time translation
getPluginInfo Gets the details of the enabled plugins
isUserLoggedIn Return true for when user is logged-in

setStatus

CometChat allows you to set the status for your profile. You can set any one of the “Available”, “Busy”, “Invisible”, “Offline” status. Method Signature:

public virtual void SetStatus(
                             nint statusOption,
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.setStatus(STATUS_BUSY,
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
statusOption status to set on profile
callback success and failure callbacks

Response for successCallback:

{
    message: "status updated"
}

setStatusMessage

Method Signature:

public virtual void setStatusMessage(
                             string statusMessage,
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.setStatusMessage("What a beautiful day!!",
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
statusMessage status message to set on profile
callback success and failure callbacks

Response for successCallback:

{ 
    message: "status message updated" 
}

getUserInfo

Allows logged-in user to fetch details of any user. Method Signature:

public virtual void getUserInfo(
                             string userId,
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.getUserInfo("12",
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
userId recipient’s user id
callback success and failure callbacks

Response for successCallback:

{
    "id": "12",
    "n": "Jon Snow",
    "l": "",
    "d": "0",
    "a": "",
    "s": "offline",
    "m": "Wonderful day",
    "ch": "cc735e0970a1e82bb6738e59b881cb23",
    "ls": "1451218483",
    "lstn": "0"
}

getOnlineUsers

You can get the user list whenever you require. Method Signature:

public virtual void GetOnlineUsers(
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.GetOnlineUsers(
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
callback success and failure callbacks

Response for successCallback:

{
    {
        "id": "1","n": "User1", "a": "avatar.png", "d": "1", "s": "available","m": "I'm available"
    },
    {
        "id": "2", "n": "User2", "a": "avatar.png", "d": "1",  "s": "available","m": "I'm available"
    }
}

sendMessage

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

public virtual void sendMessage(
                             string message,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendMessage("Hi! How are you?","15","50"
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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": 50,
    "m": "Hi! How are you?"
}

sendImage

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

Sending a image data

Method Signature:

public virtual void SendImageWithData(
                             NSData imageData,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.SendImageWithData(imageData,"15","50",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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,
}

Sending an image using file path

Method Signature:

public virtual void sendImageWithPath(
                             string imagePath,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendImageWithPath("/Documents/IMG1049.JPG","12","50",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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
imagePath image path from storage
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

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

sendVideo

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

public virtual void sendVideoWithPath(
                             string videoPath,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendVideoWithPath("/Documents/Video.mp4","12","50",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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":301,
    "original_file": "/Documents/Video.mp4",
}

sendAudioFile

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

Method Signature:

public virtual void sendAudioWithPath(
                             string audioPath,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendAudioWithPath("/Documents/audio1.aac","15","50",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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":501,
    "original_file": "/Documents/audio1.aac"
}

sendSticker

Allows the user to send a sticker.

Method signature:

public virtual void sendStickers(
                             string stickerName,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendStickers("bear_1","15","50",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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.

Method Signature:

public virtual void sendFile(
                             string filePath,
                             string toId,
                             string localID,
                             Bool isGroup
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.sendFile("Path of File To Be Sent","15","501",NO
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* 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

getChatHistory

Allows logged-in user to get the previous message

Method Signature:

public virtual void getChatHistory(
                             string userId,
                             string messageId,
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.getChatHistory("10","102",
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
userId recipient’s user id
messageId last message id
callback success and failure callbacks

Response for successCallback:

{
  history : [
   { 
     from = 14; id = 4843;  message = "HI"; "message_type" = 10; old = 1;  self = 1;  sent = 1429771974000;
   },
   { 
     from = 14; id = 4844;  message = "Hello"; "message_type" = 10; old = 1;  self = 1;  sent = 1429772345000;
   },
  .
  .
 ]
}

broadcastMessage

Allows logged-in user to send a message to more than one users Method Signature:

public virtual void broadcastMessage(
                             string message,
                             NSObject[] usersId,
                             Action < NSDictionary > response,
                             Action < NSError> failure
                             )

Example:

cometchat.broadcastMessage("Hi! How are you?",users,
                   (dict) => { this.response(dict); /* code block */ }, 
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
message message text
users recipient user’s array
callback success and failure callbacks

Response for successCallback:

{
    [
        {  "id": 71, "to":1,  "m": "Hi! How are you?" },
        {  "id": 72, "to":2,  "m": "Hi! How are you?" },
        {  "id": 73, "to":3,  "m": "Hi! How are you?" }
    ]
}

isTyping

Allows logged-in user to send an typing notification Method Signature:

public virtual void isTyping(
                             Bool istyping,
                             string channel,
                             Action < NSError> failure
                             )

Example:

cometchat.isTyping(true,"49086e3ef2d52d104fa0bc7cade215cf",
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
isTyping This is boolean value , pass true when you start typing, pass false when you stop typing
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

sendDeliverdReceipt

Allows logged-in user to notify message delivery to the sender. Method Signature:

public virtual void sendDeliverdReceipt(
                             string msgID,
                             string channel,
                             Action < NSError > failure
                             )

Example:

cometchat.sendDeliverdReceipt("5","49086e3ef2d52d104fa0bc7cade215cf",
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
msgID id for the received message
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

sendReadReceipt

Allows logged-in user to notify to the sender that the message has been read. Method Signature:

public virtual void sendReadReceipt(
                             string msgID,
                             string channel,
                             Action < NSError > failure
                             )

Example:

cometchat.sendReadReceipt("5","49086e3ef2d52d104fa0bc7cade215cf",
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
msgID id for the received message
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

getAllAnnouncements

Gets all the announcements added by CometChat admin. Method Signature:

public virtual void getAllAnnouncements:(
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.getAllAnnouncements(
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
callback success and failure callbacks

Response for successCallback:

{
  "_2":
    { "id": "2", "m": "Test 2", "t": "1416576762"},
  "_1":
    { "id": "1", "m": "Announcements test","t": "1416576743" }
}

blockUser

Allows logged-in user to block a user Method Signature:

public virtual void blockUser(
                             string userID,
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.blockUser("15",
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
userID recipient id to be block
callback success and failure callbacks

Response for successCallback:

{
    "id": "15"
}

Description:

Response Proprty Description
id userid of blocked user

getBlockedUserList

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

public virtual void getBlockedUserList:(
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.getBlockedUserList(
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Response for successCallback:

{
    "73": { "id": "73", "name": "user73" },
    "700": { "id": "70", "name": "user70" }
}

Description:

Response Property Description
callback success and failure callbacks

unblockUser

Allows logged-in user to unblock a user Method Signature:

public virtual void unblockUser(
                             string userID,
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.unblockUser("15",
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
userID recipient id to be unblock
callback success and failure callbacks

Response for successCallback:

{
    "id": "15"
}

Description:

Response Proprty Description
id userid of unblocked user

setTranslateLanguage

Allows logged-in user to set a language for real time translation Method Signature:

public virtual void setTranslateLanguage(
                             nint language,
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.setTranslateLanguage(Spainsh,
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Arguments:

Argument Description
ENUM a value from Languages enum
Callbacks Callback Methods

Response for successCallback:

{
    "Selected language": "Spanish"
}

getPluginInfo

Gets the enabled status for the plugins Method Signature:

public virtual void getPluginInfo(
                             Action < NSDictionary > response,
                             Action < NSError > failure
                             )

Example:

cometchat.getPluginInfo(
                   (dict) => { this.response(dict); /* code block */ },
                   (err) => { this.failure(err); /* code block */ }
                   );

Response for successCallback:

{
    "avchat_enabled": "1",
    "audiochat_enabled": "1",
    "createchatroom_enabled": "1",
    "blockuser_enabled": "0",
    "mediasharing_enabled": "1",
    "chatroom_mediasharing_enabled": "1",
    "realtime_translate_enabled": "0"
}

isUserLoggedIn

Return true if user has logged-in Method Signature:

public bool IsUserLoggedIn{ get; }

Example:

cometChat.isUserLoggedIn();

  • Was this helpful?
  • Yes   No