feat(sdk): expose group announcement controls
Add typed client options for pinned, popup, new-member, edit-card, and confirmation behavior. Return typed notice metadata and cover the HTTP parameter mapping.
This commit is contained in:
5 files changed
+71
-8
No files matched your search
@@ -326,9 +326,13 @@ export abstract class SnowLumaApiClient {
|
||||
|
||||
sendGroupNotice(groupId: number, content: string, options: RequestOptions & {
|
||||
image?: string;
|
||||
pinned?: number;
|
||||
type?: number;
|
||||
confirmRequired?: number;
|
||||
pinned?: 0 | 1;
|
||||
type?: 1 | 20;
|
||||
sendToNewMembers?: boolean;
|
||||
isShowEditCard?: 0 | 1;
|
||||
/** QQ's raw inverted field: 0=show popup, 1=do not show popup. */
|
||||
tipWindowType?: 0 | 1;
|
||||
confirmRequired?: 0 | 1;
|
||||
} = {}) {
|
||||
return this.call('_send_group_notice', {
|
||||
group_id: groupId,
|
||||
@@ -336,6 +340,9 @@ export abstract class SnowLumaApiClient {
|
||||
image: options.image,
|
||||
pinned: options.pinned,
|
||||
type: options.type,
|
||||
send_to_new_members: options.sendToNewMembers,
|
||||
is_show_edit_card: options.isShowEditCard,
|
||||
tip_window_type: options.tipWindowType,
|
||||
confirm_required: options.confirmRequired,
|
||||
}, options);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ import type {
|
||||
GroupFileSystemInfo,
|
||||
GroupFileUrl,
|
||||
GroupMessageHistory,
|
||||
GroupNoticeInfo,
|
||||
LoginInfo,
|
||||
MediaInfo,
|
||||
OnlineClientsInfo,
|
||||
@@ -163,7 +164,7 @@ export interface SnowLumaActionMap {
|
||||
ocr_image: { params: JsonObject; data: JsonValue };
|
||||
'.ocr_image': { params: JsonObject; data: JsonValue };
|
||||
_send_group_notice: { params: GroupNoticeParams; data: EmptyData };
|
||||
_get_group_notice: { params: GroupIdParams; data: JsonArray };
|
||||
_get_group_notice: { params: GroupIdParams; data: GroupNoticeInfo[] };
|
||||
_del_group_notice: { params: JsonObject; data: EmptyData };
|
||||
upload_forward_msg: { params: ForwardMessageParams; data: UploadForwardResult };
|
||||
upload_foward_msg: { params: ForwardMessageParams; data: UploadForwardResult };
|
||||
|
||||
@@ -217,9 +217,14 @@ export interface MarkMsgAsReadParams extends JsonObject {
|
||||
export interface GroupNoticeParams extends GroupIdParams {
|
||||
content: string;
|
||||
image?: string;
|
||||
pinned?: number;
|
||||
type?: number;
|
||||
confirm_required?: number;
|
||||
pinned?: 0 | 1;
|
||||
/** Compatibility field: 1=regular announcement, 20=new-member announcement. */
|
||||
type?: 1 | 20;
|
||||
send_to_new_members?: boolean;
|
||||
is_show_edit_card?: 0 | 1;
|
||||
/** QQ's raw inverted field: 0=show popup, 1=do not show popup. */
|
||||
tip_window_type?: 0 | 1;
|
||||
confirm_required?: 0 | 1;
|
||||
}
|
||||
|
||||
export interface ForwardPreviewParams {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { JsonArray, JsonObject } from './json';
|
||||
import type { JsonArray, JsonObject, JsonValue } from './json';
|
||||
|
||||
export interface SendMessageResult {
|
||||
message_id: number;
|
||||
@@ -60,6 +60,23 @@ export interface FriendMessageHistory {
|
||||
messages: JsonObject[];
|
||||
}
|
||||
|
||||
export interface GroupNoticeInfo {
|
||||
notice_id: string;
|
||||
sender_id: number;
|
||||
publish_time: number;
|
||||
message: {
|
||||
text: string;
|
||||
image: Array<{ id: string; height: number; width: number }>;
|
||||
images: Array<{ id: string; height: number; width: number }>;
|
||||
};
|
||||
settings: JsonValue;
|
||||
read_num: number;
|
||||
/** Server response type; regular announcements are commonly returned as 6. */
|
||||
type: number;
|
||||
pinned: number;
|
||||
send_to_new_members: boolean;
|
||||
}
|
||||
|
||||
export interface CategorizedFriend {
|
||||
user_id: number;
|
||||
nickname: string;
|
||||
|
||||
@@ -7,6 +7,39 @@ import {
|
||||
} from '../src';
|
||||
|
||||
describe('SnowLumaHttpClient', () => {
|
||||
it('maps group-announcement options to their OneBot field names', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
||||
status: 'ok',
|
||||
retcode: 0,
|
||||
data: null,
|
||||
})));
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
|
||||
await client.sendGroupNotice(941657197, 'welcome', {
|
||||
pinned: 1,
|
||||
type: 20,
|
||||
sendToNewMembers: true,
|
||||
isShowEditCard: 0,
|
||||
tipWindowType: 0,
|
||||
confirmRequired: 0,
|
||||
});
|
||||
|
||||
const init = fetchImpl.mock.calls[0]![1] as RequestInit;
|
||||
expect(JSON.parse(init.body as string)).toEqual({
|
||||
action: '_send_group_notice',
|
||||
params: {
|
||||
group_id: 941657197,
|
||||
content: 'welcome',
|
||||
pinned: 1,
|
||||
type: 20,
|
||||
send_to_new_members: true,
|
||||
is_show_edit_card: 0,
|
||||
tip_window_type: 0,
|
||||
confirm_required: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('throws SnowLumaAuthError for auth retcodes', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
||||
status: 'failed',
|
||||
|
||||
Reference in new issue
Block a user