Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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,
isGETOutboundProviderParams,
IsOutboundProviderBadRequestErrorSchema,
isOutboundProviderMetadataSchema,
} 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: IsOutboundProviderBadRequestErrorSchema,
Comment thread
KevLehman marked this conversation as resolved.
Outdated
},
query: isGETOutboundProviderParams,
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: isOutboundProviderMetadataSchema,
Comment thread
KevLehman marked this conversation as resolved.
Outdated
400: IsOutboundProviderBadRequestErrorSchema,
},
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>;
181 changes: 180 additions & 1 deletion 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 Down Expand Up @@ -26,6 +26,48 @@
};
export const isGETOutboundProviderParams = ajv.compile<GETOutboundProviderParams>(GETOutboundProviderSchema);

const isGETOutboundProvidersResponse = {
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[]}>(isGETOutboundProvidersResponse);

Check failure on line 54 in apps/meteor/ee/app/livechat-enterprise/server/outboundcomms/rest.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Insert `·`

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

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

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 isOutboundProviderMetadataSchema = ajv.compile<{ metadata: IOutboundProviderMetadata }>(OutboundProviderMetadataSchema);
Loading