Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Allow Omnichannel statistics to be collected. #23694

Merged
merged 10 commits into from
Nov 17, 2021
1 change: 1 addition & 0 deletions app/models/server/models/LivechatRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class LivechatRooms extends Base {
this.tryEnsureIndex({ 'v.token': 1, 'email.thread': 1 }, { sparse: true });
this.tryEnsureIndex({ 'v._id': 1 }, { sparse: true });
this.tryEnsureIndex({ t: 1, departmentId: 1, closedAt: 1 }, { partialFilterExpression: { closedAt: { $exists: true } } });
this.tryEnsureIndex({ source: 1 }, { sparse: true });
}

findLivechat(filter = {}, offset = 0, limit = 20) {
Expand Down
19 changes: 19 additions & 0 deletions app/models/server/raw/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,23 @@ export class RoomsRaw extends BaseRaw {
findOneByNameOrFname(name, options = {}) {
return this.col.findOne({ $or: [{ name }, { fname: name }] }, options);
}

allRoomSourcesCount() {
return this.col.aggregate([
{
$match: {
source: {
$exists: true,
},
cauefcr marked this conversation as resolved.
Show resolved Hide resolved
t: 'l',
},
},
{
$group: {
_id: '$source',
count: { $sum: 1 },
},
},
]);
}
}
13 changes: 12 additions & 1 deletion app/statistics/server/lib/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { settings } from '../../../settings/server';
import { Info, getMongoInfo } from '../../../utils/server';
import { getControl } from '../../../../server/lib/migrations';
import { getStatistics as federationGetStatistics } from '../../../federation/server/functions/dashboard';
import { NotificationQueue, Users as UsersRaw, Statistics, Sessions, Integrations, Uploads } from '../../../models/server/raw';
import { NotificationQueue, Users as UsersRaw, Rooms as RoomsRaw, Statistics, Sessions, Integrations, Uploads } from '../../../models/server/raw';
import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
import { getAppsStatistics } from './getAppsStatistics';
import { getServicesStatistics } from './getServicesStatistics';
Expand Down Expand Up @@ -116,6 +116,17 @@ export const statistics = {
// livechat enabled
statistics.livechatEnabled = settings.get('Livechat_enabled');

// Count and types of omnichannel rooms
statistics.omnichannelSources = Promise.await(RoomsRaw.allRoomSourcesCount().toArray()).map(({
_id: { id, alias, type },
count,
}) => ({
id,
alias,
type,
count,
}));

// Message statistics
statistics.totalChannelMessages = _.reduce(Rooms.findByType('c', { fields: { msgs: 1 } }).fetch(), function _countChannelMessages(num, room) { return num + room.msgs; }, 0);
statistics.totalPrivateGroupMessages = _.reduce(Rooms.findByType('p', { fields: { msgs: 1 } }).fetch(), function _countPrivateGroupMessages(num, room) { return num + room.msgs; }, 0);
Expand Down