topic-based-chat

Topic based chat lets you to group the chat by topic. You can create the topic, send all types of messages with topic information and thus you can receive the messages by topic.

Create Topic#

You can use the below given method to create a new topic.

    ChatManager.createTopic(topicName: "TOPIC_NAME", metaData: "META_DATA") { isSuccess, error, data in
    }
    ArgumentTypeDescription
    topicNameStringName of the topic (cannot be null or empty)
    metaData[MetaData]META_DATA is an optional parameter to provide additional information of topic, you can pass array of MetaData Maximum Size is 3

    Get Topics#

    You can use the below given method to get the topics details.

      ChatManager.getTopics(topicIds: "TOPIC_IDS") { isSuccess, error, data in
      }
      ArgumentTypeDescription
      topicIds[String]List of topic ids

      Send Message#

      To send the message to the user, use the below methods. Different messages such as text, image, audio, video & document type messages can be sent using the below methods.

      Text message#

      To send your text message, you need to pass the TextMessage object as an argument to the parameter in the sendTextMessage() method.

        var textMessage = TextMessage()
        textMessage.toId = TO_JID
        textMessage.messageText = MESSAGE
        textMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
        textMessage.mentionedUsersIds = MENTION_IDS // Optional
        textMessage.metaData = META_DATA // Optional
        textMessage.topicID = TOPIC_ID // Optional
        FlyMessenger.sendTextMessage(messageParams: textMessage) { isSuccess, error, chatMessage in
        if (isSuccess) {
        //you can add this message object to your arraylist,
        //then you can notify the tableview
        }
        }
        ArgumentTypeDescription
        MESSAGE_PARAMSTextMessageObject to hold the parameters of the text message
        CALLBACKFlySendMessageListenercallback to observe the action status

        Image message#

        To send your image message, you need to pass the FileMessage object with FileMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

          var fileMessageParams = FileMessageParams()
          fileMessageParams.fileUrl = FILE_URL
          fileMessageParams.fileName = FILE_NAME
          fileMessageParams.fileSize = FILE_SIZE
          fileMessageParams.thumbImage = THUMB_IMAGE
          fileMessageParams.caption = CAPTION
          fileMessageParams.fileKey = FILE_KEY
          var fileMessage = FileMessage()
          fileMessage.toId = TO_JID
          fileMessage.messageType = MessageType.image
          fileMessage.fileMessage = fileMessageParams
          fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
          fileMessage.mentionedUsersIds = MENTION_IDS // Optional
          fileMessage.metaData = META_DATA // Optional
          fileMessage.topicID = TOPIC_ID // Optional
          FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
          if (isSuccess) {
          //you can add this message object to your arraylist,
          //then you can notify the tableview
          }
          }
          ArgumentTypeDescription
          MESSAGE_PARAMSFileMessageObject to hold the parameters of the image message
          CALLBACKFlySendMessageListenercallback to observe the action status

          To get the metadata of an image file for sending images make use of the utility methods MediaUtils.getAssetsImageInfo() and MediaUtils.compressImage()

          caution

          If Image attachment feature unavailable for your plan then it will throw 403 exception.

          Audio message#

          To send your audio message, you need to pass the FileMessage object with FileMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

            var fileMessageParams = FileMessageParams()
            fileMessageParams.fileUrl = FILE_URL
            fileMessageParams.fileName = FILE_NAME
            fileMessageParams.fileSize = FILE_SIZE
            fileMessageParams.thumbImage = THUMB_IMAGE
            fileMessageParams.duration = DURATION
            fileMessageParams.caption = CAPTION
            fileMessageParams.fileKey = FILE_KEY
            var fileMessage = FileMessage()
            fileMessage.toId = TO_JID
            fileMessage.messageType = MessageType.audio
            fileMessage.fileMessage = fileMessageParams
            fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
            fileMessage.mentionedUsersIds = MENTION_IDS // Optional
            fileMessage.metaData = META_DATA // Optional
            fileMessage.topicID = TOPIC_ID // Optional
            FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
            if (isSuccess) {
            //you can add this message object to your arraylist,
            //then you can notify the tableview
            }
            }
            ArgumentTypeDescription
            MESSAGE_PARAMSFileMessageObject to hold the parameters of the audio message
            listenerFlySendMessageListenercallback to observe the action status

            To get the metadata of an audio file for sending audio make use of the utility method MediaUtils.processAudio()

            caution

            If Audio attachment feature unavailable for your plan then it will throw 403 exception.

            Video message#

            To send your video message, you need to pass the FileMessage object with FileMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

              var fileMessageParams = FileMessageParams()
              fileMessageParams.fileUrl = FILE_URL
              fileMessageParams.fileName = FILE_NAME
              fileMessageParams.fileSize = FILE_SIZE
              fileMessageParams.duration = DURATION
              fileMessageParams.thumbImage = THUMB_IMAGE
              fileMessageParams.caption = CAPTION
              fileMessageParams.fileKey = FILE_KEY
              var fileMessage = FileMessage()
              fileMessage.toId = TO_JID
              fileMessage.messageType = MessageType.video
              fileMessage.fileMessage = fileMessageParams
              fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
              fileMessage.mentionedUsersIds = MENTION_IDS // Optional
              fileMessage.metaData = META_DATA // Optional
              fileMessage.topicID = TOPIC_ID // Optional
              FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
              if (isSuccess) {
              //you can add this message object to your arraylist,
              //then you can notify the tableview
              }
              }
              ArgumentTypeDescription
              MESSAGE_PARAMSFileMessageObject to hold the parameters of the video message
              LISTENERFlySendMessageListenercallback to observe the action status

              To get the metadata of a video file for sending videos make use of the utility methods MediaUtils.processVideo() and MediaUtils.compressVideo()

              caution

              If Video attachment feature unavailable for your plan then it will throw 403 exception.

              Document message#

              To send your document message, you need to pass the FileMessage object with FileMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

                var fileMessageParams = FileMessageParams()
                fileMessageParams.fileUrl = FILE_URL
                fileMessageParams.fileName = FILE_NAME
                var fileMessage = FileMessage()
                fileMessage.toId = TO_JID
                fileMessage.messageType = MessageType.document
                fileMessage.fileMessage = fileMessageParams
                fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
                fileMessage.mentionedUsersIds = MENTION_IDS // Optional
                fileMessage.metaData = META_DATA // Optional
                fileMessage.topicID = TOPIC_ID // Optional
                FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
                if (isSuccess) {
                //you can add this message object to your arraylist,
                //then you can notify the tableview
                }
                }
                ArgumentTypeDescription
                MESSAGE_PARAMSFileMessageObject to hold the parameters of the document message
                CALLBACKFlySendMessageListenercallback to observe the action status
                caution

                If Document attachment feature unavailable for your plan then it will throw 403 exception.

                Location message#

                To send your location message, you need to pass the FileMessage object with LocationMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

                  var locationMessageParams = LocationMessageParams()
                  locationMessageParams.latitude = LATITUDE
                  locationMessageParams.longitude = LONGITUDE
                  var fileMessage = FileMessage()
                  fileMessage.toId = TO_JID
                  fileMessage.messageType = MessageType.location
                  fileMessage.locationMessage = locationMessageParams
                  fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
                  fileMessage.mentionedUsersIds = MENTION_IDS // Optional
                  fileMessage.metaData = META_DATA // Optional
                  fileMessage.topicID = TOPIC_ID // Optional
                  FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
                  if (isSuccess) {
                  //you can add this message object to your arraylist,
                  //then you can notify the tableview
                  }
                  }
                  ArgumentTypeDescription
                  MESSAGE_PARAMSFileMessageObject to hold the parameters of the location message
                  CALLBACKFlySendMessageListenercallback to observe the action status
                  caution

                  If Location attachment feature unavailable for your plan then it will throw 403 exception.

                  Contact message#

                  To send your contact message, you need to pass the FileMessage object with ContactMessageParams set as an argument to the parameter in the sendMediaFileMessage() method.

                    var contactMessageParam = ContactMessageParams()
                    contactMessageParam.name = CONTACT_NAME
                    contactMessageParam.numbers = CONTACT_NUMBERS
                    var fileMessage = FileMessage()
                    fileMessage.toId = TO_JID
                    fileMessage.messageType = MessageType.contact
                    fileMessage.contactMessage = contactMessageParam
                    fileMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
                    fileMessage.mentionedUsersIds = MENTION_IDS // Optional
                    fileMessage.metaData = META_DATA // Optional
                    fileMessage.topicID = TOPIC_ID // Optional
                    FlyMessenger.sendMediaFileMessage(messageParams: fileMessage){ isSuccess,error,message in
                    if (isSuccess) {
                    //you can add this message object to your arraylist,
                    //then you can notify the tableview
                    }
                    }
                    ArgumentTypeDescription
                    MESSAGE_PARAMSFileMessageObject to hold the parameters of the contact message
                    CALLBACKFlySendMessageListenercallback to observe the action status
                    caution

                    If Contact attachment feature unavailable for your plan then it will throw 403 exception.

                    Meet message#

                    To send your Meet message, you need to pass the MeetMessage as an argument to the parameter in the sendMeetMessage() method.

                      var meetMessage = MeetMessage()
                      meetMessage.toId = TO_JID
                      meetMessage.link = MEET_LINK
                      meetMessage.scheduledDateTime = SCHEDULED_TIME
                      meetMessage.title = TITLE // Optional
                      meetMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
                      meetMessage.mentionedUsersIds = MENTION_IDS // Optional
                      meetMessage.metaData = META_DATA // Optional
                      meetMessage.topicID = TOPIC_ID // Optional
                      FlyMessenger.sendMeetMessage(messageParams: meetMessage){ isSuccess,error,message in
                      if (isSuccess) {
                      //you can add this message object to your arraylist,
                      //then you can notify the tableview
                      }
                      }
                      ArgumentTypeDescription
                      MESSAGE_PARAMSMeetMessageObject to hold the parameters of the meet message
                      CALLBACKFlySendMessageListenercallback to observe the action status

                      Send Reply message#

                      To send reply message to the original message, you need to pass the additional parameter original message-id in replyMessageId. TextMessage object as an argument to the parameter in the sendTextMessage()

                        var textMessage = TextMessage()
                        textMessage.toId = TO_JID
                        textMessage.messageText = MESSAGE
                        textMessage.replyMessageId = REPLY_MESSAGE_ID // Optional
                        textMessage.mentionedUsersIds = MENTION_IDS // Optional
                        textMessage.metaData = META_DATA // Optional
                        textMessage.topicID = TOPIC_ID // Optional
                        FlyMessenger.sendTextMessage(messageParams: textMessage) { isSuccess, error, chatMessage in
                        if (isSuccess) {
                        //you can add this message object to your arraylist,
                        //then you can notify the tableview
                        }
                        }
                        ArgumentTypeDescription
                        MESSAGE_PARAMSTextMessageObject to hold the parameters of the text message
                        CALLBACKFlySendMessageListenercallback to observe the action status

                        Receive Message#

                        To receive a Topic related message from another user you must implement the messageListener function. It’s a function that will be triggered whenever you receive a new message or related event in the chat.

                          func onMessageReceived(message : ChatMessage, chatJid: String) {
                          }
                          info

                          To learn more on message listener callbacks, see the Message Events Delegate.

                          Get Chats by Topic Id#

                          Create a TopicChatListParams instance. Here, you can set the topic based chat filter options .

                            var topicChatListParams = TopicChatListParams()
                            topicChatListParams.limit = "LIMIT"
                            topicChatListParams.topicID = "TOPIC_ID"
                            ArgumentTypeDescription
                            LIMITIntNo of topic based chats will be fetched for each request default 40
                            TOPIC_IDStringParticular topic based chats will be fetched

                            Next, create a TopicChatListBuilder instance.

                              let topicChatListBuilder = TopicChatListBuilder(topicChatListParams: TOPIC_LIST_PARAM)
                              ArgumentTypeDescription
                              TOPIC_LIST_PARAMTopicChatListParamsInsatance of 'TopicChatListParams'

                              Load Initial Topic Based Chats#

                              To fetch initial set of topic based chat data, call the below method.

                                topicChatListBuilder?.loadTopicBasedChatList(completionHandler: { isSuccess, error, data in
                                var result = data
                                if isSuccess {
                                let topicChatArray = result.getData() as? [RecentChat]
                                } else {
                                // Fetch topic chat failed print error to know more about the exception
                                }
                                })
                                ArgumentTypeDescription
                                CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                                Load Next Set Topic Based Chats#

                                To fetch next set of topic based chats, call the below method.

                                  topicChatListBuilder?.nextSetOfTopicBasedChatList(completionHandler: { isSuccess, error, data in
                                  var result = data
                                  if isSuccess {
                                  var topicChatArray = result.getData() as? [RecentChat]
                                  }
                                  else {
                                  // Fetch topic chat failed print error to know more about the exception
                                  }
                                  })
                                  ArgumentTypeDescription
                                  CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                                  Get Message#

                                  To get the chat and media messages, use the below methods

                                  Get Chat Messages#

                                  Initialization#

                                  Create a FetchMessageListParams instance. Here, you can set the message filter to determine the message order and the starting point of the message list in the chat view.

                                    let messageListParams = FetchMessageListParams()
                                    messageListParams.chatId = "CHAT_ID"
                                    messageListParams.messageId = "MESSAGE_ID"
                                    messageListParams.messageTime = "MESSAGE_TIME"
                                    messageListParams.exclude = "EXCLUDE"
                                    messageListParams.limit = "LIMIT"
                                    messageListParams.ascendingOrder = "ASCENDING_ORDER"
                                    messageListParams.topicID = "TOPIC_ID" // Optional
                                    ArgumentTypeDescription
                                    CHAT_IDStringJid of the user/group
                                    MESSAGE_IDStringMessage id of the starting point optional
                                    MESSAGE_TIMEDoubleMessage time of the starting point optional
                                    EXCLUDEBoolIf true starting point message will be excluded in message list default true
                                    ASCENDING_ORDERBoolIf true message list will be returned ascendingOrder by message time default false
                                    LIMITIntNo of messages will be fetched for each request default 50
                                    TOPIC_IDStringTopic ID to be fetched`

                                    Secondly, create a FetchMessageListQuery instance.

                                      let messageListQuery = FetchMessageListQuery(MESSAGE_LIST_PARAM)
                                      ArgumentTypeDescription
                                      MESSAGE_LIST_PARAMFetchMessageListParams'Insatance of 'FetchMessageListParams'

                                      Load Initial Messages#

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

                                        messageListQuery.loadMessages { isSuccess, flyError, flyData in
                                        var data = flyData
                                        if (isSuccess) {
                                        let messageList = data.getData() as? [ChatMessage]
                                        } else {
                                        // Fetch messages failed print error to know more about the exception
                                        }
                                        }
                                        ArgumentTypeDescription
                                        CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                                        Load Previous Messages#

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

                                          messageListQuery.loadPreviousMessages { isSuccess, flyError, flyData in
                                          var data = flyData
                                          if (isSuccess) {
                                          let messageList = data.getData() as? [ChatMessage]
                                          } else {
                                          // Fetch messages failed print error to know more about the exception
                                          }
                                          }
                                          ArgumentTypeDescription
                                          CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                                          Load Next Messages#

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

                                            messageListQuery.loadNextMessages { isSuccess, flyError, flyData in
                                            var data = flyData
                                            if (isSuccess) {
                                            let messageList = data.getData() as? [ChatMessage]
                                            } else {
                                            // Fetch messages failed print error to know more about the exception
                                            }
                                            }
                                            ArgumentTypeDescription
                                            CALLBACKFlyCompletionHandlerFlyCompletionHandler implemented as closures

                                            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