消息解析
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[];
}Last updated