From d55ef3063bd2098e71bc4d16531ad20f4ff04908 Mon Sep 17 00:00:00 2001
From: neo773 <62795688+neo773@users.noreply.github.com>
Date: Tue, 30 Jun 2026 19:38:05 +0530
Subject: [PATCH] Fix draft send: read messageChannel from core, not workspace
ORM (#22365)
messageChannel moved to a core-schema entity, so resolving it via the
workspace ORM by name throws 'object metadata missing'. Query the core
MessageChannelEntity repository scoped by workspaceId instead.
---
.../services/messaging-draft-send.service.ts | 33 +++++++++----------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/packages/twenty-server/src/modules/messaging/message-outbound-manager/services/messaging-draft-send.service.ts b/packages/twenty-server/src/modules/messaging/message-outbound-manager/services/messaging-draft-send.service.ts
index 65b2369781..2904809bf3 100644
--- a/packages/twenty-server/src/modules/messaging/message-outbound-manager/services/messaging-draft-send.service.ts
+++ b/packages/twenty-server/src/modules/messaging/message-outbound-manager/services/messaging-draft-send.service.ts
@@ -1,14 +1,15 @@
import { Injectable } from '@nestjs/common';
+import { InjectRepository } from '@nestjs/typeorm';
import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from 'twenty-shared/utils';
-import { In } from 'typeorm';
+import { In, Repository } from 'typeorm';
import { type ConnectedAccountEntity } from 'src/engine/metadata-modules/connected-account/entities/connected-account.entity';
+import { MessageChannelEntity } from 'src/engine/metadata-modules/message-channel/entities/message-channel.entity';
import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';
import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
import { type MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
-import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessagingMessageCleanerService } from 'src/modules/messaging/message-cleaner/services/messaging-message-cleaner.service';
import { MessagingMessageOutboundService } from 'src/modules/messaging/message-outbound-manager/services/messaging-message-outbound.service';
import { type SendMessageInput } from 'src/modules/messaging/message-outbound-manager/types/send-message-input.type';
@@ -20,6 +21,8 @@ export class MessagingDraftSendService {
private readonly globalWorkspaceOrmManager: GlobalWorkspaceOrmManager,
private readonly messageOutboundService: MessagingMessageOutboundService,
private readonly messageCleanerService: MessagingMessageCleanerService,
+ @InjectRepository(MessageChannelEntity)
+ private readonly messageChannelRepository: Repository,
) {}
async sendDraftMessage({
@@ -117,27 +120,21 @@ export class MessagingDraftSendService {
connectedAccountId: string,
workspaceId: string,
): Promise<{ messageExternalId: string; messageChannelId: string } | null> {
+ const channels = await this.messageChannelRepository.find({
+ where: { connectedAccountId, workspaceId },
+ });
+
+ const channelIds = channels.map((channel) => channel.id);
+
+ if (channelIds.length === 0) {
+ return null;
+ }
+
const authContext = buildSystemAuthContext(workspaceId);
const associations =
await this.globalWorkspaceOrmManager.executeInWorkspaceContext(
async () => {
- const messageChannelRepository =
- await this.globalWorkspaceOrmManager.getRepository(
- workspaceId,
- 'messageChannel',
- );
-
- const channels = await messageChannelRepository.find({
- where: { connectedAccountId },
- });
-
- const channelIds = channels.map((channel) => channel.id);
-
- if (channelIds.length === 0) {
- return [];
- }
-
const messageChannelMessageAssociationRepository =
await this.globalWorkspaceOrmManager.getRepository(
workspaceId,