@futdevpro/nts-dynamo 1.14.13 → 1.14.15
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/discord-assistant/_services/dias.service-base.d.ts.map +1 -1
- package/build/_modules/discord-assistant/_services/dias.service-base.js.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +2 -2
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +19 -4
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.js.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +1 -1
- package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js +13 -8
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +3 -0
- package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-main.control-service.js +7 -3
- package/build/_modules/discord-bot/_services/dibo-main.control-service.js.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +1 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +10 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -1
- package/build/_modules/messaging/_services/msg.controller.js.map +1 -1
- package/eslint.config.js +3 -0
- package/package.json +14 -2
- 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/discord-assistant/_services/dias.service-base.ts +0 -1
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +22 -5
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +14 -15
- package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +12 -4
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +10 -0
- package/src/_modules/messaging/_services/msg.controller.ts +1 -1
- package/.eslintrc.json +0 -186
|
@@ -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"');
|
|
@@ -10,7 +10,6 @@ import { DyNTS_OAI_GPT_Message_Role } from '../../ai/_modules/open-ai/_enums/oai
|
|
|
10
10
|
import { DyNTS_DiAs_Util } from '../_collections/dias.util';
|
|
11
11
|
import { DyNTS_DiAs_IO_ControlService } from './dias-io.control-service';
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
export abstract class DyNTS_DiAs_ServiceBase extends DyNTS_DiBo_Main_ControlService {
|
|
15
14
|
|
|
16
15
|
getLLMChatControlService(): DyNTS_OAI_LLMChat_ServiceBase {
|
|
@@ -11,13 +11,13 @@ import { DyNTS_DiBo_global_settings } from '../_collections/dibo-global-settings
|
|
|
11
11
|
|
|
12
12
|
export abstract class DyNTS_DiBo_Commands_ControlService extends DyNTS_SingletonService {
|
|
13
13
|
|
|
14
|
-
static getInstance(): DyNTS_DiBo_Commands_ControlService {
|
|
14
|
+
/* static getInstance(): DyNTS_DiBo_Commands_ControlService {
|
|
15
15
|
return DyNTS_DiBo_Commands_ControlService.getSingletonInstance();
|
|
16
|
-
}
|
|
16
|
+
} */
|
|
17
17
|
|
|
18
18
|
protected abstract getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService;
|
|
19
|
-
protected
|
|
20
|
-
|
|
19
|
+
protected diAs_CS: DyNTS_DiBo_Main_ControlService;
|
|
20
|
+
/* protected abstract readonly diAs_CS: DyNTS_DiBo_Main_ControlService; */
|
|
21
21
|
|
|
22
22
|
get discordServer(): Guild {
|
|
23
23
|
return this.diAs_CS?.discordServer;
|
|
@@ -41,6 +41,24 @@ export abstract class DyNTS_DiBo_Commands_ControlService extends DyNTS_Singleton
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
async setup(issuer: string): Promise<void> {
|
|
45
|
+
try {
|
|
46
|
+
this.diAs_CS = this.getMainDiscordBotControlService();
|
|
47
|
+
|
|
48
|
+
if (!this.diAs_CS) {
|
|
49
|
+
throw new DyFM_Error({
|
|
50
|
+
...this.getDefaultErrorSettings('setup', new Error('Main Discord Bot Control Service not found'), issuer),
|
|
51
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-CCS-S01`,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new DyFM_Error({
|
|
56
|
+
...this.getDefaultErrorSettings('setup', error, issuer),
|
|
57
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-CCS-S00`,
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
44
62
|
async handleCommand(message: Message, issuer: string): Promise<void> {
|
|
45
63
|
try {
|
|
46
64
|
let haveCommandOperator = false;
|
|
@@ -111,7 +129,6 @@ export abstract class DyNTS_DiBo_Commands_ControlService extends DyNTS_Singleton
|
|
|
111
129
|
})
|
|
112
130
|
}
|
|
113
131
|
}
|
|
114
|
-
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
|
|
@@ -18,6 +18,7 @@ export abstract class DyNTS_DiBo_IO_ControlService extends DyNTS_SingletonServic
|
|
|
18
18
|
|
|
19
19
|
protected abstract getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService;
|
|
20
20
|
protected abstract mainDiscordBot_CS: DyNTS_DiBo_Main_ControlService;
|
|
21
|
+
/* protected abstract readonly mainDiscordBot_CS: DyNTS_DiBo_Main_ControlService; */
|
|
21
22
|
|
|
22
23
|
get discordServer(): Guild {
|
|
23
24
|
return this.mainDiscordBot_CS?.discordServer;
|
|
@@ -38,34 +39,32 @@ export abstract class DyNTS_DiBo_IO_ControlService extends DyNTS_SingletonServic
|
|
|
38
39
|
super();
|
|
39
40
|
} */
|
|
40
41
|
|
|
41
|
-
async
|
|
42
|
+
async setup(issuer: string): Promise<void> {
|
|
42
43
|
try {
|
|
43
44
|
this.mainDiscordBot_CS = this.getMainDiscordBotControlService();
|
|
44
45
|
this.commands_CS = this.getCommandsControlService();
|
|
45
46
|
|
|
46
|
-
if (!this.
|
|
47
|
+
if (!this.mainDiscordBot_CS) {
|
|
47
48
|
throw new DyFM_Error({
|
|
48
|
-
...this.getDefaultErrorSettings(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
),
|
|
56
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-IO-
|
|
49
|
+
...this.getDefaultErrorSettings('setup', new Error('Main Discord Bot Control Service not found'), issuer),
|
|
50
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-IO-S01`,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!this.commands_CS) {
|
|
55
|
+
throw new DyFM_Error({
|
|
56
|
+
...this.getDefaultErrorSettings('setup', new Error('Commands Control Service not found'), issuer),
|
|
57
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-IO-S02`,
|
|
57
58
|
})
|
|
58
59
|
}
|
|
59
60
|
} catch (error) {
|
|
60
61
|
throw new DyFM_Error({
|
|
61
|
-
...this.getDefaultErrorSettings('
|
|
62
|
+
...this.getDefaultErrorSettings('setup', error, issuer),
|
|
62
63
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-IO-S000`,
|
|
63
64
|
})
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
/* async */
|
|
68
|
-
|
|
69
68
|
async handleNewMessage(message: Message, issuer: string): Promise<void> {
|
|
70
69
|
try {
|
|
71
70
|
if (DyNTS_DiBo_global_settings.debugLevel >= 1) {
|
|
@@ -118,7 +117,7 @@ export abstract class DyNTS_DiBo_IO_ControlService extends DyNTS_SingletonServic
|
|
|
118
117
|
new Error('Bot not initialized yet').stack
|
|
119
118
|
)
|
|
120
119
|
|
|
121
|
-
await this.start(issuer);
|
|
120
|
+
//await this.mainDiscordBot_CS.start(issuer);
|
|
122
121
|
|
|
123
122
|
if (!this.discordServer || !this.mainDiscordBot_CS || !this.botClientId) {
|
|
124
123
|
DyFM_Log.H_error(
|
|
@@ -8,6 +8,7 @@ import { DyNTS_DiBo_IO_ControlService } from './dibo-io.control-service';
|
|
|
8
8
|
import { DyNTS_DiBo_global_settings } from '../_collections/dibo-global-settings.conts';
|
|
9
9
|
import { DyNTS_GlobalService } from '../../../_services/core/global.service';
|
|
10
10
|
import { DyNTS_DiBo_Operations_Util } from '../_collections/dibo-operations.util';
|
|
11
|
+
import { DyNTS_DiBo_Commands_ControlService } from './dibo-commands.control-service';
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -70,6 +71,9 @@ export abstract class DyNTS_DiBo_Main_ControlService extends DyNTS_SingletonServ
|
|
|
70
71
|
protected routines_CS: DyNTS_DiBo_Routines_ControlService;
|
|
71
72
|
protected abstract getRoutinesControlService(): DyNTS_DiBo_Routines_ControlService;
|
|
72
73
|
|
|
74
|
+
protected commands_CS: DyNTS_DiBo_Commands_ControlService;
|
|
75
|
+
protected abstract getCommandsControlService(): DyNTS_DiBo_Commands_ControlService;
|
|
76
|
+
|
|
73
77
|
private _channelsByNames: {
|
|
74
78
|
[key: string]: TextChannel;
|
|
75
79
|
} = {};
|
|
@@ -163,6 +167,14 @@ export abstract class DyNTS_DiBo_Main_ControlService extends DyNTS_SingletonServ
|
|
|
163
167
|
DyNTS_DiBo_global_settings.channelSettings.reportChannelName
|
|
164
168
|
);
|
|
165
169
|
}
|
|
170
|
+
|
|
171
|
+
this.botIO_CS = this.getBotIOControlService();
|
|
172
|
+
this.routines_CS = this.getRoutinesControlService();
|
|
173
|
+
this.commands_CS = this.getCommandsControlService();
|
|
174
|
+
|
|
175
|
+
await this.botIO_CS.setup(issuer);
|
|
176
|
+
await this.routines_CS.setup(issuer);
|
|
177
|
+
await this.commands_CS.setup(issuer);
|
|
166
178
|
|
|
167
179
|
return new Promise((resolve, reject) => {
|
|
168
180
|
this.client.on('error', (error) => {
|
|
@@ -268,11 +280,7 @@ export abstract class DyNTS_DiBo_Main_ControlService extends DyNTS_SingletonServ
|
|
|
268
280
|
|
|
269
281
|
async start(issuer: string): Promise<void> {
|
|
270
282
|
try {
|
|
271
|
-
this.botIO_CS = this.getBotIOControlService();
|
|
272
|
-
this.routines_CS = this.getRoutinesControlService();
|
|
273
|
-
|
|
274
283
|
await this.routines_CS.start(issuer);
|
|
275
|
-
await this.botIO_CS.start(issuer);
|
|
276
284
|
|
|
277
285
|
DyFM_Log.success('Discord Bot started')
|
|
278
286
|
} catch (error) {
|
|
@@ -45,6 +45,16 @@ export abstract class DyNTS_DiBo_Routines_ControlService extends DyNTS_Singleton
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
async setup(issuer: string): Promise<void> {
|
|
49
|
+
try {
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new DyFM_Error({
|
|
52
|
+
...this.getDefaultErrorSettings('setup', error, issuer),
|
|
53
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-S000`,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
async start(issuer: string): Promise<void> {
|
|
49
59
|
try {
|
|
50
60
|
await this.startRoutines(issuer);
|
|
@@ -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,
|