Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
476a827
feat: adds new endpoints to interact with outbound providers
lucas-a-pelegrino Jun 24, 2025
a12b5d4
refactor: moves outbound endpoints to correct place
lucas-a-pelegrino Jun 24, 2025
0b15f6d
refactor: improve business logic for outbound comms
lucas-a-pelegrino Jun 26, 2025
ef12314
refactor: adds more minor improvements to listOutboundPRoviders logic
lucas-a-pelegrino Jun 27, 2025
e3767f2
tests: adds unit testing for OutboundMessageProviderService
lucas-a-pelegrino Jul 3, 2025
8d16c0b
chore: adds a minor improvement on OutboundMessageProviderService
lucas-a-pelegrino Jul 8, 2025
517c4dd
Merge branch 'develop' into feat/CTZ-182
KevLehman Jul 8, 2025
0facbdc
fix
KevLehman Jul 8, 2025
d9e2196
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino Jul 8, 2025
7e0ba9a
fix: merge conflicts
lucas-a-pelegrino Jul 8, 2025
17586cd
chore: adds minor improvements to typing to ensure reusability across…
lucas-a-pelegrino Jul 8, 2025
5e37cc9
fix 2
KevLehman Jul 8, 2025
03e6f77
Create new-mails-rhyme.md
KevLehman Jul 8, 2025
3c4d938
fix: merge conflicts
lucas-a-pelegrino Jul 8, 2025
a7c4892
Update apps/meteor/ee/app/livechat-enterprise/server/api/lib/outbound.ts
KevLehman Jul 9, 2025
f0a5f34
Merge branch 'feat/CTZ-182' of github.com:RocketChat/Rocket.Chat into…
lucas-a-pelegrino Jul 9, 2025
84edd67
Update apps/meteor/ee/app/livechat-enterprise/server/api/lib/outbound.ts
KevLehman Jul 9, 2025
5721a3f
chore: refactor endpoints definition to meet new pattern
lucas-a-pelegrino Jul 9, 2025
d656934
Merge branch 'feat/CTZ-182' of github.com:RocketChat/Rocket.Chat into…
lucas-a-pelegrino Jul 9, 2025
e195b37
fix: imports mismatches, ajv typings
lucas-a-pelegrino Jul 9, 2025
6cbd5fd
Merge branch 'develop' into feat/CTZ-182
kodiakhq[bot] Jul 10, 2025
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
33 changes: 33 additions & 0 deletions apps/meteor/ee/app/livechat-enterprise/server/api/lib/outbound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { IOutboundMessageProviders } from '@rocket.chat/apps-engine/definition/outboundComunication';
import type { IOutboundProvider } from '@rocket.chat/core-typings';

import { OutboundMessageProvider } from '../../../../../../server/lib/OutboundMessageProvider';

export class OutboundMessageProviderService {
private readonly provider: OutboundMessageProvider;

constructor() {
this.provider = new OutboundMessageProvider();
}

private isProviderValid(type?: string): type is 'phone' | 'email' {
Comment thread
KevLehman marked this conversation as resolved.
Outdated
return type === 'phone' || type === 'email';
Comment thread
KevLehman marked this conversation as resolved.
Outdated
}

public listOutboundProviders(type?: string): IOutboundProvider[] {
if (type !== undefined && !this.isProviderValid(type)) {
throw new Error('Invalid type');
}

const providers = this.provider.getOutboundMessageProviders(type);

return providers.map<IOutboundProvider>((provider: IOutboundMessageProviders) => {
return {
providerId: provider.appId,
providerName: provider.name,
supportsTemplates: true,
providerType: provider.type,
};
Comment thread
KevLehman marked this conversation as resolved.
Outdated
});
}
}
35 changes: 35 additions & 0 deletions apps/meteor/ee/app/livechat-enterprise/server/api/outbound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { API } from '../../../../../app/api/server';
import { isGETOutboundProviderParams } from '../outboundcomms/rest';
import { OutboundMessageProviderService } from './lib/outbound';

const outboundMessageProvider = new OutboundMessageProviderService();
Comment thread
KevLehman marked this conversation as resolved.
Outdated

API.v1.addRoute(
'omnichannel/outbound/providers',
{ authRequired: true, validateParams: isGETOutboundProviderParams },
{
async get() {
const { type } = this.queryParams;

const providers = outboundMessageProvider.listOutboundProviders(type);

try {
return API.v1.success({
providers,
});
} catch (error) {
return API.v1.failure(error);
}
Comment thread
KevLehman marked this conversation as resolved.
Outdated
},
},
);

API.v1.addRoute(
'omnichannel/outbound/providers/:id/metadata',
{ authRequired: true },
{
async get() {
return API.v1.success();
},
},
);
Comment thread
KevLehman marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { OutboundMessageProviderService } from '../../../../../../ee/app/livechat-enterprise/server/api/lib/outbound';

jest.mock('./outbound', () => {
return {
OutboundMessageProvider: jest.fn().mockImplementation(() => {
return {
getOutboundMessageProviders: jest.fn((type?: string) => {
if (type === 'phone') {
return [{ appId: '1', name: 'PhoneProvider', type: 'phone' }];
}
if (type === 'email') {
return [{ appId: '2', name: 'EmailProvider', type: 'email' }];
}
return [
{ appId: '1', name: 'PhoneProvider', type: 'phone' },
{ appId: '2', name: 'EmailProvider', type: 'email' },
];
}),
};
}),
};
});

describe('OutboundMessageProviderService', () => {
let service: OutboundMessageProviderService;

beforeEach(() => {
service = new OutboundMessageProviderService();
});

it('should return all providers when type is not specified', () => {
const result = service.listOutboundProviders();
expect(result).toEqual([
{ providerId: '1', providerName: 'PhoneProvider', supportsTemplates: true, providerType: 'phone' },
{ providerId: '2', providerName: 'EmailProvider', supportsTemplates: true, providerType: 'email' },
]);
});

it('should return phone providers when type is "phone"', () => {
const result = service.listOutboundProviders('phone');
expect(result).toEqual([{ providerId: '1', providerName: 'PhoneProvider', supportsTemplates: true, providerType: 'phone' }]);
});

it('should return email providers when type is "email"', () => {
const result = service.listOutboundProviders('email');
expect(result).toEqual([{ providerId: '2', providerName: 'EmailProvider', supportsTemplates: true, providerType: 'email' }]);
});

it('should throw an error when type is invalid', () => {
expect(() => service.listOutboundProviders('invalid')).toThrow('Invalid type');
});
});
Loading