Single chat module
#
PrerequisitesIn order to send messages using the chat sdk , at first you need to establish the connection to the server. sdk provides methods for initializing the connection configuration as well as methods for making connection.
Note: Even if you don't have internet connection, you are still allowed to send messages which will be kept in offline database.Once the user connected to the internet, the messages will be sent automatically when user opens the app.
#
Preparing single chat jidAlmost of the sdk methods expect jid as a input parameter, so sdk provides below utility method to prepare the jid. The method prepares the single chat jid from the given string by using chat config provided via [com.contusflysdk.api.ChatConnectionManager.initialize] method.
Note: The below characters is not allowed in uniqueId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@).
Argument | Type | Description |
---|---|---|
UNIQUE_USER_ID | String | unique userId for preparing JID |
- Java
- Kotlin
#
Text messageText is a basic form of communication between users. sdk provides methods to send the text message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the text message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
TEXT | String | text message to be sent |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Location messageLocation sharing is a famous communication between users. sdk provides methods to send the location message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the location message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
LATITUDE | Double | location latitude which needs to be sent |
LONGITUDE | Double | location longitude which needs to be sent |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Contact messageContact sharing is very useful communication between users. sdk provides methods to send the contact message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the contact message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
CONTACT_NAME | String | contact name |
CONTACT_NUMBERS | List<String> | list of numbers in that contact |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Document messageDocument sharing is very useful communication between users. sdk provides methods to send the document message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the document message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
FILE | File | document file object |
FILE_NAME | String | name of the document |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Document message with urlIf you have uploaded the document to your own media server and the you want to share document with other user. sdk provides methods to send the document message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the document message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
FILE_NAME | String | name of the document |
FILE_SIZE | String | file size of the document |
FILE_URL | String | file url of the document |
LOCAL_FILE_PATH | String | localFilePath of the document |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Video messageVideo sharing is very useful communication between users. sdk provides methods to send the video message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the video message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
FILE | File | video file object |
CAPTION_TEXT | String | caption text for video file |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Video message with urlIf you have uploaded the video to your own media server and the you want to share video with other user. sdk provides methods to send the video message to the end users. once the user has sent message via sdk, it will give callback with status. if you want send the video message for a user, you can utilise the below method.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
VIDEO_FILE_NAME | String | name of the video file |
VIDEO_FILE_URL | String | file url of the video |
VIDEO_FILE_SIZE | String | file size of the video |
VIDEO_DURATION | String | duration of the video |
THUMBNAIL_BASE64 | String | base64 encoded thumbnail image of the video |
LOCAL_FILE_PATH | String | localFilePath of the video |
VIDEO_CAPTION | String | caption text for the video |
REPLY_MESSAGE_ID | if it is a reply message for message A, then message A's messageId otherwise empty string | |
listener | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Image messageTo send image as a message call the below method. Calling the below method will upload the image file to the server provided during sdk initialization then send the message
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
IMAGE_FILE | File | image File which needs to be sent |
THUMBNAIL_BASE64 | String | base64 string representation of thumbnail of the original image |
CAPTION | String | additional text which can be sent along with the image message |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Image message with urlTo send image as a message call the below method. You can upload the image file to your storage of choice and send the url and other necessary info while sending the message.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
IMAGE_FILE_NAME | String | name of the image file we are sending |
IMAGE_FILE_SIZE | String | size of the image file in bytes |
IMAGE_FILE_URL | String | url of the image file that was uploaded |
IMAGE_FILE_LOCAL_PATH | String | local path of the image file in the device |
THUMBNAIL_BASE64 | String | base64 string representation of thumbnail of the original image |
CAPTION | String | additional text which can be sent along with the image message |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Audio messageTo send audio as a message call the below method. Calling the below method will upload the audio file to the server provided during sdk initialization then send the message
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
AUDIO_FILE | File | audio File we are sending |
AUDIO_DURATION | Long | duration of the audio file |
IS_RECORDED | Boolean | true , if audio file is recorded.false , if audio file is attached. |
REPLY_MESSAGE_ID | String | if it is a reply message for message A, then message A's messageId otherwise empty string |
CALLBACK | SendMessageListener | callback to observe the action status |
- Java
- Kotlin
#
Audio message with urlTo send audio as a message call the below method. You can upload the audio file to your storage of choice and send the url and other necessary info while sending the message.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the end user |
AUDIO_FILE_SIZE | String | size of the audio file in bytes |
AUDIO_FILE_URL | String | url of the audio file that was uploaded |
AUDIO_FILE_LOCAL_PATH | String | local path of the audio file in the device |
AUDIO_DURATION | Long | duration of the audio file |
replyMessageId | if it is a reply message for message A, then message A's messageId otherwise empty string | |
listener | SendMessageListener callback to observe the action status |
- Java
- Kotlin
#
Get media messagesIf you want to get the media messages for a user/group, you can utilise the below method.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
JID | String | jid of the chat user |
info
Above methods fetch media messages which are successfully sent and received.
To get the uploaded/downloaded status of a media message Refer the snippet below.
For received media message:
- Java
- Kotlin
For sent media message:
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
MEDIA_MESSAGE_ID | String | id of a message |
#
Delete MessagesDelete messsage is a feature which is found in modern messaging apps which allows the user to delete the message once it is sent.Once you sent the message, you can able to delete the messages by using built in sdk methods.
#
Delete for meIf you want to delete the messages for yourself only then you can use the below method.
Note: The messages will not be deleted to the receipient.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the chat user |
MESSAGE_ID_LIST | List<String> | List of messageId to be deleted |
DELETE_CHAT_TYPE | DeleteChatType | DeleteChatType.chat for single chat, DeleteChatType.groupchat for group chat |
CALLBACK | ChatActionListener | callback to observe the action status |
- Java
- Kotlin
#
Delete for everyoneIf you want to delete the messages for yourself and receiver then you can use the below method. The messages will also be deleted to the receipient.
Argument | Type | Description |
---|---|---|
TO_JID | String | jid of the chat user |
MESSAGE_ID_LIST | List<String> | List of messageId to be deleted |
DELETE_CHAT_TYPE | DeleteChatType | DeleteChatType.chat for single chat, DeleteChatType.groupchat for group chat |
CALLBACK | ChatActionListener | callback to observe the action status |
- Java
- Kotlin
#
Favourite MessagesFavourite messags is feature which allows users to mark some messages as favourites. so that they can see those important messages in future without searching for them in chat. Once you marked messages as favourite, you can get those from sdk to show it in your app's screen.
Argument | Type | Description |
---|---|---|
MESSAGE_ID | String | messageId of the message |
CHAT_USER_JID | String | jid of the chat user |
IS_FAVOURITE | boolean | true , if you are adding to favourites.false to remove from favourites |
CALLBACK | ChatActionListener | callback to observe the action status |
#
Make favouriteYou can mark the messages as favourite by using the below method.
- Java
- Kotlin
#
Remove favouriteYou can remove the messages from favourite by using the below method.
- Java
- Kotlin
#
Get all favourite messagesThe below method will return all the favourite messages from the local db.
- Java
- Kotlin
#
Unfavorite all the favourite messagesYou can unfavourite all the favourite messages by using the below method.
- Java
- Kotlin
#
Message receiptsinfo
To obserserve message's sent, delivered, read status refer the message callback listeners.
Message receipts is a feature which allows users to know the status of the sent messages as well as the delivered and read time for the messages. The chat app users are well informed about the status of the sent messages.
You need to update the ongoing chat user jid always whenever you are entering/exiting the chat window of user by using below method. it is used by sdk internally for receipts.
In activity/fragment onResume
, set the user jid as ongoing chat user.
Argument | Type | Description |
---|---|---|
JID | String | jid of the chat user |
- Java
- Kotlin
Then, in activity/fragment onPause
, clear the ongoing chat user.
- Java
- Kotlin
#
Mark messages as deliveredYou don't need to send the delivery receipts explicitly, it will be automatically sent by the sdk.
#
Mark messages as readOnce the user reads the messages of user B or entered into the chat window of user B, you can mark the messages as read by using the below method. In this case user B's jid will be passed to the below method. Then read receipts will be managed by sdk. sdk will utilise the ongoing chat user jid which is set by this method ChatManager.setOnGoingChatUser(jid: String)
Argument | Type | Description |
---|---|---|
JID | String | jid of the chat user |
- Java
- Kotlin
info
Sdk is having a built-in functions to prepare the JID, Group JID.
#
Get single chat message statusTo get the time of sent, delivered and seen status of a message sent by you in a single one to one chat call the below method.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
MESSAGE_ID | String | message id of the message |
#
Get messages of a user/groupTo fetch all the conversation between you and a single chat user or group, call the below method.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
JID | String | Jid of the user/group |
#
Get message from dbWhenever you get callbacks from MessageEventsListener, you will get messageId sometimes at those times you can fetch the message from db using the below method and then update your list as well as notify the list view.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
MESSAGE_ID | String | messageId of the message |
#
Get messages using idTo get list of messages from a given message id's call the below method.
- Java
- Kotlin
#
Remove unread message separatorTo remove the unread message separator in a chat conversation list call the below method.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
JID | String | Jid of the user/group |
#
Get recalled messages of a user/groupTo get the recalled messages of a user/group call the below method.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
JID | String | Jid of the user/group |
#
Upload/Download media messageWhenever you receive a media message from a user, or when retrying to upload a already sent media message you can use built-in sdk functions to upload/download the media content / The below method is applicable only if you are using sdk media server, otherwise you have to handle uploading/downloading the media by your own implementation as well as update the status of the media message.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
isRetry | Boolean | If false for the first time video upload will compress the size and send, If true the video upload file will not compress again (avoid duplicates) |
MEDIA_MESSAGE_ID | String | Id of the media message |
#
Update media status#
Update media download statusIf you are using your own media service, whenever the media downloading status is changed, you have to update the media message status like below.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
MEDIA_MESSAGE_ID | String | id of the media message |
PROGRESS_STATUS | int | percentage of the file downloaded till now (0-100) |
DATA_TRANSFERRED | long | size of the file downloaded till now |
DOWNLOAD_STATUS | MediaDownloadStatus | status of the upload |
status
value could be one of the values below:
- Java
- Kotlin
#
Update media upload statusIf you are using your own media service, whenever the media uploading status is changed, you have to update the media message status like below.
- Java
- Kotlin
Argument | Type | Description |
---|---|---|
MEDIA_MESSAGE_ID | String | id of the media message |
PROGRESS_STATUS | int | percentage of the file uploaded till now (0-100) |
DATA_TRANSFERRED | long | size of the file uploaded till now |
UPLOAD_STATUS | MediaUploadStatus | status of the upload |
status
value could be one of the values below:
- Java
- Kotlin
#
Cancel upload/downloadWhenever you would like to cancel upload/download of a media message , you can use built-in sdk functions to cancel the media content upload/download.The below method is applicable only if you are using sdk media server, otherwise you have to handle cancelling the media by your own implementation as well as update the status of the media message.
Argument | Type | Description |
---|---|---|
MESSAGE_ID | String | message id of the media message |
- Java
- Kotlin
When the user cancelled the media download, then user need to restart the download using
FlyMessenger.downloadMedia(messageId: String)
method. In case of media upload, the upload initiated once the user sent the message In case of retry callFlyMessenger.uploadMedia(messageId: String)
.
info
Sdk is having a built-in functions to prepare the JID, Group JID.
#
Upload/Download push notification tap actionWhenever you would like to add tap action for Upload/Download push notification, you can use built-in sdk functions to add action listener to upload/download push notification. The below method is applicable only if you are using sdk media server, otherwise you have to handle tap action by your own implementation.
In your application class oncreate
method add the below method:
- Java
- Kotlin
#
Delete all messages in local dbTo delete all the chat conversation messages and their relevent data like message statuses call the below method.
- Java
- Kotlin