Skip to content

Commit

Permalink
Chore: Add extra stats for omnichannel video calling (#28211)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Mar 2, 2023
1 parent 10c0b41 commit a618eb6
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/meteor/app/models/server/models/LivechatRooms.js
Expand Up @@ -36,7 +36,10 @@ export class LivechatRooms extends Base {
);
this.tryEnsureIndex({ 'livechatData.$**': 1 });
this.tryEnsureIndex({ pdfTranscriptRequested: 1 }, { sparse: true });
this.tryEnsureIndex({ pdfTranscriptFileId: 1 }, { sparse: true });
this.tryEnsureIndex({ pdfTranscriptFileId: 1 }, { sparse: true }); // used on statistics
this.tryEnsureIndex({ callStatus: 1 }, { sparse: true }); // used on statistics
this.tryEnsureIndex({ priorityId: 1 }, { sparse: true });
this.tryEnsureIndex({ slaId: 1 }, { sparse: true });
}

findOneByIdOrName(_idOrName, options) {
Expand Down
32 changes: 32 additions & 0 deletions apps/meteor/app/statistics/server/lib/statistics.ts
Expand Up @@ -22,6 +22,8 @@ import {
Roles as RolesRaw,
InstanceStatus,
Settings,
LivechatTrigger,
LivechatCustomField,
} from '@rocket.chat/models';
import { Analytics, Team, VideoConf } from '@rocket.chat/core-services';

Expand Down Expand Up @@ -124,6 +126,7 @@ export const statistics = {

// livechat agents
statistics.totalLivechatAgents = Users.findAgents().count();
statistics.totalLivechatManagers = await UsersRaw.col.countDocuments({ roles: 'livechat-manager' });

// livechat enabled
statistics.livechatEnabled = settings.get('Livechat_enabled');
Expand All @@ -149,6 +152,30 @@ export const statistics = {
}),
);

// Number of archived departments
statsPms.push(
LivechatDepartment.col.countDocuments({ archived: true }).then((count) => {
statistics.archivedDepartments = count;
}),
);

// Workspace allows dpeartment removal
statistics.isDepartmentRemovalEnabled = settings.get('Omnichannel_enable_department_removal');

// Number of triggers
statsPms.push(
LivechatTrigger.col.count().then((count) => {
statistics.totalTriggers = count;
}),
);

// Number of custom fields
statsPms.push(
LivechatCustomField.col.count().then((count) => {
statistics.totalCustomFields = count;
}),
);

// Type of routing algorithm used on omnichannel
statistics.routingAlgorithm = settings.get('Livechat_Routing_Method') || '';

