Fix notifications (#7955)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2025-02-06 19:40:26 +04:00 committed by GitHub
parent b97b858728
commit 529230ff68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 66 deletions

View File

@ -13,10 +13,8 @@
// limitations under the License. // limitations under the License.
// //
import aiBot from '@hcengineering/ai-bot' import { ChatMessage } from '@hcengineering/chunter'
import analyticsCollector from '@hcengineering/analytics-collector' import { AttachedDoc, Tx, TxCreateDoc, TxCUD } from '@hcengineering/core'
import chunter, { ChatMessage, ThreadMessage } from '@hcengineering/chunter'
import core, { AttachedDoc, Tx, TxCreateDoc, TxCUD, TxProcessor } from '@hcengineering/core'
import { ActivityInboxNotification, MentionInboxNotification } from '@hcengineering/notification' import { ActivityInboxNotification, MentionInboxNotification } from '@hcengineering/notification'
import { TriggerControl } from '@hcengineering/server-core' 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<void> { async function onBotDirectMessageSend (control: TriggerControl, message: ChatMessage): Promise<void> {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// const account = control.modelDb.findAllSync(contact.class.PersonAccount, { // const account = control.modelDb.findAllSync(contact.class.PersonAccount, {
// _id: (message.createdBy ?? message.modifiedBy) as PersonId // _id: (message.createdBy ?? message.modifiedBy) as PersonId
// })[0] // })[0]
// if (account === undefined) { // if (account === undefined) {
// return // return
// } // }
// const direct = (await getMessageDoc(message, control)) as DirectMessage // const direct = (await getMessageDoc(message, control)) as DirectMessage
// if (direct === undefined) { // if (direct === undefined) {
// return // return
// } // }
// const isAvailable = await isDirectAvailable(direct, control) // const isAvailable = await isDirectAvailable(direct, control)
// if (!isAvailable) { // if (!isAvailable) {
// return // return
// } // }
// let messageEvent: AIMessageEventRequest // let messageEvent: AIMessageEventRequest
// if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) { // if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) {
// messageEvent = getThreadMessageData(message as ThreadMessage, account.email) // messageEvent = getThreadMessageData(message as ThreadMessage, account.email)
// } else { // } else {
// messageEvent = getMessageData(direct, message, account.email) // messageEvent = getMessageData(direct, message, account.email)
// } // }
// const transferEvent = await createTransferEvent(control, message, account, messageEvent) // const transferEvent = await createTransferEvent(control, message, account, messageEvent)
// const events = transferEvent !== undefined ? [messageEvent, transferEvent] : [messageEvent] // const events = transferEvent !== undefined ? [messageEvent, transferEvent] : [messageEvent]
// await sendAIEvents(events, control.workspace.uuid, control.ctx) // 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<void> { async function onSupportWorkspaceMessage (control: TriggerControl, message: ChatMessage): Promise<void> {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// const supportWorkspaceId = getSupportWorkspaceId() // const supportWorkspaceId = getSupportWorkspaceId()
// if (supportWorkspaceId === undefined) { // if (supportWorkspaceId === undefined) {
// return // return
// } // }
// if (control.workspace.uuid !== supportWorkspaceId) { // if (control.workspace.uuid !== supportWorkspaceId) {
// return // return
// } // }
// if (!control.hierarchy.isDerived(message.attachedToClass, analyticsCollector.class.OnboardingChannel)) { // if (!control.hierarchy.isDerived(message.attachedToClass, analyticsCollector.class.OnboardingChannel)) {
// return // return
// } // }
// const channel = (await getMessageDoc(message, control)) as OnboardingChannel // const channel = (await getMessageDoc(message, control)) as OnboardingChannel
// if (channel === undefined) { // if (channel === undefined) {
// return // return
// } // }
// const { workspaceId, email } = channel // const { workspaceId, email } = channel
// const account = control.modelDb.findAllSync(contact.class.PersonAccount, { // const account = control.modelDb.findAllSync(contact.class.PersonAccount, {
// _id: (message.createdBy ?? message.modifiedBy) as PersonId // _id: (message.createdBy ?? message.modifiedBy) as PersonId
// })[0] // })[0]
// let data: AIMessageEventRequest // let data: AIMessageEventRequest
// if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) { // if (control.hierarchy.isDerived(message._class, chunter.class.ThreadMessage)) {
// data = getThreadMessageData(message as ThreadMessage, account.email) // data = getThreadMessageData(message as ThreadMessage, account.email)
// } else { // } else {
// data = getMessageData(channel, message, account.email) // data = getMessageData(channel, message, account.email)
// } // }
// const transferEvent: AITransferEventRequest = { // const transferEvent: AITransferEventRequest = {
// type: AIEventType.Transfer, // type: AIEventType.Transfer,
// createdOn: data.createdOn, // createdOn: data.createdOn,
@ -219,39 +200,39 @@ async function onSupportWorkspaceMessage (control: TriggerControl, message: Chat
// messageId: message._id, // messageId: message._id,
// parentMessageId: await getThreadParent(control, message) // parentMessageId: await getThreadParent(control, message)
// } // }
// await sendAIEvents([transferEvent], control.workspace.uuid, control.ctx) // await sendAIEvents([transferEvent], control.workspace.uuid, control.ctx)
} }
export async function OnMessageSend (originTxs: TxCUD<AttachedDoc>[], control: TriggerControl): Promise<Tx[]> { export async function OnMessageSend (originTxs: TxCUD<AttachedDoc>[], control: TriggerControl): Promise<Tx[]> {
const { hierarchy } = control // TODO: FIXME
const txes = originTxs.filter( // const { hierarchy } = control
(it) => // const txes = originTxs.filter(
it._class === core.class.TxCreateDoc && // (it) =>
hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) && // it._class === core.class.TxCreateDoc &&
!(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System) // hierarchy.isDerived(it.objectClass, chunter.class.ChatMessage) &&
) // !(it.modifiedBy === aiBot.account.AIBot || it.modifiedBy === core.account.System)
if (txes.length === 0) { // )
return [] // if (txes.length === 0) {
} // return []
for (const tx of txes) { // }
const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage) // for (const tx of txes) {
const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc<ChatMessage>) // const isThread = hierarchy.isDerived(tx.objectClass, chunter.class.ThreadMessage)
// const message = TxProcessor.createDoc2Doc(tx as TxCreateDoc<ChatMessage>)
const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass //
// const docClass = isThread ? (message as ThreadMessage).objectClass : message.attachedToClass
if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) { //
continue // if (!hierarchy.isDerived(docClass, chunter.class.ChunterSpace)) {
} // continue
// }
if (docClass === chunter.class.DirectMessage) { //
await onBotDirectMessageSend(control, message) // if (docClass === chunter.class.DirectMessage) {
} // await onBotDirectMessageSend(control, message)
// }
if (docClass === analyticsCollector.class.OnboardingChannel) { //
await onSupportWorkspaceMessage(control, message) // if (docClass === analyticsCollector.class.OnboardingChannel) {
} // await onSupportWorkspaceMessage(control, message)
} // }
// }
return [] return []
} }

