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
5 changes: 5 additions & 0 deletions .changeset/giant-toes-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Adds an endpoint to fetch a Outbound Comms Provider's metadata.
89 changes: 42 additions & 47 deletions apps/meteor/ee/app/livechat-enterprise/server/api/outbound.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
import type { IOutboundProvider } from '@rocket.chat/core-typings';
import { ajv } from '@rocket.chat/rest-typings';

import { API } from '../../../../../app/api/server';
import { isGETOutboundProviderParams } from '../outboundcomms/rest';
import {
GETOutboundProvidersResponseSchema,
GETOutboundProviderParamsSchema,
GETOutboundProviderBadRequestErrorSchema,
GETOutboundProviderMetadataSchema,
} from '../outboundcomms/rest';
import { outboundMessageProvider } from './lib/outbound';
import type { ExtractRoutesFromAPI } from '../../../../../app/api/server/ApiClass';

const outboundCommsEndpoints = API.v1.get(
'omnichannel/outbound/providers',
{
response: {
200: ajv.compile<{ providers: IOutboundProvider[] }>({
type: 'object',
properties: {
providers: {
type: 'array',
items: {
type: 'object',
properties: {
providerId: {
type: 'string',
},
providerName: {
type: 'string',
},
supportsTemplates: {
type: 'boolean',
},
providerType: {
type: 'string',
},
documentationUrl: {
type: 'string',
},
},
},
},
},
}),
const outboundCommsEndpoints = API.v1
.get(
'omnichannel/outbound/providers',
{
response: {
200: GETOutboundProvidersResponseSchema,
400: GETOutboundProviderBadRequestErrorSchema,
},
query: GETOutboundProviderParamsSchema,
authRequired: true,
},
query: isGETOutboundProviderParams,
authRequired: true,
},
async function action() {
const { type } = this.queryParams;
async function action() {
const { type } = this.queryParams;

const providers = outboundMessageProvider.listOutboundProviders(type);
return API.v1.success({
providers,
});
},
);
const providers = outboundMessageProvider.listOutboundProviders(type);
return API.v1.success({
providers,
});
},
)
.get(
'omnichannel/outbound/providers/:id/metadata',
{
response: {
200: GETOutboundProviderMetadataSchema,
400: GETOutboundProviderBadRequestErrorSchema,
},
authRequired: true,
},
async function action() {
const { id } = this.urlParams;

const providerMetadata = await outboundMessageProvider.getProviderMetadata(id);
return API.v1.success({
metadata: providerMetadata,
});
},
);

export type OutboundCommsEndpoints = ExtractRoutesFromAPI<typeof outboundCommsEndpoints>;
183 changes: 181 additions & 2 deletions apps/meteor/ee/app/livechat-enterprise/server/outboundcomms/rest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IOutboundMessage } from '@rocket.chat/core-typings';
import type { IOutboundMessage, IOutboundProvider, IOutboundProviderMetadata } from '@rocket.chat/core-typings';
import Ajv from 'ajv';

import type { OutboundCommsEndpoints } from '../api/outbound';
Expand All @@ -24,7 +24,49 @@ const GETOutboundProviderSchema = {
required: [],
additionalProperties: false,
};
export const isGETOutboundProviderParams = ajv.compile<GETOutboundProviderParams>(GETOutboundProviderSchema);
export const GETOutboundProviderParamsSchema = ajv.compile<GETOutboundProviderParams>(GETOutboundProviderSchema);

const GETOutboundProvidersResponse = {
type: 'object',
properties: {
providers: {
type: 'array',
items: {
type: 'object',
properties: {
providerId: {
type: 'string',
},
providerName: {
type: 'string',
},
supportsTemplates: {
type: 'boolean',
},
providerType: {
type: 'string',
},
},
},
},
},
};
export const GETOutboundProvidersResponseSchema = ajv.compile<{ providers: IOutboundProvider[] }>(GETOutboundProvidersResponse);

const GETOutboundProviderBadRequestError = {
type: 'object',
properties: {
success: {
type: 'boolean',
},
message: {
type: 'string',
},
},
};
export const GETOutboundProviderBadRequestErrorSchema = ajv.compile<{ success: boolean; message: string }>(
GETOutboundProviderBadRequestError,
);

type POSTOutboundMessageParams = {
message: IOutboundMessage;
Expand Down Expand Up @@ -142,3 +184,140 @@ const POSTOutboundMessageSchema = {
};

export const isPOSTOutboundMessageParams = ajv.compile<POSTOutboundMessageParams>(POSTOutboundMessageSchema);

const OutboundProviderMetadataSchema = {
type: 'object',
properties: {
metadata: {
type: 'object',
properties: {
providerId: {
type: 'string',
},
providerName: {
type: 'string',
},
supportsTemplates: {
type: 'boolean',
},
providerType: {
type: 'string',
enum: ['phone', 'email'],
},
templates: {
type: 'object',
additionalProperties: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string',
},
name: {
type: 'string',
},
language: {
type: 'string',
},
type: {
type: 'string',
},
category: {
type: 'string',
},
status: {
type: 'string',
},
qualityScore: {
type: 'object',
required: ['score', 'reasons'],
properties: {
score: {
type: 'string',
enum: ['GREEN', 'YELLOW', 'RED', 'UNKNOWN'],
},
reasons: {
type: ['array', 'null'],
items: {
type: 'string',
},
},
},
},
components: {
type: 'array',
items: {
type: 'object',
oneOf: [
{
properties: {
type: { const: 'HEADER' },
format: {
type: 'string',
enum: ['TEXT', 'IMAGE', 'VIDEO', 'DOCUMENT'],
},
text: { type: 'string' },
example: {
type: 'object',
properties: {
headerText: {
type: 'array',
items: { type: 'string' },
},
},
},
},
},
{
properties: {
type: { const: 'BODY' },
text: { type: 'string' },
example: {
type: 'object',
properties: {
bodyText: {
type: 'array',
items: {
type: 'array',
items: { type: 'string' },
},
},
},
},
},
required: ['type', 'text'],
},
{
properties: {
type: { const: 'FOOTER' },
text: { type: 'string' },
},
required: ['type', 'text'],
},
],
},
},
createdAt: { type: 'string' },
createdBy: { type: 'string' },
modifiedAt: { type: 'string' },
modifiedBy: { type: 'string' },
namespace: { type: 'string' },
wabaAccountId: { type: 'string' },
phoneNumber: { type: 'string' },
partnerId: { type: 'string' },
externalId: { type: 'string' },
updatedExternal: { type: 'string' },
rejectedReason: {
type: ['string', 'null'],
},
},
},
},
},
},
},
},
};

export const GETOutboundProviderMetadataSchema = ajv.compile<{ metadata: IOutboundProviderMetadata }>(OutboundProviderMetadataSchema);
Loading