Class CustomMessageContent

  • All Implemented Interfaces:

    
    public abstract class CustomMessageContent
    extends MessageContent
                        

    Base class for custom message content.

    Extend this class to define custom message types. The SDK handles registration, sending, and decoding automatically — no internal SDK types are needed.

    Subclasses must:

    Usage example:

    class CardMessage : CustomMessageContent() {
        var title: String = ""
        var imageUrl: String = ""
        var linkUrl: String = ""
    
        override fun messageType(): String = "app:card"
    
        override fun persistentFlag(): Int = MessagePersistent.COUNT
    
        override fun encodeFields(): Map<String, Any?> = mapOf(
            "title" to title,
            "imageUrl" to imageUrl,
            "linkUrl" to linkUrl
        )
    
        override fun decodeFields(fields: Map<String, Any?>) {
            title = fields["title"] as? String ?: ""
            imageUrl = fields["imageUrl"] as? String ?: ""
            linkUrl = fields["linkUrl"] as? String ?: ""
        }
    }
    
    NCEngine.registerCustomMessages(listOf(CardMessage::class.java))
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract String messageType() Message type identifier.
      abstract Integer persistentFlag() Message storage policy flag.
      abstract Map<String, Object> encodeFields() Encodes the message content into serializable key-value pairs.
      abstract Unit decodeFields(Map<String, Object> fields) Decodes the message content from field data.
      List<String> searchableWords() Returns a list of keywords to be indexed for message search.
      • Methods inherited from class ai.nexconn.chat.message.MessageContent

        getDestructTime, getExtra, getMentionedInfo, isDestruct, setDestruct, setDestructTime, setExtra, setMentionedInfo, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CustomMessageContent

        CustomMessageContent()
    • Method Detail

      • messageType

         abstract String messageType()

        Message type identifier.

        Must not start with "RC:" (reserved prefix). Must be consistent across all platforms (Android / iOS / Web).

        Examples: "app:card", "app:order", "app:vote"

      • encodeFields

         abstract Map<String, Object> encodeFields()

        Encodes the message content into serializable key-value pairs.

        Called when sending a message. Values must be JSON-serializable types: String, Int, Long, Double, Boolean, List, or Map.

        Returns:

        a map of field names to their serializable values

      • decodeFields

         abstract Unit decodeFields(Map<String, Object> fields)

        Decodes the message content from field data.

        Called when receiving a message. Restores custom message properties from the given key-value pairs. Values may be String, Int, Long, Double, Boolean, List, Map, etc.

        Parameters:
        fields - the deserialized JSON field data of the message
      • searchableWords

         List<String> searchableWords()

        Returns a list of keywords to be indexed for message search.

        Defaults to an empty list.

        Returns:

        a list of searchable keywords