feat(onebot): fetch_ptt_text via async 0x210/61 result push (#79)
Live testing showed the voice-to-text text is delivered by an async push
(Event 0x210 subType 61), not the request response — so the previous
poll-by-resend never got it. Captured a real push and decoded its protobuf:
outer { f1, f2:item }; the item echoes the request msgId at field 1 (the
correlation key) and the recognised text at field 8.
- proto-defs: PttTransPush / PttTransPushItem (live-verified).
- protocol: Event0x210SubType.PttTransResult = 61 + decoder → internal
`ptt_trans_result` event { msgId, text } (replaces the temp hex dump).
- core: translatePttToText now sends ONE trigger and returns the inline text
only if present (already-transcribed); empty = pending.
- onebot: ptt-trans-waiter (keyed by selfUin:msgId), event-pipeline subscribes
`ptt_trans_result` to resolve it; fetch_ptt_text registers the waiter,
fires the trigger, and awaits the push (20s timeout).
Decoded one real push as text "12311123。" end to end.
This commit is contained in:
8 files changed
+164
-54
No files matched your search
@@ -263,6 +263,18 @@ export interface GroupMsgEmojiLikeEvent extends QQEvent {
|
||||
isAdd: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Async voice-to-text result, pushed by the server (Event 0x210 subType 61)
|
||||
* after a `pttTrans.Trans{C2C,Group}PttReq`. `msgId` echoes the request's
|
||||
* msgId — the correlation key a pending `fetch_ptt_text` waits on. Internal
|
||||
* (not surfaced to OneBot clients).
|
||||
*/
|
||||
export interface PttTransResultEvent extends QQEvent {
|
||||
kind: 'ptt_trans_result';
|
||||
msgId: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export type QQEventVariant =
|
||||
| FriendMessage
|
||||
| GroupMessage
|
||||
@@ -280,4 +292,5 @@ export type QQEventVariant =
|
||||
| GroupEssenceEvent
|
||||
| GroupFileUploadEvent
|
||||
| FriendAddEvent
|
||||
| GroupMsgEmojiLikeEvent;
|
||||
| GroupMsgEmojiLikeEvent
|
||||
| PttTransResultEvent;
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
GeneralGrayTipInfo,
|
||||
NewFriend,
|
||||
} from '@snowluma/proto-defs/notify';
|
||||
import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans';
|
||||
import type { MsgPushContext } from '../context';
|
||||
import { Event0x210SubType } from '../enums';
|
||||
import {
|
||||
@@ -28,6 +29,7 @@ const unknownLog = createLogger('MsgPush.Unknown');
|
||||
export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
|
||||
switch (ctx.head.subType as Event0x210SubType) {
|
||||
case Event0x210SubType.FriendRequestNotice: return decodeFriendRequest(ctx);
|
||||
case Event0x210SubType.PttTransResult: return decodePttTransResult(ctx);
|
||||
// 138 (other-recalled) and 139 (self-recalled) share the same
|
||||
// FriendRecall wire shape; the helper picks the right uid side
|
||||
// based on the subType.
|
||||
@@ -54,24 +56,24 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
|
||||
// until someone maps the schema.
|
||||
return [];
|
||||
}
|
||||
if (ctx.head.subType === 61) {
|
||||
// TEMP capture aid (#79 语音转文字): subType 61 (0x3D) is QQ-NT's ptt
|
||||
// voice-to-text result push. Its protobuf wire shape is registered
|
||||
// dynamically by the ptt-trans subsystem (no static sys_msg_0x210_0x3d
|
||||
// handler), so we dump the raw body once to decode it from ground truth.
|
||||
// Replace with a proper decoder + correlation once mapped.
|
||||
unknownLog.info(
|
||||
'Event0x210 ptt-trans(subType=61) fromUin=%s len=%d hex=%s',
|
||||
String(ctx.fromUin ?? ''),
|
||||
ctx.content?.length ?? 0,
|
||||
ctx.content ? Buffer.from(ctx.content).toString('hex') : '',
|
||||
);
|
||||
return [];
|
||||
}
|
||||
unknownLog.debug('Event0x210 unknown subType=%d', ctx.head.subType);
|
||||
return [];
|
||||
};
|
||||
|
||||
// Voice-to-text async result push. Wire shape (live-verified):
|
||||
// { f1: uint, f2: { f1 = msgId (echoes the request), f8 = text, ... } }
|
||||
// `msgId` is the correlation key a pending fetch_ptt_text waits on; we surface
|
||||
// it + the recognised text as an internal `ptt_trans_result` event.
|
||||
function decodePttTransResult(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const push = protobuf_decode<PttTransPush>(ctx.content);
|
||||
const item = push?.item;
|
||||
if (!item) return [];
|
||||
const msgId = Number(item.msgId ?? 0n);
|
||||
const text = item.text ?? '';
|
||||
if (!msgId || !text) return [];
|
||||
return [{ kind: 'ptt_trans_result', time: ctx.head.timestamp, selfUin: ctx.selfUin, msgId, text }];
|
||||
}
|
||||
|
||||
function decodeFriendRequest(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const request = protobuf_decode<FriendRequest>(ctx.content);
|
||||
if (!request?.info) return [];
|
||||
|
||||
@@ -36,6 +36,14 @@ export enum Event0x2DCSubType {
|
||||
|
||||
export enum Event0x210SubType {
|
||||
FriendRequestNotice = 35,
|
||||
/**
|
||||
* Voice-to-text (语音转文字) async result push, fired after a
|
||||
* `pttTrans.Trans{C2C,Group}PttReq` once the server finishes transcribing.
|
||||
* Live-verified body: `{ f1:uint, f2:{ f1=msgId, f8=text, ... } }`. There's
|
||||
* no static sys_msg_0x210_0x3d handler — the ptt-trans subsystem registers
|
||||
* it dynamically; we decode it into an internal `ptt_trans_result` event.
|
||||
*/
|
||||
PttTransResult = 61,
|
||||
/**
|
||||
* Outgoing friend-message recall — bot recalled its own message that
|
||||
* was sent to a friend. Same `FriendRecall` wire shape as 138; the
|
||||
|
||||
Reference in new issue
Block a user