C2C单聊 QGFriend
QGFriend 表示 QQ 机器人中的一个 C2C 单聊目标。
和“传统好友列表”不同, QGFriend 更接近于 “来自事件上下文的可回复目标”:
它通常从
C2C消息事件中得到目前没有对应的“好友列表查询”能力
只能稳定拿到
openid
所以它通常表现为:
id可用于标识此单聊目标name始终是空字符串,avatar始终是null
获取途径
处理 C2C 单聊相关事件时, 通常可以从事件的 author、 content 或目标对象链路中拿到 QGFriend。
要看这个场景的事件本身, 可继续阅读:
可用能力
QGFriend 当前主要有两类能力:
- 发送消息
继承
Contact的发送能力,可直接发送String、Message、MessageContent。- 上传媒体
通过
uploadMedia(...)上传媒体,得到QGMedia。QGMedia本身是一个消息元素,可用于后续的C2C/ QQ 群消息发送。
发送消息
suspend fun reply(friend: QGFriend) {
friend.send("你好,这是一条 C2C 单聊消息")
}
QGFriend friend = ...;
friend.sendAsync("你好,这是一条 C2C 单聊消息")
.thenAccept(receipt -> { });
QGFriend friend = ...;
var receipt = friend.sendBlocking("你好,这是一条 C2C 单聊消息");
QGFriend friend = ...;
friend.sendReserve("你好,这是一条 C2C 单聊消息")
.transform(SuspendReserves.mono())
.subscribe(receipt -> { });
上传媒体
目前公开了两组上传函数:
uploadMedia(url: String, type: Int)uploadMedia(resource: Resource, type: Int)(4.1.1起)
其中 type 与开放平台媒体类型一致:
1: 图片2: 视频3: 语音4: 文件(当前平台侧仍有限制)
suspend fun upload(friend: QGFriend) {
val media = friend.uploadMedia(
url = "https://example.com/example.png",
type = 1
)
// media: QGMedia
}
QGFriend friend = ...;
friend.uploadMediaAsync("https://example.com/example.png", 1)
.thenAccept(media -> { });
QGFriend friend = ...;
var media = friend.uploadMediaBlocking("https://example.com/example.png", 1);
QGFriend friend = ...;
friend.uploadMediaReserve("https://example.com/example.png", 1)
.transform(SuspendReserves.mono())
.subscribe(media -> { });
14 July 2026