Skip to content

Commit 42f21f4

Browse files
Joy-Wangjoyqwang
andauthored
SDK接口更新 (#72)
* feat: 添加语音子频道在线成员查询接口 * feat: 新增机器人上麦|下麦接口 Co-authored-by: joyqwang <[email protected]>
1 parent 41e2861 commit 42f21f4

File tree

10 files changed

+132
-4
lines changed

10 files changed

+132
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [2.9.4](https://github.com/tencent-connect/bot-node-sdk/compare/v2.9.3...v2.9.4) (2022-05-18)
6+
7+
8+
### Features
9+
10+
* 事件分发添加事件ID ([dd9800e](https://github.com/tencent-connect/bot-node-sdk/commit/dd9800ec1cc8e0f305d70baab60dc31bf5fc9d91))
11+
* 修复依赖版本问题 ([1be18a3](https://github.com/tencent-connect/bot-node-sdk/commit/1be18a300ec6241b08dcdf56ae7560a0f5863cb2))
12+
* 新增机器人获取表情表态成员列表接口 ([b4739d7](https://github.com/tencent-connect/bot-node-sdk/commit/b4739d719db4d860d2d96fb5f7a6476fc4788053))
13+
514
### [2.9.3](https://github.com/tencent-connect/bot-node-sdk/compare/v2.9.1...v2.9.3) (2022-05-12)
615

716

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qq-guild-bot",
3-
"version": "2.9.3",
3+
"version": "2.9.4",
44
"description": "QQ频道机器人NodeSDK",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/"

src/openapi/v1/audio.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,28 @@ export default class Audio implements AudioAPI {
2121
};
2222
return this.request<AudioControl>(options);
2323
}
24+
// 机器人上麦
25+
botOnMic(channelID: string): Promise<RestyResponse<{}>> {
26+
const options = {
27+
method: 'PUT' as const,
28+
url: getURL('botMic'),
29+
rest: {
30+
channelID,
31+
},
32+
data: {},
33+
};
34+
return this.request<{}>(options);
35+
}
36+
// 机器人下麦
37+
botOffMic(channelID: string): Promise<RestyResponse<{}>> {
38+
const options = {
39+
method: 'DELETE' as const,
40+
url: getURL('botMic'),
41+
rest: {
42+
channelID,
43+
},
44+
data: {},
45+
};
46+
return this.request<{}>(options);
47+
}
2448
}

src/openapi/v1/guild.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Config, OpenAPIRequest, GuildAPI, GuildMembersPager, IGuild, IMember } from '@src/types';
1+
import { Config, OpenAPIRequest, GuildAPI, GuildMembersPager, IGuild, IMember, IVoiceMember } from '@src/types';
22
import { RestyResponse } from 'resty-client';
33
import { getURL } from './resource';
44

@@ -57,4 +57,15 @@ export default class Guild implements GuildAPI {
5757
};
5858
return this.request(options);
5959
}
60+
// 语音子频道在线成员列表
61+
public guildVoiceMembers(channelID: string): Promise<RestyResponse<IVoiceMember[]>> {
62+
const options = {
63+
method: 'GET' as const,
64+
url: getURL('guildVoiceMembersURI'),
65+
rest: {
66+
channelID,
67+
},
68+
};
69+
return this.request<IVoiceMember[]>(options);
70+
}
6071
}

src/openapi/v1/resource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ const apiMap = {
3434
pinsMessageIdURI: '/channels/:channelID/pins/:messageID',
3535
pinsMessageURI: '/channels/:channelID/pins',
3636
interactionURI: '/interactions/:interactionID',
37+
guildVoiceMembersURI: '/channels/:channelID/voice/members', // 语音子频道在线成员车查询
38+
botMic: '/channels/:channelID/mic', // 机器人上麦|下麦
3739
};
3840
export const getURL = (endpoint: keyof typeof apiMap) => apiMap[endpoint];

src/types/openapi/v1/audio.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { RestyResponse } from 'resty-client';
33
// ============= Audio 音频接口 =============
44
export interface AudioAPI {
55
postAudio: (channelID: string, value: AudioControl) => Promise<RestyResponse<AudioControl>>;
6+
botOnMic: (channelID: string) => Promise<RestyResponse<{}>>;
7+
botOffMic: (channelID: string) => Promise<RestyResponse<{}>>;
68
}
79

810
// 语音对象-参数

src/types/openapi/v1/guild.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface GuildAPI {
1010
guildMember: (guildID: string, userID: string) => Promise<RestyResponse<IMember>>;
1111
guildMembers: (guildID: string, pager?: GuildMembersPager) => Promise<RestyResponse<IMember[]>>;
1212
deleteGuildMember: (guildID: string, userID: string) => Promise<RestyResponse<any>>;
13+
guildVoiceMembers: (channelID: string) => Promise<RestyResponse<IVoiceMember[]>>;
1314
}
1415

1516
// 频道对象(Guild)
@@ -39,6 +40,14 @@ export interface IMember {
3940
mute: boolean;
4041
}
4142

43+
// 语音子频道参与语音的Member群成员
44+
export interface IVoiceMember {
45+
user: IUser;
46+
nick: string;
47+
joined_at: string;
48+
mute: boolean;
49+
}
50+
4251
export interface GuildMembersPager {
4352
// 上一次回包中最大的用户ID, 如果是第一次请求填0,默认为0
4453
after: string;

test/openapi/v1/audio.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { client, channelID, REQUEST_SUCCESS_CODE } from '../config';
2+
3+
describe('audio测试', () => {
4+
enum AudioPlayStatus {
5+
START = 0, // 开始播放
6+
PAUSE = 1, // 暂停播放
7+
RESUME = 2, // 继续播放
8+
STOP = 3, // 停止播放
9+
}
10+
test('【 postAudio方法 】=== 开始播放操作', async () => {
11+
const audioControl = {
12+
audioUrl: '',
13+
text: '',
14+
status: AudioPlayStatus.START,
15+
}
16+
const res = await client.audioApi.postAudio(channelID, audioControl);
17+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
18+
});
19+
20+
test('【 postAudio方法 】=== 暂停播放操作', async () => {
21+
const audioControl = {
22+
audioUrl: '',
23+
text: '',
24+
status: AudioPlayStatus.PAUSE,
25+
}
26+
const res = await client.audioApi.postAudio(channelID, audioControl);
27+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
28+
});
29+
30+
test('【 postAudio方法 】=== 继续播放操作', async () => {
31+
const audioControl = {
32+
audioUrl: '',
33+
text: '',
34+
status: AudioPlayStatus.RESUME,
35+
}
36+
const res = await client.audioApi.postAudio(channelID, audioControl);
37+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
38+
});
39+
40+
test('【 postAudio方法 】=== 停止播放操作', async () => {
41+
const audioControl = {
42+
audioUrl: '',
43+
text: '',
44+
status: AudioPlayStatus.STOP,
45+
}
46+
const res = await client.audioApi.postAudio(channelID, audioControl);
47+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
48+
});
49+
50+
test('【 botOnMic方法 】=== 机器人上麦', async () => {
51+
const res = await client.audioApi.botOnMic(channelID);
52+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
53+
});
54+
55+
test('【 botOffMic方法 】=== 机器人下麦', async () => {
56+
const res = await client.audioApi.botOffMic(channelID);
57+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
58+
});
59+
});

test/openapi/v1/guild.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { client, guildID, userID, REQUEST_SUCCESS_CODE, REQUEST_SUCCESS_CODE_WITH_NO_CONTENT } from '../config';
1+
import {
2+
client,
3+
guildID,
4+
channelID,
5+
userID,
6+
REQUEST_SUCCESS_CODE,
7+
REQUEST_SUCCESS_CODE_WITH_NO_CONTENT } from '../config';
28

39
describe('guild测试', () => {
410
test('【 guild方法 】=== 获取频道信息', async () => {
@@ -31,4 +37,10 @@ describe('guild测试', () => {
3137
const res = await client.guildApi.deleteGuildMember(guildID, testUserId);
3238
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE_WITH_NO_CONTENT);
3339
});
40+
41+
test('【 guildVoiceMembers 】=== 语音子频道内参与语音的频道成员列表', async () => {
42+
const res = await client.guildApi.guildVoiceMembers(channelID);
43+
expect(res?.status).toStrictEqual(REQUEST_SUCCESS_CODE);
44+
expect(Array.isArray(res?.data)).toStrictEqual(true);
45+
});
3446
});

0 commit comments

Comments
 (0)