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:
Provide a no-argument constructor (the SDK creates instances via reflection)
Implement messageType, persistentFlag, encodeFields, decodeFields
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))
-
-
Field Summary
Fields Modifier and Type Field Description private Stringextraprivate MentionedInfomentionedInfoprivate BooleanisDestructprivate LongdestructTime
-
Constructor Summary
Constructors Constructor Description CustomMessageContent()
-
Method Summary
Modifier and Type Method Description abstract StringmessageType()Message type identifier. abstract IntegerpersistentFlag()Message storage policy flag. abstract Map<String, Object>encodeFields()Encodes the message content into serializable key-value pairs. abstract UnitdecodeFields(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
-
-
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"
-
persistentFlag
abstract Integer persistentFlag()
Message storage policy flag.
See MessagePersistent constants:
MessagePersistent.NONE — Not stored, not counted
MessagePersistent.PERSIST — Stored but not counted
MessagePersistent.COUNT — Stored and counted
MessagePersistent.STATUS — Status message
-
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
-
-
-
-