@inetafrica/open-claudia 2.0.0 → 2.0.1
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 +4 -0
- package/core/access.js +21 -1
- package/core/context.js +14 -2
- package/core/router.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.0.1
|
|
4
|
+
- Kazee owner detection: `envelope.channelId` is the chat-document id, but `KAZEE_OWNER_USER_ID` is the Kazee user id. `isChatOwner`/`isChatAuthorized` now also short-circuit when the inbound user id matches the configured transport owner, so the owner running `/auth` (or anything else) on a fresh Kazee install is recognized immediately instead of being queued as a non-owner request.
|
|
5
|
+
- `chatContext` now carries `userId` and `transport` in addition to `chatId`; new `currentUserId()` / `currentTransport()` exports.
|
|
6
|
+
|
|
3
7
|
## v2.0.0
|
|
4
8
|
- **Multi-channel**: the bot can now run on Telegram and Kazee Chat in the same process. `CHANNELS=telegram,kazee` selects which channels start up; each channel implements the new `ChannelAdapter` contract (send/edit/delete/upload/keyboard/typing/voice-fetch) and a `chatContext` AsyncLocalStorage routes replies, edits, and notifications back to the originating channel.
|
|
5
9
|
- Kazee adapter speaks V2 socket (inbound messages, edits, deletes, reactions, typing, presence) and uses REST for sending, editing, deleting, and uploads. Interactive button keyboards are sent as `type:"interactive"` with portable `interactive.buttons` so web and mobile clients render them natively.
|
package/core/access.js
CHANGED
|
@@ -5,7 +5,25 @@
|
|
|
5
5
|
// in the inbound envelope's canonicalUserId, not here.
|
|
6
6
|
|
|
7
7
|
const fs = require("fs");
|
|
8
|
-
const { AUTH_FILE, CHAT_ID, CHAT_IDS, saveEnvKey } = require("./config");
|
|
8
|
+
const { AUTH_FILE, CHAT_ID, CHAT_IDS, config, saveEnvKey } = require("./config");
|
|
9
|
+
const { currentTransport, currentUserId } = require("./context");
|
|
10
|
+
|
|
11
|
+
// Per-transport owner identifiers that don't live in CHAT_IDS or auth.json.
|
|
12
|
+
// Kazee envelopes carry the chat-document id as channelId, while the bot
|
|
13
|
+
// owner is identified by the Kazee user id. Resolve via env at call time so
|
|
14
|
+
// /channel add can update the value without a process restart.
|
|
15
|
+
function transportOwnerUserId(transport) {
|
|
16
|
+
if (transport === "kazee") return config.KAZEE_OWNER_USER_ID || "";
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function matchesTransportOwner() {
|
|
21
|
+
const transport = currentTransport();
|
|
22
|
+
const userId = currentUserId();
|
|
23
|
+
if (!transport || !userId) return false;
|
|
24
|
+
const ownerUserId = transportOwnerUserId(transport);
|
|
25
|
+
return ownerUserId && String(userId) === String(ownerUserId);
|
|
26
|
+
}
|
|
9
27
|
|
|
10
28
|
function loadAuth() {
|
|
11
29
|
try {
|
|
@@ -24,6 +42,7 @@ function saveAuth(auth) {
|
|
|
24
42
|
}
|
|
25
43
|
|
|
26
44
|
function isChatAuthorized(chatId) {
|
|
45
|
+
if (matchesTransportOwner()) return true;
|
|
27
46
|
const id = String(chatId || "");
|
|
28
47
|
if (!id) return false;
|
|
29
48
|
if (CHAT_IDS.includes(id)) return true;
|
|
@@ -35,6 +54,7 @@ function isChatAuthorized(chatId) {
|
|
|
35
54
|
}
|
|
36
55
|
|
|
37
56
|
function isChatOwner(chatId) {
|
|
57
|
+
if (matchesTransportOwner()) return true;
|
|
38
58
|
const id = String(chatId || "");
|
|
39
59
|
if (!id) return false;
|
|
40
60
|
if (id === String(CHAT_ID || "")) return true;
|
package/core/context.js
CHANGED
|
@@ -6,8 +6,8 @@ const { AsyncLocalStorage } = require("node:async_hooks");
|
|
|
6
6
|
|
|
7
7
|
const chatContext = new AsyncLocalStorage();
|
|
8
8
|
|
|
9
|
-
function runInChat({ adapter, channelId, canonicalUserId, raw }, fn) {
|
|
10
|
-
return chatContext.run({ adapter, channelId, canonicalUserId, raw }, fn);
|
|
9
|
+
function runInChat({ adapter, channelId, canonicalUserId, userId, transport, raw }, fn) {
|
|
10
|
+
return chatContext.run({ adapter, channelId, canonicalUserId, userId, transport, raw }, fn);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function currentStore() {
|
|
@@ -34,11 +34,23 @@ function currentRaw() {
|
|
|
34
34
|
return s ? s.raw : null;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function currentUserId() {
|
|
38
|
+
const s = currentStore();
|
|
39
|
+
return s ? s.userId : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function currentTransport() {
|
|
43
|
+
const s = currentStore();
|
|
44
|
+
return s ? s.transport : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
module.exports = {
|
|
38
48
|
chatContext,
|
|
39
49
|
runInChat,
|
|
40
50
|
currentAdapter,
|
|
41
51
|
currentChannelId,
|
|
42
52
|
currentCanonicalUserId,
|
|
53
|
+
currentUserId,
|
|
54
|
+
currentTransport,
|
|
43
55
|
currentRaw,
|
|
44
56
|
};
|
package/core/router.js
CHANGED
package/package.json
CHANGED