View File

@ -15,7 +15,7 @@
import { TriggerControl } from '@hcengineering/server-core' import { TriggerControl } from '@hcengineering/server-core'
import contact, { Employee, type Person } from '@hcengineering/contact' 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<Person | undefined> { export async function getTriggerCurrentPerson (control: TriggerControl): Promise<Person | undefined> {
const { type, value } = parseSocialIdString(control.txFactory.account) const { type, value } = parseSocialIdString(control.txFactory.account)
@ -79,9 +79,13 @@ export async function getAllSocialStringsByPersonId (
export async function getPerson (control: TriggerControl, personId: PersonId): Promise<Person | undefined> { export async function getPerson (control: TriggerControl, personId: PersonId): Promise<Person | undefined> {
const socialId = (await control.findAll(control.ctx, contact.class.SocialIdentity, { key: personId }))[0] 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<Person[]> { export async function getPersons (control: TriggerControl, personIds: PersonId[]): Promise<Person[]> {

View File

@ -147,16 +147,12 @@ async function notifyByEmail (
message?: ActivityMessage message?: ActivityMessage
): Promise<void> { ): Promise<void> {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// const account = receiver.account // const account = receiver.account
// if (account === undefined) { // if (account === undefined) {
// return // return
// } // }
// const senderPerson = sender.person // const senderPerson = sender.person
// const senderName = senderPerson !== undefined ? formatName(senderPerson.name, control.branding?.lastNameFirst) : '' // const senderName = senderPerson !== undefined ? formatName(senderPerson.name, control.branding?.lastNameFirst) : ''
// const content = await getContentByTemplate(doc, senderName, type, control, '', data, message) // const content = await getContentByTemplate(doc, senderName, type, control, '', data, message)
// if (content !== undefined) { // if (content !== undefined) {
// await sendEmailNotification(control.ctx, content.text, content.html, content.subject, account.email) // await sendEmailNotification(control.ctx, content.text, content.html, content.subject, account.email)
@ -173,7 +169,6 @@ const SendEmailNotifications: NotificationProviderFunc = async (
message?: ActivityMessage message?: ActivityMessage
): Promise<Tx[]> => { ): Promise<Tx[]> => {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// if (types.length === 0) { // if (types.length === 0) {
// return [] // return []
// } // }
@ -190,7 +185,7 @@ const SendEmailNotifications: NotificationProviderFunc = async (
// await notifyByEmail(control, type._id, object, sender, receiver, data, message) // await notifyByEmail(control, type._id, object, sender, receiver, data, message)
// } // }
// return [] return []
} }
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type // eslint-disable-next-line @typescript-eslint/explicit-function-return-type

View File

@ -45,7 +45,6 @@ export async function getValue (control: TriggerControl, context: Record<string,
async function getEmployee (control: TriggerControl, _id: PersonId): Promise<Person | undefined> { async function getEmployee (control: TriggerControl, _id: PersonId): Promise<Person | undefined> {
// TODO: FIXME // TODO: FIXME
// Related to integrations // Related to integrations
throw new Error('Not implemented')
// const employeeAccount = control.modelDb.findAllSync(contact.class.PersonAccount, { // const employeeAccount = control.modelDb.findAllSync(contact.class.PersonAccount, {
// _id: _id as PersonId // _id: _id as PersonId
// })[0] // })[0]
@ -57,6 +56,7 @@ async function getEmployee (control: TriggerControl, _id: PersonId): Promise<Per
// )[0] // )[0]
// return employee // return employee
// } // }
return undefined
} }
export async function getOwnerFirstName ( export async function getOwnerFirstName (

View File

@ -114,7 +114,6 @@ export async function GetCurrentEmployeeTG (
context: Record<string, Doc> context: Record<string, Doc>
): Promise<string | undefined> { ): Promise<string | undefined> {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// const account = await control.modelDb.findOne(contact.class.PersonAccount, { // const account = await control.modelDb.findOne(contact.class.PersonAccount, {
// _id: control.txFactory.account as PersonId // _id: control.txFactory.account as PersonId
// }) // })
@ -125,6 +124,8 @@ export async function GetCurrentEmployeeTG (
// if (employee !== undefined) { // if (employee !== undefined) {
// return await getContactChannel(control, employee, contact.channelProvider.Telegram) // return await getContactChannel(control, employee, contact.channelProvider.Telegram)
// } // }
return undefined
} }
export async function GetIntegrationOwnerTG ( export async function GetIntegrationOwnerTG (
@ -132,7 +133,6 @@ export async function GetIntegrationOwnerTG (
context: Record<string, Doc> context: Record<string, Doc>
): Promise<string | undefined> { ): Promise<string | undefined> {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// const value = context[setting.class.Integration] as Integration // const value = context[setting.class.Integration] as Integration
// if (value === undefined) return // if (value === undefined) return
// const account = await control.modelDb.findOne(contact.class.PersonAccount, { // const account = await control.modelDb.findOne(contact.class.PersonAccount, {
@ -145,6 +145,8 @@ export async function GetIntegrationOwnerTG (
// if (employee !== undefined) { // if (employee !== undefined) {
// return await getContactChannel(control, employee, contact.channelProvider.Telegram) // return await getContactChannel(control, employee, contact.channelProvider.Telegram)
// } // }
return undefined
} }
async function getContactChannel ( async function getContactChannel (
@ -261,7 +263,6 @@ const SendTelegramNotifications: NotificationProviderFunc = async (
message?: ActivityMessage message?: ActivityMessage
): Promise<Tx[]> => { ): Promise<Tx[]> => {
// TODO: FIXME // TODO: FIXME
throw new Error('Not implemented')
// if (types.length === 0) { // if (types.length === 0) {
// return [] // return []
// } // }
@ -312,7 +313,7 @@ const SendTelegramNotifications: NotificationProviderFunc = async (
// }) // })
// } // }
// return [] return []
} }
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type // eslint-disable-next-line @typescript-eslint/explicit-function-return-type