@messenger-box/platform-server 10.0.3-alpha.240 → 10.0.3-alpha.241
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": "@messenger-box/platform-server",
|
|
3
|
-
"version": "10.0.3-alpha.
|
|
3
|
+
"version": "10.0.3-alpha.241",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
]
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "54b4b576d7ae2c330a4acf7847c9758d8f9067d5",
|
|
74
74
|
"typescript": {
|
|
75
75
|
"definition": "lib/index.d.ts"
|
|
76
76
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { IExternalChannelProvider, IExternalChannelRegistry, IChannelProviderConfig } from './types';
|
|
2
|
-
export declare class ExternalChannelRegistry implements IExternalChannelRegistry {
|
|
3
|
-
private providers;
|
|
4
|
-
register(provider: IExternalChannelProvider): void;
|
|
5
|
-
unregister(providerType: string): void;
|
|
6
|
-
get(providerType: string): IExternalChannelProvider | undefined;
|
|
7
|
-
listTypes(): string[];
|
|
8
|
-
listProviders(): IChannelProviderConfig[];
|
|
9
|
-
has(providerType: string): boolean;
|
|
10
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { CdmLogger } from '@cdm-logger/core';
|
|
2
|
-
import type { IGatewayService, IExternalChannelRegistry, IMessageRouterService, IInboundMessage, IOutboundMessage, ISendResult, IGatewayChannelStatus } from './types';
|
|
3
|
-
type InboundHandler = (message: IInboundMessage) => void;
|
|
4
|
-
export declare class GatewayService implements IGatewayService {
|
|
5
|
-
private logger;
|
|
6
|
-
private registry;
|
|
7
|
-
private router;
|
|
8
|
-
private inboundHandlers;
|
|
9
|
-
private initialized;
|
|
10
|
-
constructor(registry: IExternalChannelRegistry, router: IMessageRouterService, logger?: CdmLogger.ILogger);
|
|
11
|
-
initialize(): Promise<void>;
|
|
12
|
-
shutdown(): Promise<void>;
|
|
13
|
-
getRegistry(): IExternalChannelRegistry;
|
|
14
|
-
connectChannel(channelType: string, accountId: string, options: Record<string, unknown>): Promise<void>;
|
|
15
|
-
disconnectChannel(channelType: string, accountId: string): Promise<void>;
|
|
16
|
-
sendMessage(message: IOutboundMessage): Promise<ISendResult>;
|
|
17
|
-
getStatus(): IGatewayChannelStatus[];
|
|
18
|
-
getChannelStatus(channelType: string): IGatewayChannelStatus[];
|
|
19
|
-
onInboundMessage(handler: InboundHandler): void;
|
|
20
|
-
/** Forward inbound message to all registered handlers and the router */
|
|
21
|
-
private handleInbound;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
package/lib/gateway/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CdmLogger } from '@cdm-logger/core';
|
|
2
|
-
import type { IInboundMessage, IOutboundMessage, ISendResult, IMessageRouterService, IExternalChannelRegistry } from './types';
|
|
3
|
-
export declare class MessageRouterService implements IMessageRouterService {
|
|
4
|
-
private logger;
|
|
5
|
-
private registry;
|
|
6
|
-
constructor(registry: IExternalChannelRegistry, logger?: CdmLogger.ILogger);
|
|
7
|
-
/**
|
|
8
|
-
* Route an inbound message from an external channel provider to the platform.
|
|
9
|
-
*
|
|
10
|
-
* This is where external messages get translated into platform Posts.
|
|
11
|
-
* In Go: similar to picoclaw's `pkg/channels/handler.go` HandleInbound.
|
|
12
|
-
*/
|
|
13
|
-
routeInbound(message: IInboundMessage): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Route an outbound message from the platform to the correct external channel provider.
|
|
16
|
-
*
|
|
17
|
-
* Looks up the provider by channelType in the registry and delegates the send.
|
|
18
|
-
*/
|
|
19
|
-
routeOutbound(message: IOutboundMessage): Promise<ISendResult>;
|
|
20
|
-
}
|
package/lib/gateway/types.d.ts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gateway Types — External messaging channel provider interfaces.
|
|
3
|
-
*
|
|
4
|
-
* Designed Go-portable: no Inversify decorators, no Mongoose, no Moleculer.
|
|
5
|
-
* Every interface maps 1:1 to a Go interface. Uses plain constructors,
|
|
6
|
-
* explicit error returns, and typed queues (via EventEmitter or NATS topics).
|
|
7
|
-
*
|
|
8
|
-
* Architecture mapping:
|
|
9
|
-
* openclaw → ChannelProvider / ChannelAccountManager → this file
|
|
10
|
-
* picoclaw → pkg/channels/channel.go → this file
|
|
11
|
-
* clockbook → BOT_TYPES.IChannelRegistry → this file
|
|
12
|
-
*
|
|
13
|
-
* Channel extensions register providers via `contributes.channels` in their
|
|
14
|
-
* package.json and call `channels.registerProvider()` during activation.
|
|
15
|
-
*/
|
|
16
|
-
import type { IChannelCapabilities, IChannelDock, IChannelAccountSnapshot, IChannelStatusIssue } from '../channels/types';
|
|
17
|
-
/** Provider lifecycle state */
|
|
18
|
-
export type ProviderState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
19
|
-
/** Direction of a message relative to the gateway */
|
|
20
|
-
export type MessageDirection = 'inbound' | 'outbound';
|
|
21
|
-
/** Media attachment type */
|
|
22
|
-
export type MediaType = 'image' | 'audio' | 'video' | 'document' | 'sticker' | 'location' | 'contact';
|
|
23
|
-
export interface IMediaAttachment {
|
|
24
|
-
type: MediaType;
|
|
25
|
-
url?: string;
|
|
26
|
-
/** Raw bytes (base64 in JSON, []byte in Go) */
|
|
27
|
-
data?: string;
|
|
28
|
-
mimeType?: string;
|
|
29
|
-
filename?: string;
|
|
30
|
-
caption?: string;
|
|
31
|
-
/** Duration in seconds (audio/video) */
|
|
32
|
-
durationSec?: number;
|
|
33
|
-
/** Thumbnail URL or base64 */
|
|
34
|
-
thumbnail?: string;
|
|
35
|
-
}
|
|
36
|
-
/** An inbound message from an external channel into the gateway */
|
|
37
|
-
export interface IInboundMessage {
|
|
38
|
-
/** Unique message ID from the external platform */
|
|
39
|
-
externalId: string;
|
|
40
|
-
/** Channel provider identifier (e.g. 'whatsapp', 'telegram') */
|
|
41
|
-
channelType: string;
|
|
42
|
-
/** Account ID within the channel provider */
|
|
43
|
-
accountId: string;
|
|
44
|
-
/** Sender identifier on the external platform */
|
|
45
|
-
senderId: string;
|
|
46
|
-
/** Sender display name */
|
|
47
|
-
senderName?: string;
|
|
48
|
-
/** Chat/conversation identifier on the external platform */
|
|
49
|
-
chatId: string;
|
|
50
|
-
/** Chat type */
|
|
51
|
-
chatType?: 'direct' | 'group' | 'channel';
|
|
52
|
-
/** Text content */
|
|
53
|
-
text?: string;
|
|
54
|
-
/** Media attachments */
|
|
55
|
-
media?: IMediaAttachment[];
|
|
56
|
-
/** Whether this is a reply to another message */
|
|
57
|
-
replyToExternalId?: string;
|
|
58
|
-
/** Unix timestamp in ms */
|
|
59
|
-
timestamp: number;
|
|
60
|
-
/** Raw payload from the external platform (for debugging/passthrough) */
|
|
61
|
-
raw?: Record<string, unknown>;
|
|
62
|
-
}
|
|
63
|
-
/** An outbound message from the gateway to an external channel */
|
|
64
|
-
export interface IOutboundMessage {
|
|
65
|
-
/** Channel provider identifier */
|
|
66
|
-
channelType: string;
|
|
67
|
-
/** Account ID within the channel provider */
|
|
68
|
-
accountId: string;
|
|
69
|
-
/** Target chat/conversation identifier */
|
|
70
|
-
chatId: string;
|
|
71
|
-
/** Text content */
|
|
72
|
-
text?: string;
|
|
73
|
-
/** Media attachments */
|
|
74
|
-
media?: IMediaAttachment[];
|
|
75
|
-
/** Reply to a specific external message ID */
|
|
76
|
-
replyToExternalId?: string;
|
|
77
|
-
/** Arbitrary metadata */
|
|
78
|
-
metadata?: Record<string, unknown>;
|
|
79
|
-
}
|
|
80
|
-
/** Result of sending an outbound message */
|
|
81
|
-
export interface ISendResult {
|
|
82
|
-
success: boolean;
|
|
83
|
-
/** External message ID assigned by the platform */
|
|
84
|
-
externalId?: string;
|
|
85
|
-
/** Error message if failed */
|
|
86
|
-
error?: string;
|
|
87
|
-
/** Timestamp of delivery (Unix ms) */
|
|
88
|
-
timestamp?: number;
|
|
89
|
-
}
|
|
90
|
-
/** Who is responsible for persisting chat messages to the DB. */
|
|
91
|
-
export type PersistenceMode = 'backend' | 'frontend';
|
|
92
|
-
/** Configuration schema for a channel provider (declared in contributes.channels) */
|
|
93
|
-
export interface IChannelProviderConfig {
|
|
94
|
-
/** Unique provider type identifier (e.g. 'whatsapp', 'telegram') */
|
|
95
|
-
type: string;
|
|
96
|
-
/** Human-readable label */
|
|
97
|
-
label: string;
|
|
98
|
-
/** Provider description */
|
|
99
|
-
description?: string;
|
|
100
|
-
/** Icon name or URL */
|
|
101
|
-
icon?: string;
|
|
102
|
-
/** Provider capabilities */
|
|
103
|
-
capabilities: IChannelCapabilities;
|
|
104
|
-
/** Dock (outbound constraints, streaming, threading config) */
|
|
105
|
-
dock?: Partial<IChannelDock>;
|
|
106
|
-
/** JSON Schema for provider-specific configuration (API keys, tokens, etc.) */
|
|
107
|
-
configSchema?: Record<string, unknown>;
|
|
108
|
-
/**
|
|
109
|
-
* Who persists chat messages.
|
|
110
|
-
* - `'backend'` — the gateway streaming pipeline saves messages; UI should skip auto-save.
|
|
111
|
-
* - `'frontend'` — the UI saves messages via sendMessagesMutation (default).
|
|
112
|
-
*/
|
|
113
|
-
persistenceMode?: PersistenceMode;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* IExternalChannelProvider — the interface that channel extensions implement.
|
|
117
|
-
*
|
|
118
|
-
* Each extension contributes one provider. The gateway discovers providers
|
|
119
|
-
* via `contributes.channels` in the extension manifest and calls
|
|
120
|
-
* `channels.registerProvider(provider)` during extension activation.
|
|
121
|
-
*
|
|
122
|
-
* Go mapping:
|
|
123
|
-
* type ChannelProvider interface {
|
|
124
|
-
* Type() string
|
|
125
|
-
* Connect(ctx context.Context, accountId string, config map[string]any) error
|
|
126
|
-
* Disconnect(ctx context.Context, accountId string) error
|
|
127
|
-
* Send(ctx context.Context, msg OutboundMessage) (SendResult, error)
|
|
128
|
-
* State(accountId string) ProviderState
|
|
129
|
-
* OnMessage(handler func(InboundMessage))
|
|
130
|
-
* }
|
|
131
|
-
*/
|
|
132
|
-
export interface IExternalChannelProvider {
|
|
133
|
-
/** Provider type identifier (e.g. 'whatsapp') */
|
|
134
|
-
readonly type: string;
|
|
135
|
-
/** Provider configuration */
|
|
136
|
-
readonly config: IChannelProviderConfig;
|
|
137
|
-
/**
|
|
138
|
-
* Connect an account to the external platform.
|
|
139
|
-
* @param accountId - Unique account identifier
|
|
140
|
-
* @param options - Provider-specific connection options (API keys, session data, etc.)
|
|
141
|
-
* @param signal - AbortSignal for cancellation (Go: context.Context)
|
|
142
|
-
*/
|
|
143
|
-
connect(accountId: string, options: Record<string, unknown>, signal?: AbortSignal): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Disconnect an account from the external platform.
|
|
146
|
-
* @param accountId - Account to disconnect
|
|
147
|
-
*/
|
|
148
|
-
disconnect(accountId: string): Promise<void>;
|
|
149
|
-
/**
|
|
150
|
-
* Send a message to the external platform.
|
|
151
|
-
* @param message - Outbound message to send
|
|
152
|
-
* @returns Send result with external ID on success
|
|
153
|
-
*/
|
|
154
|
-
send(message: IOutboundMessage): Promise<ISendResult>;
|
|
155
|
-
/**
|
|
156
|
-
* Get the current connection state for an account.
|
|
157
|
-
* @param accountId - Account identifier
|
|
158
|
-
*/
|
|
159
|
-
getState(accountId: string): ProviderState;
|
|
160
|
-
/**
|
|
161
|
-
* Get a snapshot of account status (connection info, last message times, etc.)
|
|
162
|
-
* @param accountId - Account identifier
|
|
163
|
-
*/
|
|
164
|
-
getAccountSnapshot(accountId: string): IChannelAccountSnapshot | undefined;
|
|
165
|
-
/**
|
|
166
|
-
* Get any status issues (config problems, auth failures, etc.)
|
|
167
|
-
* @param accountId - Account identifier
|
|
168
|
-
*/
|
|
169
|
-
getStatusIssues(accountId: string): IChannelStatusIssue[];
|
|
170
|
-
/**
|
|
171
|
-
* Register a handler for inbound messages.
|
|
172
|
-
* The gateway calls this once during provider registration.
|
|
173
|
-
* @param handler - Callback invoked for each inbound message
|
|
174
|
-
*/
|
|
175
|
-
onMessage(handler: (message: IInboundMessage) => void): void;
|
|
176
|
-
/**
|
|
177
|
-
* Register a handler for provider state changes.
|
|
178
|
-
* @param handler - Callback invoked when connection state changes
|
|
179
|
-
*/
|
|
180
|
-
onStateChange?(handler: (accountId: string, state: ProviderState) => void): void;
|
|
181
|
-
/**
|
|
182
|
-
* Dispose all resources. Called when the extension is deactivated.
|
|
183
|
-
*/
|
|
184
|
-
dispose(): Promise<void>;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* IExternalChannelRegistry — tracks all registered external channel providers.
|
|
188
|
-
*
|
|
189
|
-
* Providers register themselves via extension activation; the gateway looks
|
|
190
|
-
* them up by type when routing messages.
|
|
191
|
-
*
|
|
192
|
-
* Go mapping:
|
|
193
|
-
* type ChannelRegistry struct { providers map[string]ChannelProvider }
|
|
194
|
-
*/
|
|
195
|
-
export interface IExternalChannelRegistry {
|
|
196
|
-
/** Register a channel provider (called during extension activation) */
|
|
197
|
-
register(provider: IExternalChannelProvider): void;
|
|
198
|
-
/** Unregister a channel provider (called during extension deactivation) */
|
|
199
|
-
unregister(providerType: string): void;
|
|
200
|
-
/** Get a provider by type */
|
|
201
|
-
get(providerType: string): IExternalChannelProvider | undefined;
|
|
202
|
-
/** List all registered provider types */
|
|
203
|
-
listTypes(): string[];
|
|
204
|
-
/** List all providers with their configs */
|
|
205
|
-
listProviders(): IChannelProviderConfig[];
|
|
206
|
-
/** Check if a provider type is registered */
|
|
207
|
-
has(providerType: string): boolean;
|
|
208
|
-
}
|
|
209
|
-
/** Gateway status for a single provider/account pair */
|
|
210
|
-
export interface IGatewayChannelStatus {
|
|
211
|
-
channelType: string;
|
|
212
|
-
accountId: string;
|
|
213
|
-
state: ProviderState;
|
|
214
|
-
label: string;
|
|
215
|
-
snapshot?: IChannelAccountSnapshot;
|
|
216
|
-
issues: IChannelStatusIssue[];
|
|
217
|
-
/** Who persists chat messages — 'backend' or 'frontend' (default). */
|
|
218
|
-
persistenceMode?: PersistenceMode;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* IGatewayService — the top-level gateway orchestrator.
|
|
222
|
-
*
|
|
223
|
-
* Owns the channel registry, routes inbound messages to the platform,
|
|
224
|
-
* and dispatches outbound messages to the correct provider.
|
|
225
|
-
*
|
|
226
|
-
* Go mapping:
|
|
227
|
-
* type GatewayService struct {
|
|
228
|
-
* registry *ChannelRegistry
|
|
229
|
-
* router *MessageRouter
|
|
230
|
-
* eventBus *nats.Conn
|
|
231
|
-
* }
|
|
232
|
-
*/
|
|
233
|
-
export interface IGatewayService {
|
|
234
|
-
/** Initialize the gateway (called once at startup) */
|
|
235
|
-
initialize(): Promise<void>;
|
|
236
|
-
/** Shut down the gateway gracefully */
|
|
237
|
-
shutdown(): Promise<void>;
|
|
238
|
-
/** Get the channel registry */
|
|
239
|
-
getRegistry(): IExternalChannelRegistry;
|
|
240
|
-
/** Connect an account on a specific channel */
|
|
241
|
-
connectChannel(channelType: string, accountId: string, options: Record<string, unknown>): Promise<void>;
|
|
242
|
-
/** Disconnect an account on a specific channel */
|
|
243
|
-
disconnectChannel(channelType: string, accountId: string): Promise<void>;
|
|
244
|
-
/** Send an outbound message via the appropriate provider */
|
|
245
|
-
sendMessage(message: IOutboundMessage): Promise<ISendResult>;
|
|
246
|
-
/** Get status for all connected channels/accounts */
|
|
247
|
-
getStatus(): IGatewayChannelStatus[];
|
|
248
|
-
/** Get status for a specific channel type */
|
|
249
|
-
getChannelStatus(channelType: string): IGatewayChannelStatus[];
|
|
250
|
-
/**
|
|
251
|
-
* Register a handler for inbound messages (gateway → platform).
|
|
252
|
-
* The resolver/microservice uses this to feed messages into the platform.
|
|
253
|
-
*/
|
|
254
|
-
onInboundMessage(handler: (message: IInboundMessage) => void): void;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* IMessageRouterService — routes inbound messages to the messenger platform.
|
|
258
|
-
*
|
|
259
|
-
* Sits between external channel providers and the platform's channel/post
|
|
260
|
-
* services. Translates IInboundMessage into platform Post creation.
|
|
261
|
-
*
|
|
262
|
-
* Go mapping:
|
|
263
|
-
* type MessageRouter struct { channelSvc ChannelService; postSvc PostService }
|
|
264
|
-
*/
|
|
265
|
-
export interface IMessageRouterService {
|
|
266
|
-
/** Route an inbound message to the platform */
|
|
267
|
-
routeInbound(message: IInboundMessage): Promise<void>;
|
|
268
|
-
/** Route an outbound message from the platform to the external channel */
|
|
269
|
-
routeOutbound(message: IOutboundMessage): Promise<ISendResult>;
|
|
270
|
-
}
|
|
271
|
-
/** Topic for gateway inbound messages */
|
|
272
|
-
export declare const GATEWAY_INBOUND_TOPIC = "GATEWAY_INBOUND";
|
|
273
|
-
/** Topic for gateway outbound messages */
|
|
274
|
-
export declare const GATEWAY_OUTBOUND_TOPIC = "GATEWAY_OUTBOUND";
|
|
275
|
-
/** Topic for gateway channel status changes */
|
|
276
|
-
export declare const GATEWAY_STATUS_TOPIC = "GATEWAY_STATUS";
|
|
277
|
-
/** Build a scoped topic for a specific channel type */
|
|
278
|
-
export declare function gatewayInboundTopic(channelType: string): string;
|
|
279
|
-
export declare function gatewayOutboundTopic(channelType: string): string;
|
|
280
|
-
export declare function gatewayStatusTopic(channelType: string): string;
|