@xpert-ai/plugin-community-wechat 0.1.0
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 +353 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +139 -0
- package/dist/lib/constants.d.ts +23 -0
- package/dist/lib/constants.js +23 -0
- package/dist/lib/conversation-user-key.d.ts +13 -0
- package/dist/lib/conversation-user-key.js +28 -0
- package/dist/lib/conversation.service.d.ts +215 -0
- package/dist/lib/conversation.service.js +1179 -0
- package/dist/lib/decorators.d.ts +2 -0
- package/dist/lib/decorators.js +3 -0
- package/dist/lib/entities/index.d.ts +4 -0
- package/dist/lib/entities/index.js +4 -0
- package/dist/lib/entities/wechat-personal-account.entity.d.ts +19 -0
- package/dist/lib/entities/wechat-personal-account.entity.js +83 -0
- package/dist/lib/entities/wechat-personal-conversation-binding.entity.d.ts +14 -0
- package/dist/lib/entities/wechat-personal-conversation-binding.entity.js +65 -0
- package/dist/lib/entities/wechat-personal-message-log.entity.d.ts +27 -0
- package/dist/lib/entities/wechat-personal-message-log.entity.js +108 -0
- package/dist/lib/entities/wechat-personal-trigger-binding.entity.d.ts +17 -0
- package/dist/lib/entities/wechat-personal-trigger-binding.entity.js +71 -0
- package/dist/lib/handoff/index.d.ts +4 -0
- package/dist/lib/handoff/index.js +4 -0
- package/dist/lib/handoff/wechat-personal-chat-callback.processor.d.ts +26 -0
- package/dist/lib/handoff/wechat-personal-chat-callback.processor.js +312 -0
- package/dist/lib/handoff/wechat-personal-chat-dispatch.service.d.ts +26 -0
- package/dist/lib/handoff/wechat-personal-chat-dispatch.service.js +187 -0
- package/dist/lib/handoff/wechat-personal-chat-run-state.service.d.ts +21 -0
- package/dist/lib/handoff/wechat-personal-chat-run-state.service.js +39 -0
- package/dist/lib/handoff/wechat-personal-chat.types.d.ts +69 -0
- package/dist/lib/handoff/wechat-personal-chat.types.js +2 -0
- package/dist/lib/message.d.ts +49 -0
- package/dist/lib/message.js +64 -0
- package/dist/lib/remote-components/wechat-personal-workbench/app.js +1831 -0
- package/dist/lib/tokens.d.ts +1 -0
- package/dist/lib/tokens.js +1 -0
- package/dist/lib/types.d.ts +48 -0
- package/dist/lib/types.js +365 -0
- package/dist/lib/views/wechat-personal-view.provider.d.ts +17 -0
- package/dist/lib/views/wechat-personal-view.provider.js +441 -0
- package/dist/lib/wechat-personal-channel.strategy.d.ts +33 -0
- package/dist/lib/wechat-personal-channel.strategy.js +197 -0
- package/dist/lib/wechat-personal-integration.strategy.d.ts +56 -0
- package/dist/lib/wechat-personal-integration.strategy.js +217 -0
- package/dist/lib/wechat-personal.client.d.ts +29 -0
- package/dist/lib/wechat-personal.client.js +146 -0
- package/dist/lib/wechat-personal.controller.d.ts +50 -0
- package/dist/lib/wechat-personal.controller.js +270 -0
- package/dist/lib/wechat-personal.middleware.d.ts +20 -0
- package/dist/lib/wechat-personal.middleware.js +267 -0
- package/dist/lib/wechat-personal.plugin.d.ts +2 -0
- package/dist/lib/wechat-personal.plugin.js +58 -0
- package/dist/lib/wechat-personal.templates.d.ts +2 -0
- package/dist/lib/wechat-personal.templates.js +100 -0
- package/dist/lib/workflow/index.d.ts +5 -0
- package/dist/lib/workflow/index.js +5 -0
- package/dist/lib/workflow/wechat-personal-trigger-aggregation.service.d.ts +10 -0
- package/dist/lib/workflow/wechat-personal-trigger-aggregation.service.js +39 -0
- package/dist/lib/workflow/wechat-personal-trigger-aggregation.types.d.ts +30 -0
- package/dist/lib/workflow/wechat-personal-trigger-aggregation.types.js +2 -0
- package/dist/lib/workflow/wechat-personal-trigger-flush.processor.d.ts +8 -0
- package/dist/lib/workflow/wechat-personal-trigger-flush.processor.js +39 -0
- package/dist/lib/workflow/wechat-personal-trigger.strategy.d.ts +65 -0
- package/dist/lib/workflow/wechat-personal-trigger.strategy.js +511 -0
- package/dist/lib/workflow/wechat-personal-trigger.types.d.ts +10 -0
- package/dist/lib/workflow/wechat-personal-trigger.types.js +2 -0
- package/dist/xpert-wechat-personal-admin-assistant.yaml +103 -0
- package/dist/xpert-wechat-personal-user-assistant.yaml +127 -0
- package/package.json +79 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { TChatEventContext, type PluginContext } from '@xpert-ai/plugin-sdk';
|
|
2
|
+
import { type Cache } from 'cache-manager';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { TIntegrationWechatPersonalOptions, WechatPersonalInboundEvent } from './types.js';
|
|
5
|
+
import { WechatPersonalChannelStrategy } from './wechat-personal-channel.strategy.js';
|
|
6
|
+
import { WechatPersonalAccountEntity, WechatPersonalConversationBindingEntity, WechatPersonalMessageDirection, WechatPersonalMessageLogEntity, WechatPersonalMessageLogStatus } from './entities/index.js';
|
|
7
|
+
import { WechatPersonalTriggerStrategy } from './workflow/wechat-personal-trigger.strategy.js';
|
|
8
|
+
import { WechatPersonalChatCallbackContext } from './handoff/wechat-personal-chat.types.js';
|
|
9
|
+
type WechatPersonalTenantScope = {
|
|
10
|
+
tenantId?: string | null;
|
|
11
|
+
organizationId?: string | null;
|
|
12
|
+
};
|
|
13
|
+
type WechatPersonalConversationState = {
|
|
14
|
+
conversationId: string;
|
|
15
|
+
lastActiveAt?: Date;
|
|
16
|
+
};
|
|
17
|
+
export type WechatPersonalConversationListItem = {
|
|
18
|
+
id: string;
|
|
19
|
+
integrationId: string;
|
|
20
|
+
uuid: string;
|
|
21
|
+
contactId: string;
|
|
22
|
+
senderId: string;
|
|
23
|
+
chatType: 'private' | 'group';
|
|
24
|
+
xpertId: string;
|
|
25
|
+
conversationId: string;
|
|
26
|
+
updatedAt: Date | null;
|
|
27
|
+
};
|
|
28
|
+
export type WechatPersonalIntegrationWorkbenchItem = {
|
|
29
|
+
id: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
slug?: string;
|
|
33
|
+
callbackConfig: ReturnType<WechatPersonalConversationService['buildCallbackConfig']>;
|
|
34
|
+
accountCount: number;
|
|
35
|
+
conversationCount: number;
|
|
36
|
+
recentMessageCount: number;
|
|
37
|
+
errorCount: number;
|
|
38
|
+
config: Partial<TIntegrationWechatPersonalOptions>;
|
|
39
|
+
};
|
|
40
|
+
export type WechatPersonalWorkbenchData = {
|
|
41
|
+
scope?: 'integration' | 'organization';
|
|
42
|
+
integrationId?: string | null;
|
|
43
|
+
integrations?: WechatPersonalIntegrationWorkbenchItem[];
|
|
44
|
+
callbackConfig: {
|
|
45
|
+
webhookUrl: string;
|
|
46
|
+
globalWebhookUrl: string;
|
|
47
|
+
setCallbackUrlTemplate: string;
|
|
48
|
+
setCallbackCurlTemplate: string;
|
|
49
|
+
};
|
|
50
|
+
summary: {
|
|
51
|
+
integrationCount?: number;
|
|
52
|
+
accountCount: number;
|
|
53
|
+
conversationCount: number;
|
|
54
|
+
recentMessageCount: number;
|
|
55
|
+
errorCount: number;
|
|
56
|
+
};
|
|
57
|
+
accounts: WechatPersonalAccountEntity[];
|
|
58
|
+
conversations: WechatPersonalConversationListItem[];
|
|
59
|
+
messages: WechatPersonalMessageLogEntity[];
|
|
60
|
+
logs: WechatPersonalMessageLogEntity[];
|
|
61
|
+
tables?: Partial<Record<WechatPersonalWorkbenchTableKey, WechatPersonalWorkbenchTableResult>>;
|
|
62
|
+
config: Partial<TIntegrationWechatPersonalOptions>;
|
|
63
|
+
};
|
|
64
|
+
export type WechatPersonalPagedResult<T> = {
|
|
65
|
+
items: T[];
|
|
66
|
+
total: number;
|
|
67
|
+
page: number;
|
|
68
|
+
pageSize: number;
|
|
69
|
+
};
|
|
70
|
+
export type WechatPersonalWorkbenchTableKey = 'accounts' | 'conversations' | 'messages' | 'logs';
|
|
71
|
+
export type WechatPersonalWorkbenchTableQuery = {
|
|
72
|
+
search?: string;
|
|
73
|
+
page?: number;
|
|
74
|
+
pageSize?: number;
|
|
75
|
+
filters?: Record<string, unknown> | null;
|
|
76
|
+
};
|
|
77
|
+
export type WechatPersonalWorkbenchTableResult = (WechatPersonalPagedResult<WechatPersonalAccountEntity> & {
|
|
78
|
+
key: 'accounts';
|
|
79
|
+
}) | (WechatPersonalPagedResult<WechatPersonalConversationListItem> & {
|
|
80
|
+
key: 'conversations';
|
|
81
|
+
}) | (WechatPersonalPagedResult<WechatPersonalMessageLogEntity> & {
|
|
82
|
+
key: 'messages' | 'logs';
|
|
83
|
+
});
|
|
84
|
+
export type WechatPersonalRuntimeStatus = {
|
|
85
|
+
callbackConfig: WechatPersonalWorkbenchData['callbackConfig'];
|
|
86
|
+
summary: WechatPersonalWorkbenchData['summary'];
|
|
87
|
+
triggerBinding: {
|
|
88
|
+
integrationId: string;
|
|
89
|
+
xpertId: string;
|
|
90
|
+
sessionTimeoutSeconds: number;
|
|
91
|
+
summaryWindowSeconds: number;
|
|
92
|
+
groupTriggerMode: string;
|
|
93
|
+
groupKeywords: string[];
|
|
94
|
+
updatedAt: Date | null;
|
|
95
|
+
} | null;
|
|
96
|
+
accounts: WechatPersonalAccountEntity[];
|
|
97
|
+
recentErrors: WechatPersonalMessageLogEntity[];
|
|
98
|
+
config: Partial<TIntegrationWechatPersonalOptions>;
|
|
99
|
+
integrations?: WechatPersonalIntegrationWorkbenchItem[];
|
|
100
|
+
scope?: 'integration' | 'organization';
|
|
101
|
+
};
|
|
102
|
+
export declare class WechatPersonalConversationService {
|
|
103
|
+
private readonly wechatChannel;
|
|
104
|
+
private readonly triggerStrategy;
|
|
105
|
+
private readonly cacheManager;
|
|
106
|
+
private readonly conversationBindingRepository;
|
|
107
|
+
private readonly accountRepository;
|
|
108
|
+
private readonly messageLogRepository;
|
|
109
|
+
private readonly pluginContext;
|
|
110
|
+
private readonly logger;
|
|
111
|
+
private _integrationPermissionService;
|
|
112
|
+
constructor(wechatChannel: WechatPersonalChannelStrategy, triggerStrategy: WechatPersonalTriggerStrategy, cacheManager: Cache, conversationBindingRepository: Repository<WechatPersonalConversationBindingEntity>, accountRepository: Repository<WechatPersonalAccountEntity>, messageLogRepository: Repository<WechatPersonalMessageLogEntity>, pluginContext: PluginContext);
|
|
113
|
+
private get integrationPermissionService();
|
|
114
|
+
getConversationState(conversationUserKey: string, xpertId: string, scopeOverride?: WechatPersonalTenantScope | null): Promise<WechatPersonalConversationState | undefined>;
|
|
115
|
+
setConversation(conversationUserKey: string, xpertId: string, conversationId: string, lastActiveAt?: Date | undefined, scopeOverride?: WechatPersonalTenantScope | null): Promise<void>;
|
|
116
|
+
touchConversation(conversationUserKey: string, xpertId: string, lastActiveAt?: Date, scopeOverride?: WechatPersonalTenantScope | null): Promise<void>;
|
|
117
|
+
clearConversation(conversationUserKey: string, xpertId: string, scopeOverride?: WechatPersonalTenantScope | null): Promise<void>;
|
|
118
|
+
restartConversationBinding(integrationId: string, bindingId: string): Promise<void>;
|
|
119
|
+
handleInboundEvent(event: WechatPersonalInboundEvent, ctx: TChatEventContext<TIntegrationWechatPersonalOptions>): Promise<{
|
|
120
|
+
handled: boolean;
|
|
121
|
+
reason?: string;
|
|
122
|
+
}>;
|
|
123
|
+
logOutbound(params: {
|
|
124
|
+
context: WechatPersonalChatCallbackContext;
|
|
125
|
+
content: string;
|
|
126
|
+
status: WechatPersonalMessageLogStatus;
|
|
127
|
+
messageId?: string;
|
|
128
|
+
error?: string;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
setAccountEnabled(integrationId: string, uuid: string, enabled: boolean): Promise<void>;
|
|
131
|
+
resendOutboundMessage(integrationId: string, logId?: string): Promise<{
|
|
132
|
+
success: boolean;
|
|
133
|
+
messageId?: string;
|
|
134
|
+
error?: string;
|
|
135
|
+
}>;
|
|
136
|
+
getWorkbenchData(integrationId: string, query?: {
|
|
137
|
+
search?: string;
|
|
138
|
+
page?: number;
|
|
139
|
+
pageSize?: number;
|
|
140
|
+
}): Promise<WechatPersonalWorkbenchData>;
|
|
141
|
+
getOrganizationWorkbenchData(query?: {
|
|
142
|
+
search?: string;
|
|
143
|
+
page?: number;
|
|
144
|
+
pageSize?: number;
|
|
145
|
+
}): Promise<WechatPersonalWorkbenchData>;
|
|
146
|
+
getRuntimeStatus(integrationId: string): Promise<WechatPersonalRuntimeStatus>;
|
|
147
|
+
getOrganizationRuntimeStatus(): Promise<WechatPersonalRuntimeStatus>;
|
|
148
|
+
getBoundIntegrationIdForXpert(xpertId: string): Promise<string | null>;
|
|
149
|
+
getWorkbenchTableData(integrationId: string, table: WechatPersonalWorkbenchTableKey, query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalWorkbenchTableResult>;
|
|
150
|
+
getOrganizationWorkbenchTableData(table: WechatPersonalWorkbenchTableKey, query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalWorkbenchTableResult>;
|
|
151
|
+
listAccounts(integrationId: string, query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalPagedResult<WechatPersonalAccountEntity>>;
|
|
152
|
+
listOrganizationAccounts(query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalPagedResult<WechatPersonalAccountEntity>>;
|
|
153
|
+
listConversations(integrationId: string, query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalPagedResult<WechatPersonalConversationListItem>>;
|
|
154
|
+
listOrganizationConversations(query?: WechatPersonalWorkbenchTableQuery): Promise<WechatPersonalPagedResult<WechatPersonalConversationListItem>>;
|
|
155
|
+
searchMessageLogs(integrationId: string, query?: {
|
|
156
|
+
direction?: WechatPersonalMessageDirection;
|
|
157
|
+
status?: WechatPersonalMessageLogStatus;
|
|
158
|
+
search?: string;
|
|
159
|
+
page?: number;
|
|
160
|
+
pageSize?: number;
|
|
161
|
+
filters?: Record<string, unknown> | null;
|
|
162
|
+
}): Promise<WechatPersonalPagedResult<WechatPersonalMessageLogEntity>>;
|
|
163
|
+
searchOrganizationMessageLogs(query?: {
|
|
164
|
+
direction?: WechatPersonalMessageDirection;
|
|
165
|
+
status?: WechatPersonalMessageLogStatus;
|
|
166
|
+
search?: string;
|
|
167
|
+
page?: number;
|
|
168
|
+
pageSize?: number;
|
|
169
|
+
filters?: Record<string, unknown> | null;
|
|
170
|
+
}): Promise<WechatPersonalPagedResult<WechatPersonalMessageLogEntity>>;
|
|
171
|
+
buildCallbackConfig(integrationId: string, callbackSecret?: string): {
|
|
172
|
+
webhookUrl: string;
|
|
173
|
+
globalWebhookUrl: string;
|
|
174
|
+
setCallbackUrlTemplate: string;
|
|
175
|
+
setCallbackCurlTemplate: string;
|
|
176
|
+
};
|
|
177
|
+
private upsertAccount;
|
|
178
|
+
private isDuplicateInbound;
|
|
179
|
+
private logInbound;
|
|
180
|
+
private updateLog;
|
|
181
|
+
private getConversationCacheKey;
|
|
182
|
+
private cacheConversation;
|
|
183
|
+
private resolveTenantScope;
|
|
184
|
+
private readIntegrationTenantScope;
|
|
185
|
+
private scopedWhere;
|
|
186
|
+
private resolveBindingContext;
|
|
187
|
+
private resolveExecutionUserId;
|
|
188
|
+
private listWechatPersonalIntegrations;
|
|
189
|
+
private toIntegrationWorkbenchItem;
|
|
190
|
+
private sanitizeIntegrationConfig;
|
|
191
|
+
private emptyCallbackConfig;
|
|
192
|
+
private matchesAccountFilters;
|
|
193
|
+
private matchesConversationFilters;
|
|
194
|
+
private matchesLogFilters;
|
|
195
|
+
private normalizeFilters;
|
|
196
|
+
private matchesFilter;
|
|
197
|
+
private normalizeBooleanFilter;
|
|
198
|
+
private normalizeDirection;
|
|
199
|
+
private normalizeLogStatus;
|
|
200
|
+
private normalizeChatType;
|
|
201
|
+
private matchesConversationSearch;
|
|
202
|
+
private matchesLogSearch;
|
|
203
|
+
private toConversationListItem;
|
|
204
|
+
private normalizePositiveInt;
|
|
205
|
+
private normalizePage;
|
|
206
|
+
private normalizePageSize;
|
|
207
|
+
private paginateItems;
|
|
208
|
+
private normalizeListSearch;
|
|
209
|
+
private normalizeDate;
|
|
210
|
+
private resolveSessionTimeoutMs;
|
|
211
|
+
private isConversationExpired;
|
|
212
|
+
private parseNewSessionCommand;
|
|
213
|
+
private getNewConversationStartedText;
|
|
214
|
+
}
|
|
215
|
+
export {};
|