@nextclaw/channel-runtime 0.1.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/README.md +9 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +2658 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @nextclaw/channel-runtime
|
|
2
|
+
|
|
3
|
+
Runtime implementations for NextClaw builtin channels.
|
|
4
|
+
|
|
5
|
+
This package is consumed by channel plugin packages such as:
|
|
6
|
+
|
|
7
|
+
- `@nextclaw/channel-plugin-telegram`
|
|
8
|
+
- `@nextclaw/channel-plugin-discord`
|
|
9
|
+
- `@nextclaw/channel-plugin-email`
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { MessageBus, Config, SessionManager } from '@nextclaw/core';
|
|
2
|
+
|
|
3
|
+
type InboundAttachmentErrorCode = "too_large" | "download_failed" | "http_error" | "invalid_payload";
|
|
4
|
+
type InboundAttachment = {
|
|
5
|
+
id?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
mimeType?: string;
|
|
10
|
+
size?: number;
|
|
11
|
+
source?: string;
|
|
12
|
+
status?: "ready" | "remote-only";
|
|
13
|
+
errorCode?: InboundAttachmentErrorCode;
|
|
14
|
+
};
|
|
15
|
+
type OutboundMessage = {
|
|
16
|
+
channel: string;
|
|
17
|
+
chatId: string;
|
|
18
|
+
content: string;
|
|
19
|
+
replyTo?: string | null;
|
|
20
|
+
media: string[];
|
|
21
|
+
metadata: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare abstract class BaseChannel<TConfig extends Record<string, unknown>> {
|
|
25
|
+
protected config: TConfig;
|
|
26
|
+
protected bus: MessageBus;
|
|
27
|
+
protected running: boolean;
|
|
28
|
+
constructor(config: TConfig, bus: MessageBus);
|
|
29
|
+
abstract get name(): string;
|
|
30
|
+
abstract start(): Promise<void>;
|
|
31
|
+
abstract stop(): Promise<void>;
|
|
32
|
+
abstract send(msg: OutboundMessage): Promise<void>;
|
|
33
|
+
isAllowed(senderId: string): boolean;
|
|
34
|
+
protected handleMessage(params: {
|
|
35
|
+
senderId: string;
|
|
36
|
+
chatId: string;
|
|
37
|
+
content: string;
|
|
38
|
+
attachments?: InboundAttachment[];
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
get isRunning(): boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare class DingTalkChannel extends BaseChannel<Config["channels"]["dingtalk"]> {
|
|
45
|
+
name: string;
|
|
46
|
+
private client;
|
|
47
|
+
private accessToken;
|
|
48
|
+
private tokenExpiry;
|
|
49
|
+
constructor(config: Config["channels"]["dingtalk"], bus: MessageBus);
|
|
50
|
+
start(): Promise<void>;
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
53
|
+
private handleRobotMessage;
|
|
54
|
+
private getAccessToken;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class DiscordChannel extends BaseChannel<Config["channels"]["discord"]> {
|
|
58
|
+
name: string;
|
|
59
|
+
private client;
|
|
60
|
+
private typingTasks;
|
|
61
|
+
constructor(config: Config["channels"]["discord"], bus: MessageBus);
|
|
62
|
+
start(): Promise<void>;
|
|
63
|
+
stop(): Promise<void>;
|
|
64
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
65
|
+
private handleIncoming;
|
|
66
|
+
private resolveProxyAgent;
|
|
67
|
+
private resolveInboundAttachment;
|
|
68
|
+
private startTyping;
|
|
69
|
+
private stopTyping;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class EmailChannel extends BaseChannel<Config["channels"]["email"]> {
|
|
73
|
+
name: string;
|
|
74
|
+
private lastSubjectByChat;
|
|
75
|
+
private lastMessageIdByChat;
|
|
76
|
+
private processedUids;
|
|
77
|
+
private maxProcessedUids;
|
|
78
|
+
constructor(config: Config["channels"]["email"], bus: MessageBus);
|
|
79
|
+
start(): Promise<void>;
|
|
80
|
+
stop(): Promise<void>;
|
|
81
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
82
|
+
private validateConfig;
|
|
83
|
+
private replySubject;
|
|
84
|
+
private fetchNewMessages;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class FeishuChannel extends BaseChannel<Config["channels"]["feishu"]> {
|
|
88
|
+
name: string;
|
|
89
|
+
private client;
|
|
90
|
+
private wsClient;
|
|
91
|
+
private processedMessageIds;
|
|
92
|
+
private processedSet;
|
|
93
|
+
constructor(config: Config["channels"]["feishu"], bus: MessageBus);
|
|
94
|
+
start(): Promise<void>;
|
|
95
|
+
stop(): Promise<void>;
|
|
96
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
97
|
+
private handleIncoming;
|
|
98
|
+
private isDuplicate;
|
|
99
|
+
private addReaction;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class MochatChannel extends BaseChannel<Config["channels"]["mochat"]> {
|
|
103
|
+
name: string;
|
|
104
|
+
private socket;
|
|
105
|
+
private wsConnected;
|
|
106
|
+
private wsReady;
|
|
107
|
+
private stateDir;
|
|
108
|
+
private cursorPath;
|
|
109
|
+
private sessionCursor;
|
|
110
|
+
private cursorSaveTimer;
|
|
111
|
+
private sessionSet;
|
|
112
|
+
private panelSet;
|
|
113
|
+
private autoDiscoverSessions;
|
|
114
|
+
private autoDiscoverPanels;
|
|
115
|
+
private coldSessions;
|
|
116
|
+
private sessionByConverse;
|
|
117
|
+
private seenSet;
|
|
118
|
+
private seenQueue;
|
|
119
|
+
private delayStates;
|
|
120
|
+
private fallbackMode;
|
|
121
|
+
private sessionFallbackTasks;
|
|
122
|
+
private panelFallbackTasks;
|
|
123
|
+
private refreshTimer;
|
|
124
|
+
private targetLocks;
|
|
125
|
+
private refreshInFlight;
|
|
126
|
+
constructor(config: Config["channels"]["mochat"], bus: MessageBus);
|
|
127
|
+
start(): Promise<void>;
|
|
128
|
+
stop(): Promise<void>;
|
|
129
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
130
|
+
private seedTargetsFromConfig;
|
|
131
|
+
private startSocketClient;
|
|
132
|
+
private subscribeAll;
|
|
133
|
+
private subscribeSessions;
|
|
134
|
+
private subscribePanels;
|
|
135
|
+
private socketCall;
|
|
136
|
+
private refreshLoopTick;
|
|
137
|
+
private refreshTargets;
|
|
138
|
+
private refreshSessionsDirectory;
|
|
139
|
+
private refreshPanels;
|
|
140
|
+
private ensureFallbackWorkers;
|
|
141
|
+
private stopFallbackWorkers;
|
|
142
|
+
private sessionWatchWorker;
|
|
143
|
+
private panelPollWorker;
|
|
144
|
+
private handleWatchPayload;
|
|
145
|
+
private processInboundEvent;
|
|
146
|
+
private rememberMessageId;
|
|
147
|
+
private enqueueDelayedEntry;
|
|
148
|
+
private flushDelayedEntries;
|
|
149
|
+
private dispatchEntries;
|
|
150
|
+
private cancelDelayTimers;
|
|
151
|
+
private handleNotifyChatMessage;
|
|
152
|
+
private handleNotifyInboxAppend;
|
|
153
|
+
private markSessionCursor;
|
|
154
|
+
private loadSessionCursors;
|
|
155
|
+
private saveSessionCursors;
|
|
156
|
+
private postJson;
|
|
157
|
+
private apiSend;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class QQChannel extends BaseChannel<Config["channels"]["qq"]> {
|
|
161
|
+
name: string;
|
|
162
|
+
private bot;
|
|
163
|
+
private processedIds;
|
|
164
|
+
private processedSet;
|
|
165
|
+
constructor(config: Config["channels"]["qq"], bus: MessageBus);
|
|
166
|
+
start(): Promise<void>;
|
|
167
|
+
stop(): Promise<void>;
|
|
168
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
169
|
+
private handleIncoming;
|
|
170
|
+
private isDuplicate;
|
|
171
|
+
private sendWithTokenRetry;
|
|
172
|
+
private isTokenExpiredError;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
declare class SlackChannel extends BaseChannel<Config["channels"]["slack"]> {
|
|
176
|
+
name: string;
|
|
177
|
+
private webClient;
|
|
178
|
+
private socketClient;
|
|
179
|
+
private botUserId;
|
|
180
|
+
private botId;
|
|
181
|
+
constructor(config: Config["channels"]["slack"], bus: MessageBus);
|
|
182
|
+
start(): Promise<void>;
|
|
183
|
+
stop(): Promise<void>;
|
|
184
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
185
|
+
private handleEvent;
|
|
186
|
+
private isAllowedInSlack;
|
|
187
|
+
private shouldRespondInChannel;
|
|
188
|
+
private stripBotMention;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare class TelegramChannel extends BaseChannel<Config["channels"]["telegram"]> {
|
|
192
|
+
private sessionManager?;
|
|
193
|
+
name: string;
|
|
194
|
+
private bot;
|
|
195
|
+
private typingTasks;
|
|
196
|
+
private transcriber;
|
|
197
|
+
constructor(config: Config["channels"]["telegram"], bus: MessageBus, groqApiKey?: string, sessionManager?: SessionManager | undefined);
|
|
198
|
+
start(): Promise<void>;
|
|
199
|
+
stop(): Promise<void>;
|
|
200
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
201
|
+
private handleIncoming;
|
|
202
|
+
private dispatchToBus;
|
|
203
|
+
private startTyping;
|
|
204
|
+
private stopTyping;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare class WhatsAppChannel extends BaseChannel<Config["channels"]["whatsapp"]> {
|
|
208
|
+
name: string;
|
|
209
|
+
private ws;
|
|
210
|
+
private connected;
|
|
211
|
+
constructor(config: Config["channels"]["whatsapp"], bus: MessageBus);
|
|
212
|
+
start(): Promise<void>;
|
|
213
|
+
stop(): Promise<void>;
|
|
214
|
+
send(msg: OutboundMessage): Promise<void>;
|
|
215
|
+
private handleBridgeMessage;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
type BuiltinChannelCreateContext = {
|
|
219
|
+
config: Config;
|
|
220
|
+
bus: MessageBus;
|
|
221
|
+
sessionManager?: SessionManager;
|
|
222
|
+
};
|
|
223
|
+
type BuiltinChannelRuntime = {
|
|
224
|
+
id: BuiltinChannelId;
|
|
225
|
+
isEnabled: (config: Config) => boolean;
|
|
226
|
+
createChannel: (context: BuiltinChannelCreateContext) => unknown;
|
|
227
|
+
};
|
|
228
|
+
declare const BUILTIN_CHANNEL_RUNTIMES: {
|
|
229
|
+
readonly telegram: {
|
|
230
|
+
readonly id: "telegram";
|
|
231
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
232
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => TelegramChannel;
|
|
233
|
+
};
|
|
234
|
+
readonly whatsapp: {
|
|
235
|
+
readonly id: "whatsapp";
|
|
236
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
237
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => WhatsAppChannel;
|
|
238
|
+
};
|
|
239
|
+
readonly discord: {
|
|
240
|
+
readonly id: "discord";
|
|
241
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
242
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => DiscordChannel;
|
|
243
|
+
};
|
|
244
|
+
readonly feishu: {
|
|
245
|
+
readonly id: "feishu";
|
|
246
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
247
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => FeishuChannel;
|
|
248
|
+
};
|
|
249
|
+
readonly mochat: {
|
|
250
|
+
readonly id: "mochat";
|
|
251
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
252
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => MochatChannel;
|
|
253
|
+
};
|
|
254
|
+
readonly dingtalk: {
|
|
255
|
+
readonly id: "dingtalk";
|
|
256
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
257
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => DingTalkChannel;
|
|
258
|
+
};
|
|
259
|
+
readonly email: {
|
|
260
|
+
readonly id: "email";
|
|
261
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
262
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => EmailChannel;
|
|
263
|
+
};
|
|
264
|
+
readonly slack: {
|
|
265
|
+
readonly id: "slack";
|
|
266
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
267
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => SlackChannel;
|
|
268
|
+
};
|
|
269
|
+
readonly qq: {
|
|
270
|
+
readonly id: "qq";
|
|
271
|
+
readonly isEnabled: (config: Config) => boolean;
|
|
272
|
+
readonly createChannel: (context: BuiltinChannelCreateContext) => QQChannel;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
type BuiltinChannelId = keyof typeof BUILTIN_CHANNEL_RUNTIMES;
|
|
276
|
+
declare const BUILTIN_CHANNEL_PLUGIN_IDS: BuiltinChannelId[];
|
|
277
|
+
declare function listBuiltinChannelRuntimes(): BuiltinChannelRuntime[];
|
|
278
|
+
declare function resolveBuiltinChannelRuntime(channelId: string): BuiltinChannelRuntime;
|
|
279
|
+
|
|
280
|
+
export { BUILTIN_CHANNEL_PLUGIN_IDS, type BuiltinChannelId, type BuiltinChannelRuntime, DingTalkChannel, DiscordChannel, EmailChannel, FeishuChannel, MochatChannel, QQChannel, SlackChannel, TelegramChannel, WhatsAppChannel, listBuiltinChannelRuntimes, resolveBuiltinChannelRuntime };
|