# Class Message

消息实体，包含消息的所有属性

#### Version

1.0.0

- Defined in message/Message.ts:18

##### Index

### Constructors

constructor

### Properties

conversationType
targetId
channelId
messageId
direction
senderId
receivedStatus
sentStatus
receivedTime
sentTime
objectName
content
messageUid
extra
pushConfig
canIncludeExpansion
expansion
readReceiptInfo
readReceiptInfoV2
modifyInfo
needReceipt
sendReceipt

### Methods

checkForSend
checkForSendMedia
checkForDestruct

## Constructors

### constructor

- new Message(conId: ConversationIdentifier, content: MessageContent): Message

  消息构造方法

  conversationType、targetId、channelId、content、objectName 会被赋值

  #### Parameters

  - conId: ConversationIdentifier

    会话标识

  - content: MessageContent

    消息体内容

  #### Returns Message

  - Defined in message/Message.ts:168

## Properties

### conversationType

conversationType: ConversationType = ConversationType.Private

会话类型

#### See

EngineError

- Defined in message/Message.ts:22

### targetId

targetId: string = ''

会话 ID

- Defined in message/Message.ts:26

### channelId

channelId: string = ''

所属会话的业务标识，长度限制 20 字符

仅支持单群聊和超级群，其他类型的会话请传入空字符串

#### See

ConversationIdentifier.channelId

#### Version

1.2.0

- Defined in message/Message.ts:34

### messageId

messageId: number = 0

消息 ID，本地存储的消息的唯一值（数据库索引唯一值）

    发送消息时
    messageId > 0 时，SDK 更新数据库中对应的消息，然后再发送
    messageId <= 0 时，SDK 把消息直接入库，然后再发送
    只有当确实需要更新数据库消息时，设置 messageId > 0 ；其余情况 messageId <= 0

- Defined in message/Message.ts:44

### direction

direction: MessageDirection = MessageDirection.Send

消息方向

- Defined in message/Message.ts:48

### senderId

senderId: string = ''

消息发送者 ID

- Defined in message/Message.ts:52

### receivedStatus

receivedStatus: ReceivedStatus = ...

消息接收状态

- Defined in message/Message.ts:56

### sentStatus

sentStatus: SentStatus = SentStatus.Failed

消息的发送状态(针对发送的消息生效)

单聊消息已读时为 Read

- Defined in message/Message.ts:62

### receivedTime

receivedTime: number = 0

消息的接收毫秒时间戳，本地入库的时间，不能用做消息排序。消息排序用 sentTime

- Defined in message/Message.ts:66

### sentTime

sentTime: number = 0

消息的发送毫秒时间戳，服务端的发送时间，用作消息排序

- Defined in message/Message.ts:70

### objectName

objectName: string = ''

消息类型

- Defined in message/Message.ts:74

### content

content: MessageContent

消息内容，所有消息体的基类，需要根据 objectName 将 content 转为具体的消息类型

        // Message 必须为有效的消息，此处进行简写
        let message : Message;
        if (TextMessageObjectName === message.objectName) {
           // 转成文本消息
           let txtMsg = message.content as TextMessage;
        } else if (ImageMessageObjectName === message.objectName) {
           // 转成图片消息
           let imgMsg= message.content as ImageMessage;
        }

#### See

MessageContent

- Defined in message/Message.ts:91

### messageUid

messageUid: string = ''

服务器消息唯一 ID（在同一个 AppKey 下全局唯一）

固定格式的字符串，例如 ： CH2C-A072-OGM5-E3HL

- Defined in message/Message.ts:97

### extra

extra: string = ''

消息的附加字段

    Message.extra 只保存在本地数据库，卸载重装会丢失，不会随着消息发送出去
    MessageContent.extra 保存在消息体内部，会随着消息发送出去

- Defined in message/Message.ts:105

### pushConfig

pushConfig: PushConfig

推送配置

- Defined in message/Message.ts:109

### canIncludeExpansion

canIncludeExpansion: boolean = false

消息是否可以包含扩展信息

#### Discussion

该属性在消息发送时确定，发送之后不能再做修改

#### Discussion

扩展信息只支持单聊、群聊，其它会话类型不能设置扩展信息

#### Version

1.2.0

- Defined in message/Message.ts:118

### expansion

expansion: any = null

消息扩展信息列表

    默认消息扩展字典 key 长度不超过 32 ，value 长度不超过 4096 ，单次设置扩展数量最大为 20，消息的扩展总数不能超过 300

#### Discussion

扩展信息只支持单聊、群聊，其它会话类型不能设置扩展信息

#### Version

1.2.0

- Defined in message/Message.ts:128

### readReceiptInfo

readReceiptInfo: ReadReceiptInfo = null

群聊消息已读，仅在群聊生效

#### Version

1.3.0

- Defined in message/Message.ts:134

### readReceiptInfoV2

readReceiptInfoV2: ReadReceiptInfoV2 = null

群聊消息已读V2，仅在群聊生效

#### Version

1.4.0

- Defined in message/Message.ts:140

### modifyInfo

modifyInfo: ModifyInfo = null

- Defined in message/Message.ts:146

### needReceipt

needReceipt: boolean = false

是否需要已读回执

#### Version

1.5.0

- Defined in message/Message.ts:152

### sendReceipt

sendReceipt: boolean = false

是否已经发送已读回执

#### Version

1.5.0

- Defined in message/Message.ts:158

## Methods

### checkForSend

- checkForSend(): EngineError

  检查是否可以发送

  #### Returns EngineError

  是否可以发送，EngineError.Success 代表可以发送；否则代表消息数据有问题无法发送出去

  - Defined in message/Message.ts:191

### checkForSendMedia

- checkForSendMedia(): EngineError

  检查媒体消息是否可以发送

  #### Returns EngineError

  是否可以发送，EngineError.Success 代表可以发送；否则代表消息数据有问题无法发送出去

  - Defined in message/Message.ts:208

### checkForDestruct

- checkForDestruct(): EngineError

  检查消息是否可以阅后即焚

  #### Returns EngineError

  是否支持

  #### Version

  1.3.0

  - Defined in message/Message.ts:232