diff --git a/server-plugins/ai-bot-resources/src/index.ts b/server-plugins/ai-bot-resources/src/index.ts index 5f3c177925..3e4c27657b 100644 --- a/server-plugins/ai-bot-resources/src/index.ts +++ b/server-plugins/ai-bot-resources/src/index.ts @@ -13,10 +13,8 @@ // limitations under the License. // -import aiBot from '@hcengineering/ai-bot' -import analyticsCollector from '@hcengineering/analytics-collector' -import chunter, { ChatMessage, ThreadMessage } from '@hcengineering/chunter' -import core, { AttachedDoc, Tx, TxCreateDoc, TxCUD, TxProcessor } from '@hcengineering/core' +import { ChatMessage } from '@hcengineering/chunter' +import { AttachedDoc, Tx, TxCreateDoc, TxCUD } from '@hcengineering/core' import { ActivityInboxNotification, MentionInboxNotification } from '@hcengineering/notification' import { TriggerControl } from '@hcengineering/server-core' @@ -133,78 +131,61 @@ import { TriggerControl } from '@hcengineering/server-core' // } // } +// eslint-disable-next-line @typescript-eslint/no-unused-vars async function onBotDirectMessageSend (control: TriggerControl, message: ChatMessage): Promise { // TODO: FIXME - throw new Error('Not implemented') // const account = control.modelDb.findAllSync(contact.class.PersonAccount, { // _id: (message.createdBy ?? message.modifiedBy) as PersonId // })[0] - // if (account === undefined) { // return // } - // const direct = (await getMessageDoc(message, control)) as DirectMessage - // if (direct === undefined) { // return // } - // const isAvailable = await isDirectAvailable(direct, control) - // if (!isAvailable) { // return // } - // let messageEvent: AIMessageEventRequest - // if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) { // messageEvent = getThreadMessageData(message as ThreadMessage, account.email) // } else { // messageEvent = getMessageData(direct, message, account.email) // } - // const transferEvent = await createTransferEvent(control, message, account, messageEvent) // const events = transferEvent !== undefined ? [messageEvent, transferEvent] : [messageEvent] - // await sendAIEvents(events, control.workspace.uuid, control.ctx) } +// eslint-disable-next-line @typescript-eslint/no-unused-vars async function onSupportWorkspaceMessage (control: TriggerControl, message: ChatMessage): Promise { // TODO: FIXME - throw new Error('Not implemented') // const supportWorkspaceId = getSupportWorkspaceId() - // if (supportWorkspaceId === undefined) { // return // } - // if (control.workspace.uuid !== supportWorkspaceId) { // return // } - // if (!control.hierarchy.isDerived(message.attachedToClass, analyticsCollector.class.OnboardingChannel)) { // return // } - // const channel = (await getMessageDoc(message, control)) as OnboardingChannel - // if (channel === undefined) { // return // } - // const { workspaceId, email } = channel // const account = control.modelDb.findAllSync(contact.class.PersonAccount, { // _id: (message.createdBy ?? message.modifiedBy) as PersonId // })[0] - // let data: AIMessageEventRequest // if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) { // data = getThreadMessageData(message as ThreadMessage, account.email) // } else { // data = getMessageData(channel, message, account.email) // } - // const transferEvent: AITransferEventRequest = { // type: AIEventType.Transfer, // createdOn: data.createdOn, @@ -219,39 +200,39 @@ async function onSupportWorkspaceMessage (control: TriggerControl, message: Chat // messageId: message._id, // parentMessageId: await getThreadParent(control, message) // } - // await sendAIEvents([transferEvent], control.workspace.uuid, control.ctx) } export async function OnMessageSend (originTxs: TxCUD[], control: TriggerControl): Promise { - const { hierarchy } = control - const txes = originTxs.filter( - (it) => - it._class === core.class.TxCreateDoc && - hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) && - !(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System) - ) - if (txes.length === 0) { - return [] - } - for (const tx of txes) { - const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage) - const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc) - - const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass - - if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) { - continue - } - - if (docClass === chunter.class.DirectMessage) { - await onBotDirectMessageSend(control, message) - } - - if (docClass === analyticsCollector.class.OnboardingChannel) { - await onSupportWorkspaceMessage(control, message) - } - } + // TODO: FIXME + // const { hierarchy } = control + // const txes = originTxs.filter( + // (it) => + // it._class === core.class.TxCreateDoc && + // hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) && + // !(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System) + // ) + // if (txes.length === 0) { + // return [] + // } + // for (const tx of txes) { + // const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage) + // const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc) + // + // const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass + // + // if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) { + // continue + // } + // + // if (docClass === chunter.class.DirectMessage) { + // await onBotDirectMessageSend(control, message) + // } + // + // if (docClass === analyticsCollector.class.OnboardingChannel) { + // await onSupportWorkspaceMessage(control, message) + // } + // } return [] } diff --git a/server-plugins/contact/src/utils.ts b/server-plugins/contact/src/utils.ts index 75e1295b2a..c6bc1c31eb 100644 --- a/server-plugins/contact/src/utils.ts +++ b/server-plugins/contact/src/utils.ts @@ -15,7 +15,7 @@ import { TriggerControl } from '@hcengineering/server-core' import contact, { Employee, type Person } from '@hcengineering/contact' -import { PersonId, toIdMap, parseSocialIdString, type Ref } from '@hcengineering/core' +import { parseSocialIdString, PersonId, type Ref, toIdMap } from '@hcengineering/core' export async function getTriggerCurrentPerson (control: TriggerControl): Promise { const { type, value } = parseSocialIdString(control.txFactory.account) @@ -79,9 +79,13 @@ export async function getAllSocialStringsByPersonId ( export async function getPerson (control: TriggerControl, personId: PersonId): Promise { const socialId = (await control.findAll(control.ctx, contact.class.SocialIdentity, { key: personId }))[0] - const person = (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0] - return person + if (socialId === undefined) { + control.ctx.error('Cannot find social id', { key: personId }) + return undefined + } + + return (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0] } export async function getPersons (control: TriggerControl, personIds: PersonId[]): Promise { diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index a36c80db24..5c348dd22f 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -147,16 +147,12 @@ async function notifyByEmail ( message?: ActivityMessage ): Promise { // TODO: FIXME - throw new Error('Not implemented') // const account = receiver.account - // if (account === undefined) { // return // } - // const senderPerson = sender.person // const senderName = senderPerson !== undefined ? formatName(senderPerson.name, control.branding?.lastNameFirst) : '' - // const content = await getContentByTemplate(doc, senderName, type, control, '', data, message) // if (content !== undefined) { // await sendEmailNotification(control.ctx, content.text, content.html, content.subject, account.email) @@ -173,7 +169,6 @@ const SendEmailNotifications: NotificationProviderFunc = async ( message?: ActivityMessage ): Promise => { // TODO: FIXME - throw new Error('Not implemented') // if (types.length === 0) { // return [] // } @@ -190,7 +185,7 @@ const SendEmailNotifications: NotificationProviderFunc = async ( // await notifyByEmail(control, type._id, object, sender, receiver, data, message) // } - // return [] + return [] } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type diff --git a/server-plugins/setting-resources/src/index.ts b/server-plugins/setting-resources/src/index.ts index 5c508c873b..3ff63c328e 100644 --- a/server-plugins/setting-resources/src/index.ts +++ b/server-plugins/setting-resources/src/index.ts @@ -45,7 +45,6 @@ export async function getValue (control: TriggerControl, context: Record { // TODO: FIXME // Related to integrations - throw new Error('Not implemented') // const employeeAccount = control.modelDb.findAllSync(contact.class.PersonAccount, { // _id: _id as PersonId // })[0] @@ -57,6 +56,7 @@ async function getEmployee (control: TriggerControl, _id: PersonId): Promise ): Promise { // TODO: FIXME - throw new Error('Not implemented') // const account = await control.modelDb.findOne(contact.class.PersonAccount, { // _id: control.txFactory.account as PersonId // }) @@ -125,6 +124,8 @@ export async function GetCurrentEmployeeTG ( // if (employee !== undefined) { // return await getContactChannel(control, employee, contact.channelProvider.Telegram) // } + + return undefined } export async function GetIntegrationOwnerTG ( @@ -132,7 +133,6 @@ export async function GetIntegrationOwnerTG ( context: Record ): Promise { // TODO: FIXME - throw new Error('Not implemented') // const value = context[setting.class.Integration] as Integration // if (value === undefined) return // const account = await control.modelDb.findOne(contact.class.PersonAccount, { @@ -145,6 +145,8 @@ export async function GetIntegrationOwnerTG ( // if (employee !== undefined) { // return await getContactChannel(control, employee, contact.channelProvider.Telegram) // } + + return undefined } async function getContactChannel ( @@ -261,7 +263,6 @@ const SendTelegramNotifications: NotificationProviderFunc = async ( message?: ActivityMessage ): Promise => { // TODO: FIXME - throw new Error('Not implemented') // if (types.length === 0) { // return [] // } @@ -312,7 +313,7 @@ const SendTelegramNotifications: NotificationProviderFunc = async ( // }) // } - // return [] + return [] } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type