feat: adds new endpoint to fetch outbound provider metadata (#36424)

Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
pull/36497/head^2
Lucas Pelegrino 6 months ago committed by GitHub
parent 960a9149dd
commit 296b29bbf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/giant-toes-decide.md
  2. 89
      apps/meteor/ee/app/livechat-enterprise/server/api/outbound.ts
  3. 183
      apps/meteor/ee/app/livechat-enterprise/server/outboundcomms/rest.ts

@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---
Adds an endpoint to fetch a Outbound Comms Provider's metadata.

@ -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>;

@ -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';
@ -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;
@ -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…
Cancel
Save