@dingtalk-real-ai/dingtalk-connector 0.8.20 → 0.8.21
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/CHANGELOG.md +45 -0
- package/README.en.md +18 -2
- package/README.md +18 -2
- package/dist/{connection-BZd5NXuh.mjs → connection-D4uO_J9G.mjs} +33 -7
- package/dist/entry-bundled.mjs +1 -1
- package/dist/gateway-methods-B0_tBGPn.mjs +2 -0
- package/dist/{gateway-methods-DI8lkjSd.mjs → gateway-methods-BNuB2wXl.mjs} +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{media-DUMfXnwJ.mjs → media-BRqGsKUB.mjs} +8 -8
- package/dist/{media-DEuF7r3G.mjs → media-DD7Rlljd.mjs} +1 -1
- package/dist/{message-handler-_vk6QsWo.mjs → message-handler-CPGT1bgU.mjs} +74 -13
- package/dist/{messaging-CyIJY4h2.mjs → messaging-DQwrrd68.mjs} +90 -10
- package/dist/{runtime-b4xvqwW6.mjs → runtime-BphH7_vR.mjs} +5 -5
- package/dist/{utils-DY1gFCdU.mjs → utils-BqUoUOwd.mjs} +1 -1
- package/dist/utils-QEvgZ2uM.mjs +119 -0
- package/docs/RELEASE_NOTES_V0.8.21-beta.0.md +163 -0
- package/docs/RELEASE_NOTES_V0.8.21.md +154 -0
- package/docs/TROUBLESHOOTING.md +28 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/core/connection.ts +75 -13
- package/src/core/message-handler.ts +15 -1
- package/src/reply-dispatcher.ts +101 -5
- package/src/services/messaging/card.ts +117 -5
- package/src/utils/empty-reply.ts +72 -0
- package/src/utils/index.ts +1 -0
- package/dist/gateway-methods-DtdiDpYK.mjs +0 -2
- package/dist/utils-CIfI_3Jh.mjs +0 -63
package/dist/utils-CIfI_3Jh.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { n as dingtalkOapiHttp, t as dingtalkHttp } from "./http-client-DFWZgO1n.mjs";
|
|
2
|
-
//#region src/utils/token.ts
|
|
3
|
-
const DINGTALK_API = "https://api.dingtalk.com";
|
|
4
|
-
const DINGTALK_OAPI = "https://oapi.dingtalk.com";
|
|
5
|
-
/**
|
|
6
|
-
* 按 clientId 分桶缓存,避免多账号串 token。
|
|
7
|
-
*/
|
|
8
|
-
const apiTokenCache = /* @__PURE__ */ new Map();
|
|
9
|
-
const oapiTokenCache = /* @__PURE__ */ new Map();
|
|
10
|
-
function cacheKey(config) {
|
|
11
|
-
const clientId = String(config?.clientId ?? "").trim();
|
|
12
|
-
if (!clientId) throw new Error("Invalid DingtalkConfig: clientId is required for token caching. Please ensure your configuration includes a valid clientId.");
|
|
13
|
-
return clientId;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 获取钉钉 Access Token(新版 API)
|
|
17
|
-
*/
|
|
18
|
-
async function getAccessToken(config) {
|
|
19
|
-
const now = Date.now();
|
|
20
|
-
const key = cacheKey(config);
|
|
21
|
-
const cached = apiTokenCache.get(key);
|
|
22
|
-
if (cached && cached.expiryMs > now + 6e4) return cached.token;
|
|
23
|
-
const response = await dingtalkHttp.post(`${DINGTALK_API}/v1.0/oauth2/accessToken`, {
|
|
24
|
-
appKey: config.clientId,
|
|
25
|
-
appSecret: config.clientSecret
|
|
26
|
-
});
|
|
27
|
-
const token = response.data.accessToken;
|
|
28
|
-
const expireInSec = Number(response.data.expireIn ?? 0);
|
|
29
|
-
apiTokenCache.set(key, {
|
|
30
|
-
token,
|
|
31
|
-
expiryMs: now + expireInSec * 1e3
|
|
32
|
-
});
|
|
33
|
-
return token;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 获取钉钉 OAPI Access Token(旧版 API,用于媒体上传等)
|
|
37
|
-
*/
|
|
38
|
-
async function getOapiAccessToken(config) {
|
|
39
|
-
try {
|
|
40
|
-
const now = Date.now();
|
|
41
|
-
const key = cacheKey(config);
|
|
42
|
-
const cached = oapiTokenCache.get(key);
|
|
43
|
-
if (cached && cached.expiryMs > now + 6e4) return cached.token;
|
|
44
|
-
const resp = await dingtalkOapiHttp.get(`${DINGTALK_OAPI}/gettoken`, { params: {
|
|
45
|
-
appkey: config.clientId,
|
|
46
|
-
appsecret: config.clientSecret
|
|
47
|
-
} });
|
|
48
|
-
if (resp.data?.errcode === 0 && resp.data?.access_token) {
|
|
49
|
-
const token = String(resp.data.access_token);
|
|
50
|
-
const expiresInSec = Number(resp.data.expires_in ?? 7200);
|
|
51
|
-
oapiTokenCache.set(key, {
|
|
52
|
-
token,
|
|
53
|
-
expiryMs: now + expiresInSec * 1e3
|
|
54
|
-
});
|
|
55
|
-
return token;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
} catch {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { getOapiAccessToken as i, DINGTALK_OAPI as n, getAccessToken as r, DINGTALK_API as t };
|