feat(onebot): add group share links
Retrieve group invitation links with compatible request defaults and explicit error reporting. Add a typed SDK helper and discoverable action documentation. Fixes #521
This commit is contained in:
14 files changed
+587
-2
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Add `getGroupShareLink()` and typed `get_group_share_link` support for group invitation links.
|
||||
- Breaking: require Node.js 24 or newer.
|
||||
- Add `CustomReplySegment` and `message.customReply()` for inline quote previews inside merged-forward nodes.
|
||||
- Expose optional inline content and quote metadata on received `ReplySegment` values.
|
||||
|
||||
@@ -62,6 +62,8 @@ const bot = new SnowLumaHttpClient({
|
||||
|
||||
await bot.sendPrivateMessage(10001, text('pong'));
|
||||
|
||||
const { url } = await bot.getGroupShareLink(123456);
|
||||
|
||||
await bot.sendGroupMessage(123456, [
|
||||
message.text('Hello'),
|
||||
message.at('all'),
|
||||
|
||||
@@ -153,6 +153,26 @@ export abstract class SnowLumaApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
getGroupShareLink(
|
||||
groupId: number,
|
||||
options?: RequestOptions & {
|
||||
needShortUrl?: boolean;
|
||||
srcId?: number;
|
||||
additionalParam?: string;
|
||||
},
|
||||
) {
|
||||
return this.call(
|
||||
'get_group_share_link',
|
||||
{
|
||||
group_id: groupId,
|
||||
need_short_url: options?.needShortUrl,
|
||||
src_id: options?.srcId,
|
||||
additional_param: options?.additionalParam,
|
||||
},
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
getGroupMemberInfo(
|
||||
groupId: number,
|
||||
userId: number,
|
||||
|
||||
@@ -21,6 +21,7 @@ import type {
|
||||
GetGroupHonorInfoParams,
|
||||
GetGroupSystemMsgParams,
|
||||
GetGroupInfoParams,
|
||||
GetGroupShareLinkParams,
|
||||
GetGroupListParams,
|
||||
GetGroupMemberInfoParams,
|
||||
GetGroupMemberListParams,
|
||||
@@ -134,6 +135,7 @@ export interface SnowLumaActionMap {
|
||||
delete_friend: { params: DeleteFriendParams; data: EmptyData };
|
||||
get_group_list: { params: GetGroupListParams; data: JsonObject[] };
|
||||
get_group_info: { params: GetGroupInfoParams; data: JsonObject };
|
||||
get_group_share_link: { params: GetGroupShareLinkParams; data: { url: string } };
|
||||
get_group_member_list: { params: GetGroupMemberListParams; data: JsonObject[] };
|
||||
get_group_member_info: { params: GetGroupMemberInfoParams; data: JsonObject };
|
||||
get_group_honor_info: { params: GetGroupHonorInfoParams; data: JsonValue };
|
||||
|
||||
@@ -52,6 +52,12 @@ export interface GetGroupInfoParams extends GroupIdParams {
|
||||
no_cache?: boolean;
|
||||
}
|
||||
|
||||
export interface GetGroupShareLinkParams extends GroupIdParams {
|
||||
need_short_url?: boolean;
|
||||
src_id?: number;
|
||||
additional_param?: string;
|
||||
}
|
||||
|
||||
export interface GetGroupMemberListParams extends GroupIdParams {
|
||||
no_cache?: boolean;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,41 @@ import {
|
||||
} from '../src';
|
||||
|
||||
describe('SnowLumaHttpClient', () => {
|
||||
it('requests group share links with default and explicit options', async () => {
|
||||
const url = 'https://qm.qq.com/q/example';
|
||||
const fetchImpl = vi
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
async () =>
|
||||
new Response(JSON.stringify({ status: 'ok', retcode: 0, data: { url } })),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
|
||||
await expect(client.getGroupShareLink(12345)).resolves.toEqual({ url });
|
||||
await expect(
|
||||
client.getGroupShareLink(12345, {
|
||||
needShortUrl: false,
|
||||
srcId: 0,
|
||||
additionalParam: 'source=二维码',
|
||||
}),
|
||||
).resolves.toEqual({ url });
|
||||
|
||||
expect(
|
||||
fetchImpl.mock.calls.map((call) => JSON.parse((call[1] as RequestInit).body as string)),
|
||||
).toEqual([
|
||||
{ action: 'get_group_share_link', params: { group_id: 12345 } },
|
||||
{
|
||||
action: 'get_group_share_link',
|
||||
params: {
|
||||
group_id: 12345,
|
||||
need_short_url: false,
|
||||
src_id: 0,
|
||||
additional_param: 'source=二维码',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('maps extended group-info refresh options to OneBot field names', async () => {
|
||||
const fetchImpl = vi.fn().mockImplementation(
|
||||
async () =>
|
||||
|
||||
Reference in new issue
Block a user