Replying to Messages

To reply a particular message. You can call message creation method from AmityMessageRepository and inject the parentId.

func replyMessageExample() {
    // Create a reply message.
    // A `parentId` is the message id you are replying to.
    let newMessage = messageRepository.createTextMessage(withChannelId: "channel-123",
                                                         text: "Hello Amity!!",
                                                         tags: nil,
                                                         parentId: "message-123") { message, error in
         // Handle message creation result.
    }
}

When replying to a message, you can observe the message with specific channelId, force the filterByParentId to true, and inject the parentId of the message.

func queryReplyMessagesExample(){
    // A query for children messages belongs to the parentId.
    // Please note that `parentId` is requred, along with `filterByParentId` must be true.
    let childrenMessagesCollection = messageRepository.getMessages(channelId: "channel-123",
                                                                   includingTags: [],
                                                                   excludingTags: [],
                                                                   filterByParentId: true,
                                                                   parentId: "message-123",
                                                                   reverse: false)
    token = childrenMessagesCollection.observe { collection, change, error in
        for message in collection.allObjects() {
            // For example, to handle each message in the list.
        }
    }
}

Last updated