Expand Down Expand Up @@ -503,6 +530,11 @@ export const statistics = {

statistics.matrixFederation = await getMatrixFederationStatistics();

// Omnichannel call stats
statistics.webRTCEnabled = settings.get('WebRTC_Enabled');
statistics.webRTCEnabledForOmnichannel = settings.get('Omnichannel_call_provider') === 'WebRTC';
statistics.omnichannelWebRTCCalls = await RoomsRaw.findCountOfRoomsWithActiveCalls();

await Promise.all(statsPms).catch(log);

return statistics;
Expand Down
Expand Up @@ -76,6 +76,11 @@ export default {
totalRoomsInsideTeams: 0,
totalDefaultRoomsInsideTeams: 0,
},
totalLivechatManagers: 10,
totalCustomFields: 10,
totalTriggers: 1,
isDepartmentRemovalEnabled: false,
archivedDepartments: 0,
totalLivechatVisitors: 0,
totalLivechatAgents: 0,
livechatEnabled: false,
Expand Down Expand Up @@ -146,6 +151,9 @@ export default {
voipSuccessfulCalls: 0,
voipErrorCalls: 0,
voipOnHoldCalls: 0,
webRTCEnabled: false,
webRTCEnabledForOmnichannel: false,
omnichannelWebRTCCalls: 1,
federationOverviewData: {
numberOfEvents: 0,
numberOfFederatedUsers: 0,
Expand Down
Expand Up @@ -106,6 +106,11 @@ export default {
totalRoomsInsideTeams: 0,
totalDefaultRoomsInsideTeams: 0,
},
totalLivechatManagers: 10,
totalCustomFields: 10,
totalTriggers: 1,
isDepartmentRemovalEnabled: false,
archivedDepartments: 0,
totalLivechatVisitors: 0,
totalLivechatAgents: 0,
livechatEnabled: false,
Expand Down Expand Up @@ -176,6 +181,9 @@ export default {
voipSuccessfulCalls: 0,
voipErrorCalls: 0,
voipOnHoldCalls: 0,
webRTCEnabled: false,
webRTCEnabledForOmnichannel: false,
omnichannelWebRTCCalls: 1,
federationOverviewData: {
numberOfEvents: 0,
numberOfFederatedUsers: 0,
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/client/views/admin/info/UsageCard.stories.tsx
Expand Up @@ -54,6 +54,11 @@ export default {
totalRoomsInsideTeams: 0,
totalDefaultRoomsInsideTeams: 0,
},
totalLivechatManagers: 10,
totalCustomFields: 10,
totalTriggers: 1,
isDepartmentRemovalEnabled: false,
archivedDepartments: 0,
totalLivechatVisitors: 0,
totalLivechatAgents: 0,
livechatEnabled: false,
Expand Down Expand Up @@ -124,6 +129,9 @@ export default {
voipSuccessfulCalls: 0,
voipErrorCalls: 0,
voipOnHoldCalls: 0,
webRTCEnabled: false,
webRTCEnabledForOmnichannel: false,
omnichannelWebRTCCalls: 1,
federationOverviewData: {
numberOfEvents: 0,
numberOfFederatedUsers: 0,
Expand Down
27 changes: 26 additions & 1 deletion apps/meteor/ee/app/license/server/getStatistics.ts
@@ -1,6 +1,6 @@
import { log } from 'console';

import { CannedResponse, OmnichannelServiceLevelAgreements, LivechatRooms, LivechatTag, LivechatUnit } from '@rocket.chat/models';
import { CannedResponse, OmnichannelServiceLevelAgreements, LivechatRooms, LivechatTag, LivechatUnit, Users } from '@rocket.chat/models';
import { Analytics } from '@rocket.chat/core-services';

import { getModules, getTags, hasLicense } from './license';
Expand All @@ -21,6 +21,9 @@ type EEOnlyStats = {
businessUnits: number;
omnichannelPdfTranscriptRequested: number;
omnichannelPdfTranscriptSucceeded: number;
omnichannelRoomsWithSlas: number;
omnichannelRoomsWithPriorities: number;
livechatMonitors: number;
};

export async function getStatistics(): Promise<ENTERPRISE_STATISTICS> {
Expand Down Expand Up @@ -74,6 +77,20 @@ async function getEEStatistics(): Promise<EEOnlyStats | undefined> {
}),
);

statsPms.push(
LivechatRooms.col.countDocuments({ priorityId: { $exists: true } }).then((count) => {
statistics.omnichannelRoomsWithPriorities = count;
return true;
}),
);

statsPms.push(
LivechatRooms.col.countDocuments({ slaId: { $exists: true } }).then((count) => {
statistics.omnichannelRoomsWithSlas = count;
return true;
}),
);

// Number of business units
statsPms.push(
LivechatUnit.find({ type: 'u' })
Expand All @@ -84,6 +101,14 @@ async function getEEStatistics(): Promise<EEOnlyStats | undefined> {
}),
);

statsPms.push(
// Total livechat monitors
Users.col.countDocuments({ type: 'livechat-monitor' }).then((count) => {
statistics.livechatMonitors = count;
return true;
}),
);

// Number of PDF transcript requested
statsPms.push(
LivechatRooms.find({ pdfTranscriptRequested: { $exists: true } })
Expand Down
9 changes: 9 additions & 0 deletions apps/meteor/server/models/raw/Rooms.js
Expand Up @@ -704,4 +704,13 @@ export class RoomsRaw extends BaseRaw {

return this.find(query, options);
}

findCountOfRoomsWithActiveCalls() {
const query = {
// No matter the actual "status" of the call, if the room has a callStatus, it means there is/was a call
callStatus: { $exists: true },
};

return this.col.countDocuments(query);
}
}
8 changes: 8 additions & 0 deletions packages/core-typings/src/IStats.ts
Expand Up @@ -33,11 +33,15 @@ export interface IStats {
teams: ITeamStats;
totalLivechatVisitors: number;
totalLivechatAgents: number;
totalLivechatManagers: number;
totalCustomFields: number;
livechatEnabled: boolean;
isDepartmentRemovalEnabled: boolean;
totalChannelMessages: number;
totalPrivateGroupMessages: number;
totalDirectMessages: number;
totalLivechatMessages: number;
totalTriggers: number;
totalMessages: number;
federatedServers: number;
federatedUsers: number;
Expand Down Expand Up @@ -82,6 +86,7 @@ export interface IStats {
pushQueue: number;
omnichannelSources: { [key: string]: number | string }[];
departments: number;
archivedDepartments: number;
routingAlgorithm: string;
onHoldEnabled: boolean;
emailInboxes: number;
Expand Down Expand Up @@ -200,4 +205,7 @@ export interface IStats {
matrixFederation: {
enabled: boolean;
};
webRTCEnabled: boolean;
webRTCEnabledForOmnichannel: boolean;
omnichannelWebRTCCalls: number;
}
1 change: 1 addition & 0 deletions packages/model-typings/src/models/IRoomsModel.ts
Expand Up @@ -103,4 +103,5 @@ export interface IRoomsModel extends IBaseModel<IRoom> {
findPaginatedByTypeAndIds(type: IRoom['t'], ids: string[], options?: FindOptions<IRoom>): FindPaginated<FindCursor<IRoom>>;

findFederatedRooms(options?: FindOptions<IRoom>): FindCursor<IRoom>;
findCountOfRoomsWithActiveCalls(): Promise<number>;
}

0 comments on commit a618eb6

Please sign in to comment.