Single chat module

Prerequisites#

In 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 jid#

Almost 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 (@).

ArgumentTypeDescription
UNIQUE_USER_IDStringunique userId for preparing JID
FlyUtils.getJid(UNIQUE_USER_ID)

Text message#

Text 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.

FlyMessenger.sendTextMessage(TO_JID, TEXT, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}
ArgumentTypeDescription
TO_JIDStringjid of the end user
MESSAGEStringText message to be sent
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKFlySendMessageListenercallback to observe the action status

Get messages#

To fetch all the conversation between you and a single chat user or group, call the below method.

var messages : [ChatMessage] = FlyMessenger.getMessagesOf(jid: JID)
ArgumentTypeDescription
JIDStringJid of the chat user/group

Get media messages#

To get the media messages of a conversation, call the below method.

var mediaMessages : [ChatMessage] = FlyMessenger.getMediaMessagesOf(jid: JID)
ArgumentTypeDescription
JIDStringJid of the chat user/group

Get Single message#

To get a single message from database using a message id, call the below method.

var message : ChatMessage? = FlyMessenger.getMessageOfId(MESSAGE_MID)
ArgumentTypeDescription
MESSAGE_MIDStringId of a message

Get messages using ids#

To get array of messages from database using their message ids, call the below method.

var messages : [ChatMessage] = FlyMessenger.getMessagesUsingIds(MESSAGE_MIDS)
ArgumentTypeDescription
MESSAGE_MIDS[String]Ids of messages

Location message#

Location 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
LATITUDEDoublelocation latitude which needs to be sent
LONGITUDEDoublelocation longitude which needs to be sent
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendLocationMessage(TO_JID, LATITUDE, LONGITUDE, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Contact message#

Contact 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
CONTACT_NAMEStringcontact name
CONTACT_NUMBERSList<String>list of numbers in that contact
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendLocationMessage(TO_JID, CONTACT_NAME, CONTACT_NUMBERS, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Video message#

Video 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
FILEURLvideo Url
CAPTION_TEXTStringcaption text for video file
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendVideoMessage(TO_JID, FILE, CAPTION_TEXT, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Video message with url#

If 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
VIDEO_FILE_NAMEStringname of the video file
VIDEO_FILE_URLStringfile url of the video
VIDEO_FILE_SIZEStringfile size of the video
VIDEO_DURATIONStringduration of the video
THUMBNAIL_BASE64Stringbase64 encoded thumbnail image of the video
LOCAL_FILE_PATHStringlocalFilePath of the video
VIDEO_CAPTIONStringcaption text for the video
REPLY_MESSAGE_IDif it is a reply message for message A, then message A's messageId otherwise empty string
listenerSendMessageListenercallback to observe the action status
FlyMessenger.sendVideoMessage(TO_JID, VIDEO_FILE_NAME, VIDEO_FILE_URL, VIDEO_FILE_SIZE, VIDEO_DURATION, THUMBNAIL_BASE64,
LOCAL_FILE_PATH, VIDEO_CAPTION, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Image message#

To 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

ArgumentTypeDescription
TO_JIDStringjid of the end user
IMAGE_FILEURLimage Url which needs to be sent
THUMBNAIL_BASE64Stringbase64 string representation of thumbnail of the original image
CAPTIONStringadditional text which can be sent along with the image message
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendImageMessage(TO_JID, IMAGE_FILE, THUMBNAIL_BASE64, CAPTION, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Image message with url#

To 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
IMAGE_FILE_NAMEStringname of the image file we are sending
IMAGE_FILE_SIZEStringsize of the image file in bytes
IMAGE_FILE_URLStringurl of the image file that was uploaded
IMAGE_FILE_LOCAL_PATHStringlocal path of the image file in the device
THUMBNAIL_BASE64Stringbase64 string representation of thumbnail of the original image
CAPTIONStringadditional text which can be sent along with the image message
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendImageMessage(TO_JID, IMAGE_FILE_NAME, IMAGE_FILE_SIZE, IMAGE_FILE_URL, IMAGE_FILE_LOCAL_PATH, THUMBNAIL_BASE64, CAPTION, REPLY_MESSAGE_ID){isSuccess,error,message in
if isSuccess {
// append message in your array and the update ui
// reset the message TextField UI
}
}

Audio message#

To 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

ArgumentTypeDescription
TO_JIDStringjid of the end user
AUDIO_FILEURLaudio Url we are sending
AUDIO_DURATIONLongduration of the audio file
REPLY_MESSAGE_IDStringif it is a reply message for message A, then message A's messageId otherwise empty string
CALLBACKSendMessageListenercallback to observe the action status
FlyMessenger.sendAudioMessage(TO_JID, AUDIO_FILE, AUDIO_DURATION, REPLY_MESSAGE_ID, (isSuccess, message) -> {
if (message != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});

Audio message with url#

To 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.

ArgumentTypeDescription
TO_JIDStringjid of the end user
AUDIO_FILE_SIZEStringsize of the audio file in bytes
AUDIO_FILE_URLStringurl of the audio file that was uploaded
AUDIO_FILE_LOCAL_PATHStringlocal path of the audio file in the device
AUDIO_DURATIONLongduration of the audio file
replyMessageIdif it is a reply message for message A, then message A's messageId otherwise empty string
listenerSendMessageListener callback to observe the action status
FlyMessenger.sendAudioMessage(TO_JID, AUDIO_FILE_SIZE, AUDIO_FILE_URL, AUDIO_FILE_LOCAL_PATH, AUDIO_DURATION,
REPLY_MESSAGE_ID, (isSuccess, message) -> {
if (message != null) {
//you can add this message object to your arraylist,
//then you can call notifyItemInserted in adapter of recycler view
}
});