Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions backend/__tests__/unit/services/telegramBridgeService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('telegramBridgeService — user-scope outbound gate', () => {
podId: 'active-pod',
type: 'telegram',
isActive: true,
status: 'connected',
config: {
liveRelay: true,
chatType: 'private',
Expand Down Expand Up @@ -207,6 +208,7 @@ describe('telegramBridgeService — multi-pod routing', () => {
podId: ORIGINAL_POD,
type: 'telegram',
isActive: true,
status: 'connected',
config: {
liveRelay: true,
chatType: 'private',
Expand Down Expand Up @@ -294,6 +296,34 @@ describe('telegramBridgeService — multi-pod routing', () => {
}));
});

it('keeps relaying a pending dispatcher-selected row', async () => {
await relayAgentMessageToTelegram({
podId: GATED_POD,
agentUsername: 'kai',
displayName: 'Kai',
content: 'deploy is green',
integration: { ...userScoped({ relayAllAgentMessages: true }), status: 'pending' },
});

expect(telegramSend.sendMessage).toHaveBeenCalledTimes(1);
});

it('does not relay through an error row found by the Telegram fallback', async () => {
IntegrationModel.findOne.mockReturnValue({
lean: jest.fn().mockResolvedValue({ ...userScoped({ relayAllAgentMessages: true }), status: 'error' }),
});

await relayAgentMessageToTelegram({
podId: GATED_POD,
agentUsername: 'kai',
displayName: 'Kai',
content: 'Must stay in Commonly',
});

expect(IntegrationModel.findOne).toHaveBeenCalledWith(expect.objectContaining({ status: { $ne: 'error' } }));
expect(telegramSend.sendMessage).not.toHaveBeenCalled();
});

it('posts a quote-reply into the quoted pod, not the active one', async () => {
const result = await inbound(userScoped(), { reply_to_message: { message_id: 101 } });

Expand Down
3 changes: 3 additions & 0 deletions backend/services/telegramBridgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface TelegramIntegrationDoc {
scope?: 'pod' | 'user';
type?: string;
isActive?: boolean;
status?: 'connected' | 'disconnected' | 'error' | 'pending';
config?: {
chatId?: string;
chatType?: string;
Expand Down Expand Up @@ -156,6 +157,7 @@ const findLiveIntegration = async (podId: unknown): Promise<TelegramIntegrationD
return await IntegrationModel.findOne({
type: 'telegram',
isActive: true,
status: { $ne: 'error' },
podId,
'config.liveRelay': true,
'config.chatId': { $exists: true, $ne: null },
Expand All @@ -182,6 +184,7 @@ const isRelayableIntegration = (
isGatedPodTarget(integration, podId)
&& (integration.type === undefined || integration.type === 'telegram')
&& integration.isActive !== false
&& integration.status !== 'error'
&& integration.config?.liveRelay === true
&& integration.config?.chatType === 'private'
&& !integration.config?.adminPause
Expand Down
Loading