@futdevpro/nts-dynamo 1.14.12 → 1.14.14
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/.vscode/settings.json +11 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-document.data-service.js +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-document.data-service.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.js +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.js.map +1 -1
- package/build/_modules/bot/_enums/bot-provider.enum.d.ts +1 -0
- package/build/_modules/bot/_enums/bot-provider.enum.d.ts.map +1 -1
- package/build/_modules/bot/_enums/bot-provider.enum.js +1 -0
- package/build/_modules/bot/_enums/bot-provider.enum.js.map +1 -1
- package/build/_modules/bot/_models/bot-provider.interface.d.ts +5 -0
- package/build/_modules/bot/_models/bot-provider.interface.d.ts.map +1 -1
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.d.ts +17 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.d.ts.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.js +43 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.js.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb.util.d.ts +5 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb.util.d.ts.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb.util.js +26 -0
- package/build/_modules/bot/_modules/dynamo-bot/_collections/dyb.util.js.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.d.ts +10 -0
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.d.ts.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.js +3 -0
- package/build/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.js.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.d.ts +54 -0
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.d.ts.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.js +310 -0
- package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.js.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/index.d.ts +5 -0
- package/build/_modules/bot/_modules/dynamo-bot/index.d.ts.map +1 -0
- package/build/_modules/bot/_modules/dynamo-bot/index.js +17 -0
- package/build/_modules/bot/_modules/dynamo-bot/index.js.map +1 -0
- package/build/_modules/bot/_services/bot-provider-factory.service.d.ts.map +1 -1
- package/build/_modules/bot/_services/bot-provider-factory.service.js +3 -0
- package/build/_modules/bot/_services/bot-provider-factory.service.js.map +1 -1
- package/build/_modules/bot/index.d.ts +1 -0
- package/build/_modules/bot/index.d.ts.map +1 -1
- package/build/_modules/bot/index.js +1 -0
- package/build/_modules/bot/index.js.map +1 -1
- package/build/_modules/messaging/_services/msg.controller.js.map +1 -1
- package/build/_services/base/data.service.js +4 -4
- package/build/_services/base/data.service.js.map +1 -1
- package/eslint.config.js +3 -0
- package/package.json +16 -4
- package/src/_modules/ai/_modules/open-ai/_services/oai-document.data-service.ts +1 -1
- package/src/_modules/ai/_modules/open-ai/_services/oai-vector-data.service.ts +1 -1
- package/src/_modules/bot/_enums/bot-provider.enum.ts +1 -0
- package/src/_modules/bot/_models/bot-provider.interface.ts +5 -0
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +52 -0
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb.util.ts +26 -0
- package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +15 -0
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.ts +399 -0
- package/src/_modules/bot/_modules/dynamo-bot/index.ts +16 -0
- package/src/_modules/bot/_services/bot-provider-factory.service.ts +4 -0
- package/src/_modules/bot/index.ts +1 -0
- package/src/_modules/messaging/_services/msg.controller.ts +1 -1
- package/src/_services/base/data.service.ts +4 -4
- package/.eslintrc.json +0 -186
- package/build/_modules/messaging/get-messaging-routing-module.util.d.ts +0 -8
- package/build/_modules/messaging/get-messaging-routing-module.util.d.ts.map +0 -1
- package/build/_modules/messaging/get-messaging-routing-module.util.js +0 -21
- package/build/_modules/messaging/get-messaging-routing-module.util.js.map +0 -1
- package/build/_modules/messaging/messaging.controller.d.ts +0 -13
- package/build/_modules/messaging/messaging.controller.d.ts.map +0 -1
- package/build/_modules/messaging/messaging.controller.js +0 -257
- package/build/_modules/messaging/messaging.controller.js.map +0 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { DyFM_Error, DyFM_Log, week } from '@futdevpro/fsm-dynamo';
|
|
2
|
+
import { DyNTS_Bot_Provider, DyNTS_Bot_Provider_Config } from '../../../_models/bot-provider.interface';
|
|
3
|
+
import { DyNTS_Bot_LastMessageDate } from '../../../_models/bot-last-message-date.interface';
|
|
4
|
+
import { DyNTS_Bot_LastMentionDate } from '../../../_models/bot-last-mention-date.interface';
|
|
5
|
+
import { DyNTS_Bot_Provider_Type } from '../../../_enums/bot-provider.enum';
|
|
6
|
+
import { DyNTS_DyB_Message, DyNTS_DyB_Channel, DyNTS_DyB_User } from '../_models/dyb-platform.types';
|
|
7
|
+
import { DyNTS_global_settings } from '../../../../../_collections/global-settings.const';
|
|
8
|
+
import { DyNTS_Msg_Main_ControlService } from '../../../../messaging/_services/msg-main.control-service';
|
|
9
|
+
import { DyNTS_Msg_Message_DataService } from '../../../../messaging/_services/msg-message.data-service';
|
|
10
|
+
import { DyNTS_Msg_Conversation_DataService } from '../../../../messaging/_services/msg-conversation.data-service';
|
|
11
|
+
import { DyNTS_Msg_Events_Service } from '../../../../messaging/_services/msg-events.service';
|
|
12
|
+
import { DyFM_Msg_Conversation, DyFM_Msg_EventKey, DyFM_Msg_Message, DyFM_Msg_Participant } from '@futdevpro/fsm-dynamo/messaging';
|
|
13
|
+
|
|
14
|
+
export class DyNTS_DyB_Provider implements DyNTS_Bot_Provider<
|
|
15
|
+
DyNTS_DyB_Channel,
|
|
16
|
+
DyNTS_DyB_Message,
|
|
17
|
+
DyNTS_DyB_User
|
|
18
|
+
> {
|
|
19
|
+
private isInitialized: boolean = false;
|
|
20
|
+
private config: DyNTS_Bot_Provider_Config;
|
|
21
|
+
private conversationCache: Map<string, DyNTS_DyB_Channel>;
|
|
22
|
+
private userCache: Map<string, DyNTS_DyB_User>;
|
|
23
|
+
|
|
24
|
+
// Event handlers
|
|
25
|
+
private messageHandlers: Array<(message: DyNTS_DyB_Message, issuer: string) => void> = [];
|
|
26
|
+
private readyHandlers: Array<() => void> = [];
|
|
27
|
+
private errorHandlers: Array<(error: Error) => void> = [];
|
|
28
|
+
|
|
29
|
+
// Services
|
|
30
|
+
private messagingService: DyNTS_Msg_Main_ControlService;
|
|
31
|
+
private eventsService: DyNTS_Msg_Events_Service;
|
|
32
|
+
|
|
33
|
+
constructor() {
|
|
34
|
+
this.conversationCache = new Map();
|
|
35
|
+
this.userCache = new Map();
|
|
36
|
+
this.messagingService = DyNTS_Msg_Main_ControlService.getInstance();
|
|
37
|
+
this.eventsService = DyNTS_Msg_Events_Service.getInstance();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async initialize(config: DyNTS_Bot_Provider_Config): Promise<void> {
|
|
41
|
+
this.config = config;
|
|
42
|
+
|
|
43
|
+
if (config.provider !== DyNTS_Bot_Provider_Type.dynamo) {
|
|
44
|
+
throw new Error(`Invalid provider type: ${config.provider}. Expected 'dynamo'`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this.isInitialized = true;
|
|
48
|
+
DyFM_Log.success('Dynamo bot provider initialized');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async login(token?: string): Promise<void> {
|
|
52
|
+
if (!this.isInitialized) {
|
|
53
|
+
throw new Error('Provider not initialized. Call initialize() first.');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Setup event listeners for messaging events
|
|
57
|
+
this.setupEventListeners();
|
|
58
|
+
|
|
59
|
+
// Trigger ready handlers
|
|
60
|
+
this.readyHandlers.forEach(handler => handler());
|
|
61
|
+
|
|
62
|
+
DyFM_Log.success('Dynamo bot provider logged in');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private setupEventListeners(): void {
|
|
66
|
+
// Listen to messaging events and convert them to bot events
|
|
67
|
+
// Note: This would require extending the events service to support custom listeners
|
|
68
|
+
// For now, we'll implement a basic approach
|
|
69
|
+
DyFM_Log.info('Dynamo bot event listeners setup (messaging integration)');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Channel operations
|
|
73
|
+
async getChannelByName(name: string): Promise<DyNTS_DyB_Channel> {
|
|
74
|
+
if (this.conversationCache.has(name)) {
|
|
75
|
+
return this.conversationCache.get(name);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const conversationService: DyNTS_Msg_Conversation_DataService = new DyNTS_Msg_Conversation_DataService({
|
|
79
|
+
issuer: 'dynamo-bot',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Try to find conversation by name or platformChannelId
|
|
83
|
+
const conversation: DyFM_Msg_Conversation = await conversationService.dataDBService.findOne({
|
|
84
|
+
$or: [
|
|
85
|
+
{ name: name },
|
|
86
|
+
{ platformChannelId: name }
|
|
87
|
+
],
|
|
88
|
+
__deleted: { $exists: false }
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!conversation) {
|
|
92
|
+
throw new Error(`No conversation found with name "${name}"`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const channel: DyNTS_DyB_Channel = this.translateChannel(conversation);
|
|
96
|
+
this.conversationCache.set(name, channel);
|
|
97
|
+
return channel;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getChannelById(conversationId: string): Promise<DyNTS_DyB_Channel> {
|
|
101
|
+
const conversationService: DyNTS_Msg_Conversation_DataService = new DyNTS_Msg_Conversation_DataService({
|
|
102
|
+
issuer: 'dynamo-bot',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const conversation: DyFM_Msg_Conversation = await conversationService.getDataById(conversationId);
|
|
106
|
+
if (!conversation) {
|
|
107
|
+
throw new Error(`No conversation found with ID "${conversationId}"`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this.translateChannel(conversation);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async sendMessageToChannelByName(channelName: string, message: string): Promise<DyNTS_DyB_Message> {
|
|
114
|
+
const channel: DyNTS_DyB_Channel = await this.getChannelByName(channelName);
|
|
115
|
+
return this.sendMessage(channel.id, message);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getMessagesFromChannelByChannelName(channelName: string, limit: number = 100): Promise<DyNTS_DyB_Message[]> {
|
|
119
|
+
const channel: DyNTS_DyB_Channel = await this.getChannelByName(channelName);
|
|
120
|
+
return this.fetchMessages(channel.id, limit);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async getLastMessageInChannel(channelName: string): Promise<DyNTS_DyB_Message> {
|
|
124
|
+
const messages: DyNTS_DyB_Message[] = await this.getMessagesFromChannelByChannelName(channelName, 1);
|
|
125
|
+
return messages.length > 0 ? messages[0] : null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async clearChannel(channelId: string): Promise<void> {
|
|
129
|
+
// For messaging system, we don't actually delete messages
|
|
130
|
+
// This could be implemented to mark messages as deleted or archived
|
|
131
|
+
DyFM_Log.warn('Clear channel not implemented for messaging system');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Message operations
|
|
135
|
+
async sendMessage(channelId: string, content: string): Promise<DyNTS_DyB_Message> {
|
|
136
|
+
const botUserId: string = this.config.dynamo?.botUserId || 'dynamo-bot';
|
|
137
|
+
|
|
138
|
+
const message: DyFM_Msg_Message = await this.messagingService.sendMessage(
|
|
139
|
+
channelId,
|
|
140
|
+
{
|
|
141
|
+
content,
|
|
142
|
+
type: 'text' as any,
|
|
143
|
+
},
|
|
144
|
+
botUserId,
|
|
145
|
+
'dynamo-bot'
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return this.translateMessage(message);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async replyToMessage(messageId: string, channelId: string, content: string): Promise<DyNTS_DyB_Message> {
|
|
152
|
+
// In messaging system, we can't directly reply to a message
|
|
153
|
+
// Instead, we'll send a new message with reference to the original
|
|
154
|
+
const replyContent: string = `[Reply to message ${messageId}] ${content}`;
|
|
155
|
+
return this.sendMessage(channelId, replyContent);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async sendTyping(channelId: string): Promise<void> {
|
|
159
|
+
// Typing indicators not implemented for messaging system
|
|
160
|
+
DyFM_Log.info('Typing indicator not supported in messaging system');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async fetchMessages(channelId: string, limit: number): Promise<DyNTS_DyB_Message[]> {
|
|
164
|
+
const messageService: DyNTS_Msg_Message_DataService = new DyNTS_Msg_Message_DataService({
|
|
165
|
+
issuer: 'dynamo-bot',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const messages: DyFM_Msg_Message[] = await messageService.dataDBService.find({
|
|
169
|
+
conversationId: channelId,
|
|
170
|
+
__deleted: { $exists: false },
|
|
171
|
+
$sort: { sentAt: -1 },
|
|
172
|
+
$limit: limit
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return messages.map((msg: DyFM_Msg_Message) => this.translateMessage(msg));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async fetchAllMessagesWithPaging(channelId: string, maxFetch: number = 1000): Promise<DyNTS_DyB_Message[]> {
|
|
179
|
+
return this.fetchMessages(channelId, maxFetch);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async deleteMessage(messageId: string, channelId: string): Promise<void> {
|
|
183
|
+
await this.messagingService.deleteMessage(messageId, 'dynamo-bot', 'dynamo-bot');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// User operations
|
|
187
|
+
async getUserByName(username: string): Promise<DyNTS_DyB_User> {
|
|
188
|
+
if (this.userCache.has(username)) {
|
|
189
|
+
return this.userCache.get(username);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// In messaging system, we don't have a direct user lookup by name
|
|
193
|
+
// This would need to be implemented based on your user management system
|
|
194
|
+
const user: DyNTS_DyB_User = {
|
|
195
|
+
id: username,
|
|
196
|
+
username: username,
|
|
197
|
+
displayName: username,
|
|
198
|
+
isBot: false,
|
|
199
|
+
rawPlatformUser: null
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
this.userCache.set(username, user);
|
|
203
|
+
return user;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
getUserMention(userId: string): string {
|
|
207
|
+
return `@${userId}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async readMembersInChannel(channelName: string): Promise<DyNTS_DyB_User[]> {
|
|
211
|
+
const channel: DyNTS_DyB_Channel = await this.getChannelByName(channelName);
|
|
212
|
+
const participants: DyFM_Msg_Participant[] = channel.rawPlatformChannel.participants;
|
|
213
|
+
|
|
214
|
+
return participants.map(participant => this.translateUser(participant));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async readMemberNamesInChannel(channelName: string): Promise<string[]> {
|
|
218
|
+
const members: DyNTS_DyB_User[] = await this.readMembersInChannel(channelName);
|
|
219
|
+
return members.map(member => member.username);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Advanced message queries
|
|
223
|
+
async getLastMessageSentBy(channelName: string, username: string): Promise<DyNTS_DyB_Message> {
|
|
224
|
+
const messages: DyNTS_DyB_Message[] = await this.fetchAllMessagesWithPaging(
|
|
225
|
+
(await this.getChannelByName(channelName)).id,
|
|
226
|
+
1000
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
return messages.find(msg => msg.authorName === username) || null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async getLastMentionOf(channelName: string, username: string): Promise<DyNTS_DyB_Message> {
|
|
233
|
+
const messages: DyNTS_DyB_Message[] = await this.fetchAllMessagesWithPaging(
|
|
234
|
+
(await this.getChannelByName(channelName)).id,
|
|
235
|
+
1000
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
return messages.find(msg =>
|
|
239
|
+
msg.content.includes(`@${username}`) ||
|
|
240
|
+
msg.content.includes(username)
|
|
241
|
+
) || null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async readLastMessageDatesByMembers(channelName: string, memberNames: string[]): Promise<DyNTS_Bot_LastMessageDate[]> {
|
|
245
|
+
const channel: DyNTS_DyB_Channel = await this.getChannelByName(channelName);
|
|
246
|
+
const messages: DyNTS_DyB_Message[] = await this.fetchAllMessagesWithPaging(channel.id, 1000);
|
|
247
|
+
|
|
248
|
+
const memberStatus: Record<string, { lastMessageDate: Date | null, allMessages: number }> = {};
|
|
249
|
+
memberNames.forEach((name: string) => {
|
|
250
|
+
memberStatus[name] = { lastMessageDate: null, allMessages: 0 };
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const cutoffTime: number = Date.now() - (3 * week); // 3 weeks
|
|
254
|
+
|
|
255
|
+
messages.forEach((message: DyNTS_DyB_Message) => {
|
|
256
|
+
if (message.timestamp < cutoffTime) return;
|
|
257
|
+
|
|
258
|
+
const author = message.authorName;
|
|
259
|
+
if (memberStatus[author] !== undefined) {
|
|
260
|
+
memberStatus[author].allMessages++;
|
|
261
|
+
if (!memberStatus[author].lastMessageDate) {
|
|
262
|
+
memberStatus[author].lastMessageDate = new Date(message.timestamp);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
return memberNames.map((memberName: string) => {
|
|
268
|
+
const status: { lastMessageDate: Date | null, allMessages: number } = memberStatus[memberName];
|
|
269
|
+
return {
|
|
270
|
+
memberName: memberName,
|
|
271
|
+
allMessages: status.allMessages,
|
|
272
|
+
lastMessageDate: status.lastMessageDate
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async readLastMessageWithMemberNamePingInIt(channelName: string, users: DyNTS_DyB_User[]): Promise<DyNTS_Bot_LastMentionDate[]> {
|
|
278
|
+
const channel: DyNTS_DyB_Channel = await this.getChannelByName(channelName);
|
|
279
|
+
const messages: DyNTS_DyB_Message[] = await this.fetchAllMessagesWithPaging(channel.id, 1000);
|
|
280
|
+
|
|
281
|
+
const memberStatus: Record<string, { lastMentionDate: Date | null; allMentions: number }> = {};
|
|
282
|
+
users.forEach((user: DyNTS_DyB_User) => {
|
|
283
|
+
memberStatus[user.username] = { lastMentionDate: null, allMentions: 0 };
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const cutoffTime: number = Date.now() - (3 * week); // 3 weeks
|
|
287
|
+
|
|
288
|
+
messages.forEach((message: DyNTS_DyB_Message) => {
|
|
289
|
+
if (message.timestamp < cutoffTime) return;
|
|
290
|
+
|
|
291
|
+
users.forEach((user: DyNTS_DyB_User) => {
|
|
292
|
+
if (
|
|
293
|
+
message.content.includes(`@${user.id}`) &&
|
|
294
|
+
!memberStatus[user.username].lastMentionDate
|
|
295
|
+
) {
|
|
296
|
+
memberStatus[user.username].lastMentionDate = new Date(message.timestamp);
|
|
297
|
+
memberStatus[user.username].allMentions++;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return users.map((user: DyNTS_DyB_User) => {
|
|
303
|
+
const status: { lastMentionDate: Date | null; allMentions: number } = memberStatus[user.username];
|
|
304
|
+
return {
|
|
305
|
+
memberId: user.id,
|
|
306
|
+
memberName: user.username,
|
|
307
|
+
allMentions: status.allMentions,
|
|
308
|
+
lastMentionDate: status.lastMentionDate
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Platform-specific features (not applicable for messaging system)
|
|
314
|
+
getRoleByName?(roleName: string): any {
|
|
315
|
+
return null; // Not applicable for messaging system
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
getRolePingByName?(roleName: string): Promise<string> {
|
|
319
|
+
return Promise.resolve(''); // Not applicable for messaging system
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
getRolePingsByName?(roleNames: string[]): Promise<string> {
|
|
323
|
+
return Promise.resolve(''); // Not applicable for messaging system
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Event binding
|
|
327
|
+
onMessage(handler: (message: DyNTS_DyB_Message, issuer: string) => void): void {
|
|
328
|
+
this.messageHandlers.push(handler);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
onReady(handler: () => void): void {
|
|
332
|
+
this.readyHandlers.push(handler);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
onError(handler: (error: Error) => void): void {
|
|
336
|
+
this.errorHandlers.push(handler);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Metadata
|
|
340
|
+
getBotId(): string {
|
|
341
|
+
return this.config.dynamo?.botUserId || 'dynamo-bot';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
getBotDisplayName(): string {
|
|
345
|
+
return this.config.dynamo?.botDisplayName || 'Dynamo Bot';
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
getProviderName(): string {
|
|
349
|
+
return 'dynamo';
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
isReady(): boolean {
|
|
353
|
+
return this.isInitialized;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Helper method to get config
|
|
357
|
+
getConfig(): DyNTS_Bot_Provider_Config {
|
|
358
|
+
return this.config;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Translation methods
|
|
362
|
+
private translateMessage(msgMessage: any): DyNTS_DyB_Message {
|
|
363
|
+
return {
|
|
364
|
+
id: msgMessage._id || msgMessage.id,
|
|
365
|
+
content: msgMessage.content || '',
|
|
366
|
+
authorId: msgMessage.senderId || msgMessage.authorId,
|
|
367
|
+
authorName: msgMessage.senderName || msgMessage.authorName,
|
|
368
|
+
authorDisplayName: msgMessage.senderDisplayName || msgMessage.authorDisplayName,
|
|
369
|
+
channelId: msgMessage.conversationId || msgMessage.channelId,
|
|
370
|
+
channelName: msgMessage.conversationName || msgMessage.channelName || 'unknown',
|
|
371
|
+
timestamp: msgMessage.sentAt ? new Date(msgMessage.sentAt).getTime() : Date.now(),
|
|
372
|
+
isBot: msgMessage.isAIGenerated || false,
|
|
373
|
+
replyToMessageId: msgMessage.replyToMessageId,
|
|
374
|
+
mentions: msgMessage.mentions || [],
|
|
375
|
+
rawPlatformMessage: msgMessage
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private translateChannel(conversation: any): DyNTS_DyB_Channel {
|
|
380
|
+
return {
|
|
381
|
+
id: conversation._id || conversation.id,
|
|
382
|
+
name: conversation.name || conversation.platformChannelId || 'unknown',
|
|
383
|
+
isTextBased: true,
|
|
384
|
+
isDM: conversation.type === 'direct',
|
|
385
|
+
participants: conversation.participants || [],
|
|
386
|
+
rawPlatformChannel: conversation
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
private translateUser(user: any): DyNTS_DyB_User {
|
|
391
|
+
return {
|
|
392
|
+
id: user.userId || user.id,
|
|
393
|
+
username: user.username || user.userId || user.id,
|
|
394
|
+
displayName: user.displayName || user.username || user.userId,
|
|
395
|
+
isBot: user.isBot || false,
|
|
396
|
+
rawPlatformUser: user
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Dynamo Bot Provider
|
|
3
|
+
//
|
|
4
|
+
// This module provides messaging system-specific implementation of the Bot provider interface
|
|
5
|
+
// Uses the messaging system as the underlying platform instead of external services
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// TYPES
|
|
9
|
+
export * from './_models/dyb-platform.types';
|
|
10
|
+
|
|
11
|
+
// SERVICES
|
|
12
|
+
export * from './_services/dyb-provider.service';
|
|
13
|
+
|
|
14
|
+
// COLLECTIONS
|
|
15
|
+
export * from './_collections/dyb-operations.util';
|
|
16
|
+
export * from './_collections/dyb.util';
|
|
@@ -3,6 +3,7 @@ import { DyNTS_Bot_Provider_Type } from '../_enums/bot-provider.enum';
|
|
|
3
3
|
import { DyNTS_DiB_Provider } from '../_modules/discord-bot/_services/dib-provider.service';
|
|
4
4
|
import { DyNTS_SlB_Provider } from '../_modules/slack-bot/_services/slb-provider.service';
|
|
5
5
|
import { DyNTS_TeB_Provider } from '../_modules/teams-bot/_services/teb-provider.service';
|
|
6
|
+
import { DyNTS_DyB_Provider } from '../_modules/dynamo-bot/_services/dyb-provider.service';
|
|
6
7
|
|
|
7
8
|
export class DyNTS_Bot_Provider_Factory {
|
|
8
9
|
|
|
@@ -17,6 +18,9 @@ export class DyNTS_Bot_Provider_Factory {
|
|
|
17
18
|
case DyNTS_Bot_Provider_Type.teams:
|
|
18
19
|
return new DyNTS_TeB_Provider();
|
|
19
20
|
|
|
21
|
+
case DyNTS_Bot_Provider_Type.dynamo:
|
|
22
|
+
return new DyNTS_DyB_Provider();
|
|
23
|
+
|
|
20
24
|
case DyNTS_Bot_Provider_Type.custom:
|
|
21
25
|
if (!config.providerInstance) {
|
|
22
26
|
throw new Error('Custom provider instance is required when provider type is "custom"');
|
|
@@ -48,7 +48,7 @@ export class DyNTS_Msg_Controller extends DyNTS_Controller {
|
|
|
48
48
|
endpoint: DyFM_msgModule_settings.endPoints.getConversations,
|
|
49
49
|
tasks: [
|
|
50
50
|
async (req: Request, res: Response, issuer: string): Promise<void> => {
|
|
51
|
-
|
|
51
|
+
const userId = this.authService.getIssuerFromRequest(req);
|
|
52
52
|
|
|
53
53
|
const conversationService = new DyNTS_Msg_Conversation_DataService({
|
|
54
54
|
issuer,
|
|
@@ -1220,7 +1220,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
1220
1220
|
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : '')
|
|
1221
1221
|
)
|
|
1222
1222
|
),
|
|
1223
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-
|
|
1223
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-VDP1`,
|
|
1224
1224
|
});
|
|
1225
1225
|
} else {
|
|
1226
1226
|
return;
|
|
@@ -1235,7 +1235,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
1235
1235
|
((data as any)?.name ? `\n The failed data's name: ${(data as any).name}` : '')
|
|
1236
1236
|
)
|
|
1237
1237
|
),
|
|
1238
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-
|
|
1238
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-VDP2`,
|
|
1239
1239
|
additionalContent: {
|
|
1240
1240
|
data: data,
|
|
1241
1241
|
},
|
|
@@ -1248,14 +1248,14 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
1248
1248
|
}
|
|
1249
1249
|
);
|
|
1250
1250
|
} catch (error) {
|
|
1251
|
-
if (error?.errorCode?.includes?.('DyNTS-DS0-
|
|
1251
|
+
if (error?.errorCode?.includes?.('DyNTS-DS0-VDP')) {
|
|
1252
1252
|
throw error;
|
|
1253
1253
|
} else {
|
|
1254
1254
|
throw new DyFM_Error({
|
|
1255
1255
|
...this._getDefaultErrorSettings('validateByPropertyParams', error),
|
|
1256
1256
|
|
|
1257
1257
|
status: 522,
|
|
1258
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-
|
|
1258
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DS0-VDP0`,
|
|
1259
1259
|
});
|
|
1260
1260
|
}
|
|
1261
1261
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es2021": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"eslint:recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended"
|
|
9
|
-
],
|
|
10
|
-
"parser": "@typescript-eslint/parser",
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": "latest"
|
|
13
|
-
},
|
|
14
|
-
"plugins": [
|
|
15
|
-
"@typescript-eslint",
|
|
16
|
-
"unused-imports",
|
|
17
|
-
"max-params-no-constructor"
|
|
18
|
-
],
|
|
19
|
-
"rules": {
|
|
20
|
-
/**
|
|
21
|
-
WARNING!
|
|
22
|
-
If the rules have any json parse error, it wont work!
|
|
23
|
-
(even if have unknown property anywhere)
|
|
24
|
-
*/
|
|
25
|
-
"no-warning-comments": [
|
|
26
|
-
"warn",
|
|
27
|
-
{
|
|
28
|
-
"terms": [ "todo", "fixme", "removable", "??" ],
|
|
29
|
-
"location": "anywhere"
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
"indent": [
|
|
33
|
-
"warn",
|
|
34
|
-
2,
|
|
35
|
-
{ "SwitchCase": 1 }
|
|
36
|
-
],
|
|
37
|
-
"max-len": [
|
|
38
|
-
"warn",
|
|
39
|
-
{
|
|
40
|
-
"code": 100,
|
|
41
|
-
"comments": 120
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
"max-lines" : [
|
|
45
|
-
"warn",
|
|
46
|
-
1500
|
|
47
|
-
],
|
|
48
|
-
"linebreak-style": "off",
|
|
49
|
-
"semi": [ "warn", "always" ],
|
|
50
|
-
"no-unused-vars": "off",
|
|
51
|
-
"no-prototype-builtins": "off",
|
|
52
|
-
"no-empty": "warn",
|
|
53
|
-
"comma-dangle": [
|
|
54
|
-
"warn",
|
|
55
|
-
{
|
|
56
|
-
"arrays": "always-multiline",
|
|
57
|
-
"objects": "always-multiline",
|
|
58
|
-
"imports": "never",
|
|
59
|
-
"exports": "never",
|
|
60
|
-
"functions": "only-multiline"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
"brace-style": [
|
|
64
|
-
"warn",
|
|
65
|
-
"1tbs",
|
|
66
|
-
{
|
|
67
|
-
"allowSingleLine": true
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
"padding-line-between-statements": [
|
|
71
|
-
"warn",
|
|
72
|
-
{
|
|
73
|
-
/** BREAK BEFORE */
|
|
74
|
-
"blankLine": "always",
|
|
75
|
-
"prev": "*",
|
|
76
|
-
"next": [
|
|
77
|
-
"return",
|
|
78
|
-
"throw",
|
|
79
|
-
"if",
|
|
80
|
-
"for",
|
|
81
|
-
"while",
|
|
82
|
-
"switch",
|
|
83
|
-
/* "case", */
|
|
84
|
-
"default"
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
/** BREAK AFTER */
|
|
89
|
-
"blankLine": "always",
|
|
90
|
-
"prev": [
|
|
91
|
-
"const",
|
|
92
|
-
"let",
|
|
93
|
-
"var",
|
|
94
|
-
"break"
|
|
95
|
-
],
|
|
96
|
-
"next": "*"
|
|
97
|
-
},
|
|
98
|
-
{ /** CAN FOLLOW (this must be after the BREAK AFTER and BREAK BEFORE) */
|
|
99
|
-
"blankLine": "any",
|
|
100
|
-
"prev": [
|
|
101
|
-
"const",
|
|
102
|
-
"let",
|
|
103
|
-
"var"
|
|
104
|
-
],
|
|
105
|
-
"next": [
|
|
106
|
-
"const",
|
|
107
|
-
"let",
|
|
108
|
-
"var"
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
"prefer-const": "warn",
|
|
113
|
-
"no-case-declarations": "warn",
|
|
114
|
-
"no-fallthrough": "off",
|
|
115
|
-
"keyword-spacing": "warn",
|
|
116
|
-
"no-else-return": "off",
|
|
117
|
-
"no-restricted-imports": [
|
|
118
|
-
"error",
|
|
119
|
-
{
|
|
120
|
-
"paths": [
|
|
121
|
-
{
|
|
122
|
-
"name": "../../../../../*",
|
|
123
|
-
"message": "Dont use long paths, create and use bridge/share index files instead, but better to avoid any of them, so try to resolve other way"
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
],
|
|
128
|
-
"max-lines-per-function": [
|
|
129
|
-
"warn",
|
|
130
|
-
{
|
|
131
|
-
"max": 150,
|
|
132
|
-
"skipComments": true,
|
|
133
|
-
"skipBlankLines": true
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
"id-length": [
|
|
137
|
-
"warn",
|
|
138
|
-
{
|
|
139
|
-
"min": 3,
|
|
140
|
-
"max": 40,
|
|
141
|
-
"exceptions": [
|
|
142
|
-
"i", "j", "a", "b", "x", "y",
|
|
143
|
-
"id", "to", "en", "hu", "ok",
|
|
144
|
-
"no", "or", "my", "ee"
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
],
|
|
148
|
-
"no-duplicate-imports": "warn",
|
|
149
|
-
"max-params": [
|
|
150
|
-
"warn",
|
|
151
|
-
{
|
|
152
|
-
"max": 4
|
|
153
|
-
}
|
|
154
|
-
],
|
|
155
|
-
"max-params-no-constructor/max-params-no-constructor": [
|
|
156
|
-
"warn", 5
|
|
157
|
-
],
|
|
158
|
-
"quotes": [
|
|
159
|
-
"warn",
|
|
160
|
-
"single",
|
|
161
|
-
{ "allowTemplateLiterals": true }
|
|
162
|
-
],
|
|
163
|
-
"object-curly-spacing": [ "warn", "always" ],
|
|
164
|
-
"array-bracket-spacing": [
|
|
165
|
-
"warn",
|
|
166
|
-
"always",
|
|
167
|
-
{ "objectsInArrays": false, "arraysInArrays": false }
|
|
168
|
-
],
|
|
169
|
-
"@typescript-eslint/quotes": [
|
|
170
|
-
"warn",
|
|
171
|
-
"single",
|
|
172
|
-
{ "allowTemplateLiterals": true }
|
|
173
|
-
],
|
|
174
|
-
"@typescript-eslint/no-unused-vars": "warn",
|
|
175
|
-
"@typescript-eslint/explicit-function-return-type": [
|
|
176
|
-
"warn",
|
|
177
|
-
{
|
|
178
|
-
"allowTypedFunctionExpressions": false
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
182
|
-
"@typescript-eslint/typedef": "warn",
|
|
183
|
-
"@typescript-eslint/no-unsafe-function-type": "warn",
|
|
184
|
-
"@typescript-eslint/ban-types": "off"
|
|
185
|
-
}
|
|
186
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DyNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
2
|
-
import { DyNTS_RoutingModule } from '../../_services/route/routing-module.service';
|
|
3
|
-
/**
|
|
4
|
-
* Get messaging routing module
|
|
5
|
-
* Creates and configures the messaging module routes
|
|
6
|
-
*/
|
|
7
|
-
export declare function DyNTS_getMessagingRoutingModule(securityOverride?: DyNTS_RouteSecurity): DyNTS_RoutingModule;
|
|
8
|
-
//# sourceMappingURL=get-messaging-routing-module.util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-messaging-routing-module.util.d.ts","sourceRoot":"","sources":["../../../src/_modules/messaging/get-messaging-routing-module.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAIvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAGnF;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,gBAAgB,CAAC,EAAE,mBAAmB,GACrC,mBAAmB,CAWrB"}
|