消息解析

使用 messageParse() 方法解析原始消息

import { messageParser } from "@relationlabs/im"

const msg: Message

const parsedMsg: ParsedMessage = messageParser(msg)

类型定义

// 消息类型
type MessageType = 'SYS' | 'TEXT' | 'CARD' | 'ANNOUNCEMENT' | 'BATCH_TRANSFER';

// 原始消息结构
type Message = {
    type: MessageType;
    content: string;
    quote?: Message;
}

// 解析后的消息结构
type ParsedMessage = {
    type: MessageType;
    content: string;
    parsedContent?: ParsedContent;
    quote?: Message;
    unidentified?: boolean | undefined;
}

//解析后的消息内容
type ParsedContent = string|JoinGroupMessage|ShareMessage|NormalImageMessage|NFTMessage|MentionMessage

// 邀请加入群组
type JoinGroupMessage = {
    groupId: string;
    groupName: string;
    chatType: 'p2p'|'group'
}

// 收藏分享
type ShareMessage = {
    shareUrl: string;
    shareName: string;
    shareIcon: string;
}

// 普通图片
type NormalImageMessage = {
    imgUrl: string;
    s3Key: string;
}

// NFT
type NFTMessage = {
    imgUrl: string;
    nftChain: string;
}

// 消息引用
type MentionMessage = {
    mentionContent: string;
    mentionPosition: number[];
}

ParsedMessageunidentified 表示是否是当前可识别的消息,parsedContent 表示对原消息文本内容解析后的结果,其余字段原封不动的将原消息结构返回

Last updated