Files
SnowLuma/packages/protocol/src/services/qidian/fetch-corp-info.ts
T
makotowu c1a0091143 feat(onebot): expose qidian enterprise name on stranger info
When a stranger is a qidian account, attach the enterprise name from the corp data card. Non-qidian accounts keep an empty name.

Refs #404
2026-08-26 23:31:15 +08:00

53 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import type { QidianCorpInfoRequest, QidianCorpInfoResponse } from '@snowluma/proto-defs/qidian-corp';
// 企点企业资料卡(trpc.basic.corp.Datacard.SsoCorpInfo)。
// 请求体为 protobuf field1 = 目标账号 UIN(varint)
// 返回企业名称等资料卡字段(来源见 SnowLuma issue #404 讨论)。
export const QIDIAN_CORP_INFO_CMD = 'trpc.basic.corp.Datacard.SsoCorpInfo';
export interface QidianCorpInfo {
name: string;
intro: string;
website: string;
slogan: string;
address: string;
phone: string;
email: string;
}
export interface RawSender {
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
}
/**
* Fetch the qidian enterprise data-card for a qidian account UIN.
* Returns null when the account is not a qidian corp user or the server
* returns no corp info. Best-effort by design — callers must NOT fail the
* whole profile read if this lookup throws / returns null.
*/
export async function fetchQidianCorpInfo(
sender: RawSender,
uin: number,
timeoutMs?: number,
): Promise<QidianCorpInfo | null> {
const req = protobuf_encode<QidianCorpInfoRequest>({ uin });
const result = await sender.sendRawPacket(QIDIAN_CORP_INFO_CMD, req, timeoutMs);
if (!result.success || !result.gotResponse || !result.responseData || result.responseData.length === 0) {
return null;
}
const decoded = protobuf_decode<QidianCorpInfoResponse>(result.responseData);
const name = decoded?.corpName ?? '';
if (!name) return null;
return {
name,
intro: decoded?.intro ?? '',
website: decoded?.website ?? '',
slogan: decoded?.slogan ?? '',
address: decoded?.address ?? '',
phone: decoded?.phone ?? '',
email: decoded?.email ?? '',
};
}