Segments - 消息片段
消息片段是构成消息链的基本单元,每种片段类型代表不同的消息内容。
基类 Segment
所有消息片段的抽象基类。
declare abstract class Segment {
abstract AsString(): string; // 转换为字符串表示
}
文本片段 (TextSegment)
表示纯文本类型的消息片段。
declare class TextSegment extends Segment {
Text: string; // 文本内容
AsString(): string; // 返回原始文本
}
属性
- Text:
string
- 文本内容
方法
- AsString(): 返回未修改的文本字符串
示例:
const textSegment = new TextSegment();
textSegment.Text = "Hello World";
logger.info(textSegment.AsString()); // "Hello World"
@用户片段 (AtSegment)
表示@用户类型的消息片段。
declare class AtSegment extends Segment {
Id: string; // 被@的用户ID
AsString(): string; // 返回"@用户ID"格式
}
属性
- Id:
string
- 被@的用户ID
方法
- AsString(): 生成格式为"@用户ID"的字符串
示例:
const atSegment = new AtSegment();
atSegment.Id = "123456789";
logger.info(atSegment.AsString()); // "@123456789"
图片片段 (ImageSegment)
表示图片类型的消息片段。
declare class ImageSegment extends Segment {
Uri: string; // 图片URI地址
AsString(): string; // 返回"[图片]"
}
属性
- Uri:
string
- 图片资源的URI地址
方法
- AsString(): 生成格式为"[图片]"的字符串
示例:
const imageSegment = new ImageSegment();
imageSegment.Uri = "https://example.com/image.jpg";
logger.info(imageSegment.AsString()); // "[图片]"
表情片段 (FaceSegment)
表示表情类型的消息片段。
declare class FaceSegment extends Segment {
id: string; // 表情ID (注意小写)
AsString(): string; // 返回"[表情ID]"
}
属性
- id:
string
- 表情的唯一标识符(注意属性名为小写)
方法
- AsString(): 生成格式为"[表情ID]"的字符串
示例:
const faceSegment = new FaceSegment();
faceSegment.id = "1";
logger.info(faceSegment.AsString()); // "[1]"
回复片段 (ReplySegment)
表示回复引用类型的消息片段。
declare class ReplySegment extends Segment {
Id: string; // 被回复的消息ID
AsString(): string; // 返回"[回复消息ID]"
}