import { DyFM_Msg_Message, DyFM_Msg_Conversation, DyFM_Msg_Type, DyFM_Msg_Status, } from '@futdevpro/fsm-dynamo/messaging'; import { DyNTS_Bot_MessageWrapper } from '../../bot/_models/bot-message-wrapper.interface'; /** * Messaging utility functions */ export class DyNTS_Msg_Util { /** * Convert bot message to messaging system message */ static botMessageToMsgMessage( botMessage: DyNTS_Bot_MessageWrapper, conversationId: string, issuer: string ): DyFM_Msg_Message { return new DyFM_Msg_Message({ conversationId, content: botMessage.content || '', type: DyFM_Msg_Type.userToUser, status: DyFM_Msg_Status.sent, senderId: botMessage.authorId, senderName: botMessage.authorName, senderDisplayName: botMessage.authorDisplayName, platformMessageId: (botMessage.rawPlatformMessage as any)?.id || botMessage.id, platformChannelId: botMessage.channelId, sentAt: new Date(botMessage.timestamp), __createdBy: issuer, __lastModifiedBy: issuer, }); } /** * Create AI message from assistant response */ static createAIMessage( conversationId: string, content: string, aiProvider: string, aiModel: string, senderId: string, issuer: string ): DyFM_Msg_Message { return new DyFM_Msg_Message({ conversationId, content, type: DyFM_Msg_Type.aiToUser, status: DyFM_Msg_Status.sent, senderId, isAIGenerated: true, aiProvider, aiModel, sentAt: new Date(), __createdBy: issuer, __lastModifiedBy: issuer, }); } /** * Extract mentions from message content * Looks for @username or @userId patterns */ static extractMentions(content: string): string[] { const mentionRegex = /@(\w+)/g; const matches = content.match(mentionRegex); return matches ? matches.map(m => m.substring(1)) : []; } /** * Check if user has permission to access conversation */ static userCanAccessConversation( conversation: DyFM_Msg_Conversation, userId: string ): boolean { return conversation.participants?.some(p => p.userId === userId) ?? false; } }