@perk-net/perk-pushplus-sdk 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perk-net/perk-pushplus-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "pushplus(推送加) 官方接口 JavaScript/TypeScript SDK,可在 Node.js 与浏览器中使用",
5
5
  "keywords": [
6
6
  "pushplus",
@@ -0,0 +1,75 @@
1
+ import { AccessKeyManager } from '../access-key-manager';
2
+ import { ResolvedPushPlusConfig } from '../config';
3
+ import { HttpRequester } from '../http';
4
+ import {
5
+ PageQuery,
6
+ PageResult,
7
+ QqBotBindInfo,
8
+ QqBotBindLink,
9
+ QqBotItem,
10
+ QqBotSaveRequest,
11
+ QqGroupItem,
12
+ } from '../models';
13
+ import { OpenAbstractApi } from './open-base';
14
+
15
+ /** 发送到 QQ 群,目前渠道配置仅支持该类型。 */
16
+ const SEND_TYPE_QQ_GROUP = 2;
17
+
18
+ /**
19
+ * 开放接口 - QQ 机器人(文档「九. QQ机器人接口」)。
20
+ */
21
+ export class QqBotApi extends OpenAbstractApi {
22
+ constructor(config: ResolvedPushPlusConfig, http: HttpRequester, mgr: AccessKeyManager) {
23
+ super(config, http, mgr);
24
+ }
25
+
26
+ /** 1. 获取绑定链接与绑定码;refresh 为 true 时旧绑定码失效并重新生成。 */
27
+ getBindLink(refresh = false): Promise<QqBotBindLink> {
28
+ const path = refresh
29
+ ? this.appendQuery('/api/open/qqBot/getBindLink', { refresh: true })
30
+ : '/api/open/qqBot/getBindLink';
31
+ return this.executeOpen<QqBotBindLink>('GET', path);
32
+ }
33
+
34
+ /** 2. 查询绑定状态。 */
35
+ botInfo(): Promise<QqBotBindInfo> {
36
+ return this.executeOpen<QqBotBindInfo>('GET', '/api/open/qqBot/botInfo');
37
+ }
38
+
39
+ /** 3. 解绑 QQ 机器人。 */
40
+ async unbind(): Promise<void> {
41
+ await this.executeOpen<unknown>('GET', '/api/open/qqBot/unbind');
42
+ }
43
+
44
+ /** 4. 获取机器人已加入的 QQ 群列表。 */
45
+ async groupList(): Promise<QqGroupItem[]> {
46
+ return (await this.executeOpen<QqGroupItem[]>('GET', '/api/open/qqBot/groupList')) ?? [];
47
+ }
48
+
49
+ /** 5. 获取 QQ 机器人渠道配置列表。 */
50
+ list(q?: PageQuery): Promise<PageResult<QqBotItem>> {
51
+ return this.executeOpen<PageResult<QqBotItem>>('POST', '/api/open/qqBot/list', q ?? {});
52
+ }
53
+
54
+ /** 6. 新增渠道配置,用于把消息发送到指定 QQ 群;发给自己无需创建配置。 */
55
+ async add(req: QqBotSaveRequest): Promise<void> {
56
+ await this.executeOpen<unknown>('POST', '/api/open/qqBot/add', withDefaultSendType(req));
57
+ }
58
+
59
+ /** 7. 修改渠道配置;配置编码不可修改。 */
60
+ async edit(req: QqBotSaveRequest): Promise<void> {
61
+ await this.executeOpen<unknown>('POST', '/api/open/qqBot/edit', withDefaultSendType(req));
62
+ }
63
+
64
+ /** 8. 删除渠道配置。 */
65
+ async delete(id: number): Promise<void> {
66
+ await this.executeOpen<unknown>(
67
+ 'DELETE',
68
+ this.appendQuery('/api/open/qqBot/delete', { id }),
69
+ );
70
+ }
71
+ }
72
+
73
+ function withDefaultSendType(req: QqBotSaveRequest): QqBotSaveRequest {
74
+ return { ...req, sendType: req.sendType ?? SEND_TYPE_QQ_GROUP };
75
+ }
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import { MessageApi } from './api/message-api';
11
11
  import { MessageTokenApi } from './api/message-token-api';
12
12
  import { OpenMessageApi } from './api/open-message-api';
13
13
  import { PreApi } from './api/pre-api';
14
+ import { QqBotApi } from './api/qqbot-api';
14
15
  import { SettingApi } from './api/setting-api';
15
16
  import { TopicApi } from './api/topic-api';
16
17
  import { TopicUserApi } from './api/topic-user-api';
@@ -67,6 +68,7 @@ export class PushPlusClient {
67
68
  readonly webhook: WebhookApi;
68
69
  readonly channel: ChannelApi;
69
70
  readonly clawBot: ClawBotApi;
71
+ readonly qqBot: QqBotApi;
70
72
  readonly setting: SettingApi;
71
73
  readonly pre: PreApi;
72
74
  readonly image: ImageApi;
@@ -92,6 +94,7 @@ export class PushPlusClient {
92
94
  this.webhook = new WebhookApi(this.config, this.httpRequester, this.accessKeyManager);
93
95
  this.channel = new ChannelApi(this.config, this.httpRequester, this.accessKeyManager);
94
96
  this.clawBot = new ClawBotApi(this.config, this.httpRequester, this.accessKeyManager);
97
+ this.qqBot = new QqBotApi(this.config, this.httpRequester, this.accessKeyManager);
95
98
  this.setting = new SettingApi(this.config, this.httpRequester, this.accessKeyManager);
96
99
  this.pre = new PreApi(this.config, this.httpRequester, this.accessKeyManager);
97
100
  this.image = new ImageApi(this.config, this.httpRequester, this.accessKeyManager);
package/src/enums.ts CHANGED
@@ -22,6 +22,8 @@ export enum Channel {
22
22
  APP = 'app',
23
23
  /** 微信 ClawBot。 */
24
24
  CLAWBOT = 'clawbot',
25
+ /** QQ 机器人;不带 option 发给自己,option 填配置编码则发到对应 QQ 群。 */
26
+ QQ = 'qq',
25
27
  }
26
28
 
27
29
  /**
package/src/index.ts CHANGED
@@ -88,6 +88,12 @@ export type {
88
88
  ClawBotInfo,
89
89
  ClawBotMessage,
90
90
  ClawBotQrCode,
91
+ QqBotBindLink,
92
+ QqBotBindInfo,
93
+ QqBotInfo,
94
+ QqBotItem,
95
+ QqBotSaveRequest,
96
+ QqGroupItem,
91
97
  MpItem,
92
98
  CpItem,
93
99
  MailItem,
@@ -142,6 +148,7 @@ export { FriendApi } from './api/friend-api';
142
148
  export { WebhookApi } from './api/webhook-api';
143
149
  export { ChannelApi } from './api/channel-api';
144
150
  export { ClawBotApi } from './api/clawbot-api';
151
+ export { QqBotApi } from './api/qqbot-api';
145
152
  export { SettingApi } from './api/setting-api';
146
153
  export { PreApi } from './api/pre-api';
147
154
  export {
package/src/models.ts CHANGED
@@ -270,6 +270,7 @@ export interface SendCount {
270
270
  cpSendCount?: number;
271
271
  webhookSendCount?: number;
272
272
  mailSendCount?: number;
273
+ qqBotSendCount?: number;
273
274
  }
274
275
 
275
276
  export interface UserLimitTime {
@@ -518,6 +519,82 @@ export interface ClawBotQrCode {
518
519
  qrcode?: string;
519
520
  }
520
521
 
522
+ /* ============================== 开放接口 - QQ 机器人 ============================== */
523
+
524
+ export interface QqBotBindLink {
525
+ /** 带参分享链接,用于生成扫码二维码;已绑定用户再次获取时可能为空。 */
526
+ url?: string;
527
+ /** 绑定码。已是好友时扫码收不到加好友事件,需私聊发送该码;认领 QQ 群也用此码。 */
528
+ bindCode?: string;
529
+ /** 有效期秒数,默认 300。 */
530
+ expireSeconds?: number;
531
+ /** 为当前用户分配的官方机器人 appId。 */
532
+ botAppId?: string;
533
+ botName?: string;
534
+ botAvatar?: string;
535
+ }
536
+
537
+ export interface QqBotInfo {
538
+ botId?: string;
539
+ username?: string;
540
+ avatar?: string;
541
+ appId?: string;
542
+ /** 官方分享链接,可用于拉机器人进群。 */
543
+ shareUrl?: string;
544
+ }
545
+
546
+ export interface QqBotBindInfo {
547
+ /** 0-未绑定,1-已绑定。 */
548
+ isBind?: number;
549
+ /** 1-可接收,0-用户已关闭单聊接收。 */
550
+ receiveStatus?: number;
551
+ createTime?: string;
552
+ botInfo?: QqBotInfo;
553
+ }
554
+
555
+ export interface QqGroupItem {
556
+ /** 群编号;新增渠道配置时作为 qqGroupId 使用。 */
557
+ id?: number;
558
+ groupOpenId?: string;
559
+ groupRemark?: string;
560
+ /** 1-在群,2-群消息接收关闭。 */
561
+ status?: number;
562
+ /** 群名称,接口未授权时为空。 */
563
+ groupName?: string;
564
+ groupFingerMemo?: string;
565
+ groupClassText?: string;
566
+ groupTags?: string[];
567
+ groupMemberNum?: number;
568
+ createTime?: string;
569
+ }
570
+
571
+ export interface QqBotItem {
572
+ id?: number;
573
+ qqName?: string;
574
+ /** 配置编码;发送消息时作为 option 传入。 */
575
+ qqCode?: string;
576
+ /** 2-发到 QQ 群。 */
577
+ sendType?: number;
578
+ qqGroupId?: number;
579
+ groupRemark?: string;
580
+ groupOpenId?: string;
581
+ groupName?: string;
582
+ updateTime?: string;
583
+ }
584
+
585
+ export interface QqBotSaveRequest {
586
+ /** 修改时必填。 */
587
+ id?: number;
588
+ /** 配置名称,必填,最多 64 个字符。 */
589
+ qqName?: string;
590
+ /** 配置编码,新增必填;仅支持字母、数字、下划线和中划线,创建后不可修改。 */
591
+ qqCode?: string;
592
+ /** 发送类型;留空时 SDK 自动填 2(发到 QQ 群)。 */
593
+ sendType?: number;
594
+ /** QQ 群编号,必填,取自 groupList 返回的 id。 */
595
+ qqGroupId?: number;
596
+ }
597
+
521
598
  /* ============================== 开放接口 - channel ============================== */
522
599
 
523
600
  export interface MpItem {