@karinjs/adapter-qqbot 1.2.9 → 1.2.10
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/config/comment/config.json +3 -0
- package/config/config/config.yaml +53 -0
- package/lib/cli/pr.d.ts +2 -0
- package/lib/cli/pr.js +73 -0
- package/lib/core/adapter/adapter.d.ts +91 -0
- package/lib/core/adapter/adapter.js +144 -0
- package/lib/core/adapter/handler.d.ts +49 -0
- package/lib/core/adapter/handler.js +140 -0
- package/lib/core/adapter/markdown.d.ts +38 -0
- package/lib/core/adapter/markdown.js +220 -0
- package/lib/core/adapter/normal.d.ts +30 -0
- package/lib/core/adapter/normal.js +263 -0
- package/lib/core/api/index.d.ts +167 -0
- package/lib/core/api/index.js +180 -0
- package/lib/core/api/sign.d.ts +22 -0
- package/lib/core/api/sign.js +40 -0
- package/lib/core/api/types.d.ts +236 -0
- package/lib/core/event/conver.d.ts +10 -0
- package/lib/core/event/conver.js +57 -0
- package/lib/core/event/index.d.ts +9 -0
- package/lib/core/event/index.js +98 -0
- package/lib/core/event/message.d.ts +27 -0
- package/lib/core/event/message.js +95 -0
- package/lib/core/event/notice.d.ts +50 -0
- package/lib/core/event/notice.js +133 -0
- package/lib/{types/event.d.ts → core/event/types.d.ts} +255 -14
- package/lib/core/internal/axios.d.ts +25 -0
- package/lib/core/internal/axios.js +46 -0
- package/lib/core/internal/sign.d.ts +22 -0
- package/lib/core/internal/sign.js +40 -0
- package/lib/core/webhook/c2c.d.ts +2 -0
- package/lib/core/webhook/c2c.js +14 -0
- package/lib/core/webhook/http.d.ts +2 -0
- package/lib/core/webhook/http.js +35 -0
- package/lib/core/webhook/index.d.ts +17 -0
- package/lib/core/webhook/index.js +87 -0
- package/lib/core/webhook/ws.d.ts +2 -0
- package/lib/core/webhook/ws.js +79 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.js +5 -7
- package/lib/root.d.ts +5 -0
- package/lib/root.js +9 -0
- package/lib/types/config.d.ts +53 -0
- package/lib/utils/common.d.ts +75 -61
- package/lib/utils/common.js +190 -202
- package/lib/utils/config.d.ts +5 -130
- package/lib/utils/config.js +50 -172
- package/lib/utils/dir.d.ts +1 -5
- package/lib/utils/dir.js +1 -10
- package/lib/utils/index.d.ts +4 -3
- package/lib/utils/index.js +4 -3
- package/package.json +41 -23
- package/config/config.yaml +0 -69
- package/lib/core/api.d.ts +0 -180
- package/lib/core/api.js +0 -454
- package/lib/core/index.d.ts +0 -90
- package/lib/core/index.js +0 -349
- package/lib/core/intents.d.ts +0 -6
- package/lib/core/intents.js +0 -57
- package/lib/core/markdown.d.ts +0 -23
- package/lib/core/markdown.js +0 -265
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -3
- package/lib/types/media.d.ts +0 -100
- package/lib/types/message.d.ts +0 -85
- /package/lib/{types/event.js → core/api/types.js} +0 -0
- /package/lib/{types/media.js → core/event/types.js} +0 -0
- /package/lib/types/{message.js → config.js} +0 -0
package/lib/utils/config.js
CHANGED
|
@@ -1,176 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*/
|
|
42
|
-
updateYaml(filePath, settings) {
|
|
43
|
-
let yaml = new YamlEditor(filePath);
|
|
44
|
-
/** 先添加内容 */
|
|
45
|
-
settings.forEach(({ key, val }) => {
|
|
46
|
-
try {
|
|
47
|
-
if (!yaml.has(key))
|
|
48
|
-
yaml.set(key, val);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger.error(`[common] 更新yaml文件时出错:${error.stack || error.message || error}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
/** 先保存 */
|
|
55
|
-
yaml.save();
|
|
56
|
-
/** 重新解析 再次写入注释 直接写入注释会报错 写入的不是node节点模式 */
|
|
57
|
-
yaml = new YamlEditor(filePath);
|
|
58
|
-
settings.forEach(({ key, comment, type }) => {
|
|
59
|
-
try {
|
|
60
|
-
yaml.comment(key, comment, type);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger.error(`[common] 更新yaml文件时出错:${error.stack || error.message || error}`);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
yaml.save();
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 基本配置
|
|
70
|
-
*/
|
|
71
|
-
get Config() {
|
|
72
|
-
const key = 'change.config';
|
|
73
|
-
const res = this.change.get(key);
|
|
74
|
-
/** 取缓存 */
|
|
75
|
-
if (res)
|
|
76
|
-
return res;
|
|
77
|
-
/** 取配置 */
|
|
78
|
-
const config = this.getYaml('config', 'config', true);
|
|
79
|
-
const defSet = this.getYaml('defSet', 'config', false);
|
|
80
|
-
const data = {
|
|
81
|
-
...defSet,
|
|
82
|
-
...config,
|
|
83
|
-
default: { ...defSet?.default, ...config?.default },
|
|
84
|
-
};
|
|
85
|
-
/** 缓存 */
|
|
86
|
-
this.change.set(key, data);
|
|
87
|
-
return data;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 获取指定Bot配置
|
|
91
|
-
* @param {string} appID - Bot的AppID
|
|
92
|
-
*/
|
|
93
|
-
getBotConfig(appID) {
|
|
94
|
-
if (!appID)
|
|
95
|
-
throw new Error('appID不能为空');
|
|
96
|
-
const key = `change.config.${appID}`;
|
|
97
|
-
const res = this.change.get(key);
|
|
98
|
-
/** 取缓存 */
|
|
99
|
-
if (res)
|
|
100
|
-
return res;
|
|
101
|
-
/** 所有配置 */
|
|
102
|
-
const allCfg = this.Config;
|
|
103
|
-
/** 取不到 */
|
|
104
|
-
if (!allCfg?.accounts?.[appID])
|
|
105
|
-
return null;
|
|
106
|
-
/** 单个账号配置 */
|
|
107
|
-
const botCfg = allCfg.accounts[appID];
|
|
108
|
-
/** 全局默认配置 */
|
|
109
|
-
const defCfg = allCfg.default;
|
|
110
|
-
/** 对regex进行处理 */
|
|
111
|
-
const regex = Array.isArray(botCfg.regex) ? botCfg.regex : defCfg.regex;
|
|
112
|
-
/** 对表达式进行new RegExp处理 */
|
|
113
|
-
const regexData = regex.map(({ reg, rep }) => {
|
|
114
|
-
return {
|
|
115
|
-
reg: reg instanceof RegExp ? reg : new RegExp(reg),
|
|
116
|
-
rep,
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
const data = {
|
|
120
|
-
...defCfg,
|
|
121
|
-
...botCfg,
|
|
122
|
-
sendMode: Number(botCfg.sendMode) || defCfg.sendMode,
|
|
123
|
-
regex: regexData,
|
|
1
|
+
import { dirPath } from '@/utils';
|
|
2
|
+
import { watch, basePath, filesByExt, copyConfigSync, requireFileSync, } from 'node-karin';
|
|
3
|
+
let cache;
|
|
4
|
+
/**
|
|
5
|
+
* @description package.json
|
|
6
|
+
*/
|
|
7
|
+
export const pkg = () => requireFileSync(`${dirPath}/package.json`);
|
|
8
|
+
/** 用户配置的插件名称 */
|
|
9
|
+
const pluginName = pkg().name.replace(/\//g, '-');
|
|
10
|
+
/** 用户配置 */
|
|
11
|
+
const dirConfig = `${basePath}/${pluginName}/config`;
|
|
12
|
+
/** 默认配置 */
|
|
13
|
+
const defConfig = `${dirPath}/config/config`;
|
|
14
|
+
/**
|
|
15
|
+
* @description 初始化配置文件
|
|
16
|
+
*/
|
|
17
|
+
copyConfigSync(defConfig, dirConfig, ['.yaml']);
|
|
18
|
+
/**
|
|
19
|
+
* @description 配置文件
|
|
20
|
+
*/
|
|
21
|
+
export const config = () => {
|
|
22
|
+
if (cache)
|
|
23
|
+
return cache;
|
|
24
|
+
const user = requireFileSync(`${dirConfig}/config.yaml`);
|
|
25
|
+
const def = requireFileSync(`${defConfig}/config.yaml`);
|
|
26
|
+
const result = { default: Object.assign(def.default, user.default) };
|
|
27
|
+
for (const key in user) {
|
|
28
|
+
if (key === 'default')
|
|
29
|
+
continue;
|
|
30
|
+
result[key] = {
|
|
31
|
+
...result.default,
|
|
32
|
+
...user[key],
|
|
33
|
+
event: {
|
|
34
|
+
...result.default.event,
|
|
35
|
+
...user?.[key]?.event
|
|
36
|
+
},
|
|
37
|
+
markdown: {
|
|
38
|
+
...result.default.markdown,
|
|
39
|
+
...user?.[key]?.markdown
|
|
40
|
+
},
|
|
124
41
|
};
|
|
125
|
-
/** 缓存 */
|
|
126
|
-
this.change.set(key, data);
|
|
127
|
-
return data;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* package
|
|
131
|
-
*/
|
|
132
|
-
get package() {
|
|
133
|
-
const data = fs.readFileSync(dirPath + '/package.json', 'utf8');
|
|
134
|
-
const pkg = JSON.parse(data);
|
|
135
|
-
return pkg;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* 获取配置yaml
|
|
139
|
-
*/
|
|
140
|
-
getYaml(type, name, isWatch = false) {
|
|
141
|
-
/** 文件路径 */
|
|
142
|
-
const file = type === 'defSet' ? `${this.defdir}/${name}.yaml` : `${this.dir}/${name}.yaml`;
|
|
143
|
-
/** 读取文件 */
|
|
144
|
-
const data = Yaml.parse(fs.readFileSync(file, 'utf8'));
|
|
145
|
-
/** 监听文件 */
|
|
146
|
-
if (isWatch)
|
|
147
|
-
this.watch(type, name, file);
|
|
148
|
-
return data;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 监听配置文件
|
|
152
|
-
* @param {'defSet'|'config'} type 类型
|
|
153
|
-
* @param {string} name 文件名称 不带后缀
|
|
154
|
-
* @param {string} file 文件路径
|
|
155
|
-
*/
|
|
156
|
-
async watch(type, name, file) {
|
|
157
|
-
const key = `change.${name}`;
|
|
158
|
-
/** 已经监听过了 */
|
|
159
|
-
const res = this.change.get(key);
|
|
160
|
-
if (res)
|
|
161
|
-
return true;
|
|
162
|
-
/** 监听文件 */
|
|
163
|
-
const watcher = chokidar.watch(file);
|
|
164
|
-
/** 监听文件变化 */
|
|
165
|
-
watcher.on('change', () => {
|
|
166
|
-
this.change.delete(key);
|
|
167
|
-
logger.mark(`[修改配置文件][${type}][${name}]`);
|
|
168
|
-
});
|
|
169
|
-
/** 缓存 防止重复监听 */
|
|
170
|
-
this.watcher.set(key, watcher);
|
|
171
42
|
}
|
|
172
|
-
|
|
43
|
+
cache = result;
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
173
46
|
/**
|
|
174
|
-
*
|
|
47
|
+
* @description 监听配置文件
|
|
175
48
|
*/
|
|
176
|
-
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
const list = filesByExt(dirConfig, '.yaml', 'abs');
|
|
51
|
+
list.forEach(file => watch(file, (old, now) => {
|
|
52
|
+
cache = undefined;
|
|
53
|
+
}));
|
|
54
|
+
}, 2000);
|
package/lib/utils/dir.d.ts
CHANGED
package/lib/utils/dir.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
/** 当前文件的绝对路径 */
|
|
5
|
-
const filePath = fileURLToPath(import.meta.url).replace(/\\/g, '/');
|
|
6
|
-
/** 插件包绝对路径 */
|
|
7
|
-
const dirPath = path.resolve(filePath, '../../../');
|
|
8
|
-
/** 插件包的名称 */
|
|
9
|
-
const basename = JSON.parse(fs.readFileSync(`${dirPath}/package.json`, 'utf-8')).name;
|
|
10
|
-
export { dirPath, basename };
|
|
1
|
+
export * from '../root';
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './dir
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './dir';
|
|
2
|
+
export * from './config';
|
|
3
|
+
export * as common from './common';
|
|
4
|
+
export * as config from './config';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './dir
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './dir';
|
|
2
|
+
export * from './config';
|
|
3
|
+
export * as common from './common';
|
|
4
|
+
export * as config from './config';
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karinjs/adapter-qqbot",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"
|
|
5
|
-
"type": "module",
|
|
6
|
-
"description": "karin plugin template",
|
|
3
|
+
"version": "1.2.10",
|
|
4
|
+
"description": "karin plugin adapter for qqbot",
|
|
7
5
|
"homepage": "https://github.com/KarinJS/karin-plugin-adapter-qqbot",
|
|
8
6
|
"bugs": {
|
|
9
7
|
"url": "https://github.com/KarinJS/karin-plugin-adapter-qqbot/issues"
|
|
@@ -12,34 +10,54 @@
|
|
|
12
10
|
"type": "git",
|
|
13
11
|
"url": "git+https://github.com/KarinJS/karin-plugin-adapter-qqbot.git"
|
|
14
12
|
},
|
|
13
|
+
"author": "shijin",
|
|
14
|
+
"type": "module",
|
|
15
15
|
"main": "lib/index.js",
|
|
16
|
-
"types": "lib/index.d.ts",
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
19
|
-
"pub": "npm publish --access public"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@karinjs/geturls": "^1.0.2",
|
|
23
|
-
"got": "^14.4.1",
|
|
24
|
-
"jimp": "^0.22.12",
|
|
25
|
-
"qrcode": "^1.5.3",
|
|
26
|
-
"silk-wasm": "^3.6.1"
|
|
27
|
-
},
|
|
28
|
-
"karin": {
|
|
29
|
-
"apps": [],
|
|
30
|
-
"outDir": "lib",
|
|
31
|
-
"rootDir": "src"
|
|
32
|
-
},
|
|
33
16
|
"files": [
|
|
34
17
|
"/lib/**/*.js",
|
|
35
18
|
"/lib/**/*.d.ts",
|
|
36
|
-
"
|
|
19
|
+
"config",
|
|
20
|
+
"resources",
|
|
37
21
|
"LICENSE",
|
|
38
22
|
"package.json",
|
|
39
23
|
"README.md"
|
|
40
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc && tsup",
|
|
27
|
+
"pr": "node lib/cli/pr.js",
|
|
28
|
+
"pub": "npm publish --access public",
|
|
29
|
+
"pub-beta": "npm publish --tag beta",
|
|
30
|
+
"sort": "npx sort-package-json",
|
|
31
|
+
"dev": "tsx src/index.ts",
|
|
32
|
+
"karin": "karin"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@karinjs/geturls": "^1.0.2",
|
|
36
|
+
"form-data": "^4.0.2",
|
|
37
|
+
"image-size": "^1.2.0",
|
|
38
|
+
"qrcode": "^1.5.4",
|
|
39
|
+
"silk-wasm": "^3.6.3",
|
|
40
|
+
"tweetnacl": "^1.0.3"
|
|
41
|
+
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public",
|
|
43
44
|
"registry": "https://registry.npmjs.org"
|
|
45
|
+
},
|
|
46
|
+
"karin": {
|
|
47
|
+
"main": "src/index.ts",
|
|
48
|
+
"apps": [
|
|
49
|
+
"lib/apps"
|
|
50
|
+
],
|
|
51
|
+
"ts-apps": [
|
|
52
|
+
"src/apps"
|
|
53
|
+
],
|
|
54
|
+
"static": [
|
|
55
|
+
"resources"
|
|
56
|
+
],
|
|
57
|
+
"files": [
|
|
58
|
+
"config",
|
|
59
|
+
"data",
|
|
60
|
+
"resources"
|
|
61
|
+
]
|
|
44
62
|
}
|
|
45
|
-
}
|
|
63
|
+
}
|
package/config/config.yaml
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# 全局默认配置 以下所有配置均可在账号配置中单独配置
|
|
2
|
-
default:
|
|
3
|
-
# 获取调用凭证的api
|
|
4
|
-
accessTokenApi: https://bots.qq.com/app/getAppAccessToken
|
|
5
|
-
# 沙盒api
|
|
6
|
-
sandBoxApi: https://sandbox.api.sgroup.qq.com
|
|
7
|
-
# 正式环境api
|
|
8
|
-
qqBotApi: https://api.sgroup.qq.com
|
|
9
|
-
# 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
|
|
10
|
-
sendMode: 0
|
|
11
|
-
# 是否开启沙盒环境
|
|
12
|
-
sandBox: false
|
|
13
|
-
# 是否启用频道机器人
|
|
14
|
-
guild: false
|
|
15
|
-
# 频道机器人模式 0-公域机器人 1-私域机器人
|
|
16
|
-
guildMode: 0
|
|
17
|
-
|
|
18
|
-
# 机器人Markdown模板ID 只有在sendMode为3或4时有效
|
|
19
|
-
templateId: ""
|
|
20
|
-
|
|
21
|
-
# 机器人旧图文模板Markdown配置
|
|
22
|
-
oldTemplate:
|
|
23
|
-
# 开头文字
|
|
24
|
-
textStartKey: text_start
|
|
25
|
-
# 图片描述
|
|
26
|
-
imgDescKey: img_dec
|
|
27
|
-
# 图片地址
|
|
28
|
-
imgUrlKey: img_url
|
|
29
|
-
# 结尾文字
|
|
30
|
-
textEndKey: text_end
|
|
31
|
-
|
|
32
|
-
# 机器人纯文模板Markdown配置
|
|
33
|
-
textTemplate:
|
|
34
|
-
- text_0
|
|
35
|
-
- text_1
|
|
36
|
-
- text_2
|
|
37
|
-
- text_3
|
|
38
|
-
- text_4
|
|
39
|
-
- text_5
|
|
40
|
-
- text_6
|
|
41
|
-
- text_7
|
|
42
|
-
- text_8
|
|
43
|
-
- text_9
|
|
44
|
-
|
|
45
|
-
# 文本中的url转二维码白名单 配置后将不转换这些url为二维码
|
|
46
|
-
exclude: []
|
|
47
|
-
# 接受到消息后对文本进行表达式处理
|
|
48
|
-
regex: [
|
|
49
|
-
{
|
|
50
|
-
# 表达式
|
|
51
|
-
reg: "^#",
|
|
52
|
-
# 替换为
|
|
53
|
-
rep: "",
|
|
54
|
-
},
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
# 账号配置列表
|
|
58
|
-
accounts:
|
|
59
|
-
default:
|
|
60
|
-
# 机器人ID 必须为字符串
|
|
61
|
-
appId: "123456789"
|
|
62
|
-
# 机器人密钥
|
|
63
|
-
secret: "123456789"
|
|
64
|
-
# 机器人发送模式 0-直接发送 1-原生Markdown 3-旧图文模板Markdown 4-纯文模板Markdown 5-自定义处理
|
|
65
|
-
sendMode: 0
|
|
66
|
-
# 文本中的url转二维码白名单 配置后将不转换这些url为二维码 优先级高于全局配置
|
|
67
|
-
exclude: []
|
|
68
|
-
# 接受到消息后对文本进行表达式处理 优先级高于全局配置
|
|
69
|
-
regex: []
|
package/lib/core/api.d.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import EventEmitter from 'events';
|
|
3
|
-
import { AccountCfgType } from '../utils/index.js';
|
|
4
|
-
import { LoggerLevel } from 'node-karin';
|
|
5
|
-
import { IdType, FileType, PathType, V2ApiType, UploadMediaOptions, SendMessageOptions, UploadMediaResponse, SubEvent } from '../types/index.js';
|
|
6
|
-
export interface SendMessageResponse {
|
|
7
|
-
/** 消息唯一ID */
|
|
8
|
-
id: string;
|
|
9
|
-
/** 发送时间 */
|
|
10
|
-
timestamp: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* {key: xxx, values: xxx},模版内变量与填充值的kv映射
|
|
14
|
-
*/
|
|
15
|
-
export type Params = Array<{
|
|
16
|
-
key: string;
|
|
17
|
-
values: string[];
|
|
18
|
-
}>;
|
|
19
|
-
export declare class QQBotApi extends EventEmitter {
|
|
20
|
-
#private;
|
|
21
|
-
/** 开发者的appId */
|
|
22
|
-
appId: string;
|
|
23
|
-
/** Bot头像 */
|
|
24
|
-
avatar: string;
|
|
25
|
-
/** Bot的昵称 */
|
|
26
|
-
nick: string;
|
|
27
|
-
/** wss地址 */
|
|
28
|
-
wssUrl: string;
|
|
29
|
-
/** wss连接 */
|
|
30
|
-
wss: WebSocket;
|
|
31
|
-
/** wss连接唯一值 */
|
|
32
|
-
seq: number;
|
|
33
|
-
/** 心跳内容 */
|
|
34
|
-
heartbeat: {
|
|
35
|
-
op: 1;
|
|
36
|
-
d: null | number;
|
|
37
|
-
session_id: string;
|
|
38
|
-
};
|
|
39
|
-
/** 心跳生命周期 单位:毫秒 */
|
|
40
|
-
heartbeat_interval: number;
|
|
41
|
-
/** 请求头 用于鉴权 */
|
|
42
|
-
headers: {
|
|
43
|
-
[key: string]: string;
|
|
44
|
-
};
|
|
45
|
-
/** 基本请求接口 */
|
|
46
|
-
host: string;
|
|
47
|
-
constructor(config: AccountCfgType);
|
|
48
|
-
logger(level: LoggerLevel, ...args: any[]): void;
|
|
49
|
-
/**
|
|
50
|
-
* post请求
|
|
51
|
-
* @param url 请求地址
|
|
52
|
-
* @param options 请求参数
|
|
53
|
-
*/
|
|
54
|
-
post(url: string, options: any): Promise<import("got").Response<string> | undefined>;
|
|
55
|
-
/**
|
|
56
|
-
* delete请求
|
|
57
|
-
* @param url 请求地址
|
|
58
|
-
* @param options 请求参数
|
|
59
|
-
*/
|
|
60
|
-
delete(url: string): Promise<import("got").Response<string> | undefined>;
|
|
61
|
-
/**
|
|
62
|
-
* 获取调用凭证
|
|
63
|
-
* @param clientSecret 开发者的Secret
|
|
64
|
-
* @param isRefresh 是否是刷新凭证
|
|
65
|
-
*/
|
|
66
|
-
getAccessToken(isRefresh?: boolean): Promise<{
|
|
67
|
-
/** 凭证有效时间,单位:秒 需要在倒计时50秒内刷新凭证 */
|
|
68
|
-
expires_in: string;
|
|
69
|
-
/** 调用凭证 */
|
|
70
|
-
access_token: string;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* wss鉴权
|
|
74
|
-
* @param isAuth 是否鉴权
|
|
75
|
-
*/
|
|
76
|
-
wssAuth(isAuth: boolean): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* 获取wss地址
|
|
79
|
-
*/
|
|
80
|
-
getWssUrl(): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* 获取当前Bot信息
|
|
83
|
-
*/
|
|
84
|
-
getBotInfo(): Promise<{
|
|
85
|
-
/** Bot id */
|
|
86
|
-
id: string;
|
|
87
|
-
/** Bot昵称 */
|
|
88
|
-
username: string;
|
|
89
|
-
/** Bot头像 */
|
|
90
|
-
avatar: string;
|
|
91
|
-
/** Bot分享链接 */
|
|
92
|
-
share_url: string;
|
|
93
|
-
/** 欢迎信息 */
|
|
94
|
-
welcome_msg: string;
|
|
95
|
-
}>;
|
|
96
|
-
/**
|
|
97
|
-
* 创建wss连接
|
|
98
|
-
*/
|
|
99
|
-
createWss(isAuth?: boolean): void;
|
|
100
|
-
payload(payload: string): void;
|
|
101
|
-
/**
|
|
102
|
-
* 事件处理
|
|
103
|
-
*/
|
|
104
|
-
intents(data: SubEvent): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* 发送消息
|
|
107
|
-
* @param openid 用户、群openid
|
|
108
|
-
* @param type 请求路径类型
|
|
109
|
-
* @param options 请求参数
|
|
110
|
-
*/
|
|
111
|
-
sendMessage(openid: string, type: PathType, options: SendMessageOptions): Promise<SendMessageResponse>;
|
|
112
|
-
/**
|
|
113
|
-
* 撤回消息
|
|
114
|
-
* @param openid 用户、群openid
|
|
115
|
-
* @param type 请求路径类型
|
|
116
|
-
* @param message_id 消息id
|
|
117
|
-
*/
|
|
118
|
-
recallMessage(openid: string, type: PathType, message_id: string): Promise<boolean>;
|
|
119
|
-
/**
|
|
120
|
-
* 构建发送文本消息请求参数
|
|
121
|
-
*/
|
|
122
|
-
buildText(content: string, id?: string, seq?: number): SendMessageOptions;
|
|
123
|
-
/**
|
|
124
|
-
* 上传富媒体文件
|
|
125
|
-
* @param openid 用户、群openid
|
|
126
|
-
* @param type 请求类型
|
|
127
|
-
* @param file 文件内容 http、base64、file://
|
|
128
|
-
* @param file_type 文件类型
|
|
129
|
-
*/
|
|
130
|
-
uploadMedia(openid: string, type: PathType, file: string, file_type: FileType): Promise<UploadMediaResponse>;
|
|
131
|
-
/**
|
|
132
|
-
* 构建v2接口请求地址
|
|
133
|
-
* @param openid 用户、群openid
|
|
134
|
-
* @param type 请求类型
|
|
135
|
-
* @param apiType v2接口类型
|
|
136
|
-
*/
|
|
137
|
-
buildUrl(openid: string, type: PathType, apiType: V2ApiType): string;
|
|
138
|
-
/**
|
|
139
|
-
* 传入一个msg_id或者event_id 返回其对应的key和value
|
|
140
|
-
* @param id 消息id或者事件id
|
|
141
|
-
*/
|
|
142
|
-
buildId(id: string): {
|
|
143
|
-
key: IdType;
|
|
144
|
-
value: string;
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* 构建发送富媒体请求参数
|
|
148
|
-
* 富媒体消息只能单独发送 并且必须进行上传
|
|
149
|
-
* @param content 附带的文字信息,仅在file_type为1时有效,其余情况请传空字符串
|
|
150
|
-
* @param file_info 富媒体接口返回的file_info
|
|
151
|
-
* @param id 消息id或者事件id
|
|
152
|
-
*/
|
|
153
|
-
buildMedia(content: string, file_info: string, id?: string, seq?: number): SendMessageOptions;
|
|
154
|
-
/**
|
|
155
|
-
* 构建发送Markdown模板请求参数
|
|
156
|
-
* @param custom_template_id 模板id
|
|
157
|
-
* @param params 模板参数
|
|
158
|
-
* @param id 消息id或者事件id
|
|
159
|
-
* @param seq 消息序号
|
|
160
|
-
*/
|
|
161
|
-
buildTplMarkdown(custom_template_id: string, params: Params, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
|
|
162
|
-
/**
|
|
163
|
-
* 构建发送原生Markdown请求参数
|
|
164
|
-
* @param content markdown文本
|
|
165
|
-
* @param id 消息id或者事件id
|
|
166
|
-
* @param seq 消息序号
|
|
167
|
-
*/
|
|
168
|
-
buildRawMarkdown(content: string, keyboard: SendMessageOptions['keyboard'], id?: string, seq?: number): SendMessageOptions;
|
|
169
|
-
/**
|
|
170
|
-
* 构建上传富媒体请求参数
|
|
171
|
-
* @param file 文件内容 http、base64、file://
|
|
172
|
-
* @param file_type 文件类型
|
|
173
|
-
*/
|
|
174
|
-
buildUploadMedia(file: string, file_type: FileType): Promise<{
|
|
175
|
-
json: UploadMediaOptions;
|
|
176
|
-
headers: {
|
|
177
|
-
[key: string]: string;
|
|
178
|
-
};
|
|
179
|
-
}>;
|
|
180
|
-
}
|