Skip to content

Commit 7cb10bc

Browse files
committed
Merge remote-tracking branch 'origin/new/livechat-voip' into livechat-voip/registration-wiring
2 parents c4a9649 + be172ee commit 7cb10bc

File tree

19 files changed

+757
-141
lines changed

19 files changed

+757
-141
lines changed

app/api/server/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import './v1/instances';
4444
import './v1/banners';
4545
import './v1/email-inbox';
4646
import './v1/teams';
47-
import './v1/voip/asterisk-connector';
47+
import './v1/voip/extensions';
48+
import './v1/voip/queues';
4849
import './v1/voip/server-config';
4950

5051
export { API, APIClass, defaultRateLimiterOptions } from './api';

app/api/server/v1/voip/asterisk-connector.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import { Match, check } from 'meteor/check';
3+
4+
import { API } from '../../api';
5+
import { Voip } from '../../../../../server/sdk';
6+
import { IVoipExtensionBase } from '../../../../../definition/IVoipExtension';
7+
import { IVoipConnectorResult } from '../../../../../definition/IVoipConnectorResult';
8+
9+
// Get the connector version and type
10+
API.v1.addRoute('connector.getVersion', { authRequired: true }, {
11+
get() {
12+
const version = Promise.await(Voip.getConnectorVersion());
13+
return API.v1.success(version);
14+
},
15+
});
16+
17+
// Get the extensions available on the call server
18+
API.v1.addRoute('connector.extension.list', { authRequired: true }, {
19+
get() {
20+
const list = Promise.await(Voip.getExtensionList()) as IVoipConnectorResult;
21+
const result: IVoipExtensionBase[] = list.result as IVoipExtensionBase[];
22+
this.logger.debug({ msg: 'API = connector.extension.list length ', result: result.length });
23+
return API.v1.success({ extensions: result });
24+
},
25+
});
26+
27+
/* Get the details of a single extension.
28+
* Note : This API will either be called by the endpoint
29+
* or will be consumed internally.
30+
*/
31+
API.v1.addRoute('connector.extension.getDetails', { authRequired: true }, {
32+
get() {
33+
check(this.requestParams(), Match.ObjectIncluding({
34+
extension: String,
35+
}));
36+
const endpointDetails = Promise.await(Voip.getExtensionDetails(this.requestParams())) as IVoipConnectorResult;
37+
this.logger.debug({ msg: 'API = connector.extension.getDetails', result: endpointDetails.result });
38+
return API.v1.success({ ...endpointDetails.result });
39+
},
40+
});
41+
42+
/* Get the details for registration extension.
43+
*/
44+
API.v1.addRoute('connector.extension.getRegistrationInfo', { authRequired: true }, {
45+
get() {
46+
check(this.requestParams(), Match.ObjectIncluding({
47+
extension: String,
48+
}));
49+
const endpointDetails = Promise.await(Voip.getRegistrationInfo(this.requestParams()));
50+
this.logger.debug({ msg: 'API = connector.extension.getRegistrationInfo', result: endpointDetails });
51+
return API.v1.success({ ...endpointDetails.result });
52+
},
53+
});

app/api/server/v1/voip/queues.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Match, check } from 'meteor/check';
2+
3+
import { API } from '../../api';
4+
import { Voip } from '../../../../../server/sdk';
5+
import { IVoipConnectorResult } from '../../../../../definition/IVoipConnectorResult';
6+
7+
API.v1.addRoute('voip/queues.getSummary', { authRequired: true }, {
8+
get() {
9+
const queueSummary = Promise.await(Voip.getQueueSummary()) as IVoipConnectorResult;
10+
this.logger.debug({ msg: 'API = voip/queues.getSummary ', result: queueSummary });
11+
return API.v1.success({ summary: queueSummary.result });
12+
},
13+
});
14+
15+
API.v1.addRoute('voip/queues.getQueuedCallsForThisExtension', { authRequired: true }, {
16+
get() {
17+
check(this.requestParams(), Match.ObjectIncluding({
18+
extension: String,
19+
}));
20+
const membershipDetails: IVoipConnectorResult = Promise.await(Voip.getQueuedCallsForThisExtension(this.requestParams()));
21+
this.logger.debug({ msg: 'API = queues.getCallWaitingInQueuesForThisExtension', result: membershipDetails });
22+
return API.v1.success({ ...membershipDetails.result });
23+
},
24+
});

definition/ACDQueues.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export interface IQueueSummary {
2+
name: string;
3+
loggedin: string;
4+
available: string;
5+
callers: string;
6+
holdtime: string;
7+
talktime: string;
8+
logestholdtime: string;
9+
}
10+
export interface IQueueMember {
11+
name: string;
12+
location: string;
13+
stateinterface: string;
14+
membership: string;
15+
penalty: string;
16+
callstaken: string;
17+
lastcall: string;
18+
lastpause: string;
19+
incall: string;
20+
status: string;
21+
paused: string;
22+
pausedreason: string;
23+
wrapuptime: string;
24+
}
25+
export interface IQueueDetails {
26+
name: string;
27+
strategy: string;
28+
calls: string;
29+
holdtime: string;
30+
talktime: string;
31+
completed: string;
32+
abandoned: string;
33+
logestholdtime: string;
34+
members: IQueueMember [];
35+
}

definition/IVoipConnectorResult.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { IVoipExtensionConfig, IVoipExtensionBase, IQueueMembershipDetails, IRegistrationInfo } from './IVoipExtension';
2+
import { IQueueDetails, IQueueSummary } from './ACDQueues';
3+
4+
export interface IVoipConnectorResult {
5+
result: IVoipExtensionConfig | IVoipExtensionBase [] | IQueueSummary [] | IQueueDetails | IQueueMembershipDetails | IRegistrationInfo;
6+
}

definition/IVoipExtension.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ICallServerConfigData } from './IVoipServerConfig';
2+
13
export enum EndpointState {
24
UNKNOWN = 'unknown',
35
REGISTERED = 'registered',
@@ -11,3 +13,22 @@ export interface IVoipExtensionConfig extends IVoipExtensionBase{
1113
authType: string;
1214
password: string;
1315
}
16+
17+
export interface IQueueMembershipDetails {
18+
extension: string;
19+
queueCount: number;
20+
callWaitingCount: number;
21+
}
22+
23+
export interface IExtensionDetails {
24+
extension: string;
25+
password: string;
26+
authtype: string;
27+
state: string;
28+
}
29+
30+
export interface IRegistrationInfo {
31+
host: string;
32+
callServerConfig: ICallServerConfigData;
33+
extensionDetails: IExtensionDetails;
34+
}

server/sdk/types/IVoipService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { IVoipServerConfig, ServerType } from '../../../definition/IVoipServerConfig';
2+
import { CommandHandler } from '../../services/voip/connector/asterisk/CommandHandler';
3+
import { IVoipConnectorResult } from '../../../definition/IVoipConnectorResult';
24

35
export interface IVoipService {
46
getConfiguration(): any;
57
getServerConfigData(serverType: ServerType): Promise<IVoipServerConfig | null>;
68
addServerConfigData(config: Omit<IVoipServerConfig, '_id' | '_updatedAt'>): Promise<boolean>;
79
updateServerConfigData(config: Omit<IVoipServerConfig, '_id' | '_updatedAt'>): Promise<boolean>;
810
deactivateServerConfigDataIfAvailable(serverType: ServerType): Promise<boolean>;
11+
getConnector(): Promise<CommandHandler>;
12+
getConnectorVersion(): Promise<string>;
13+
getQueueSummary(): Promise<IVoipConnectorResult>;
14+
getQueuedCallsForThisExtension(requestParams: any): Promise<IVoipConnectorResult>;
15+
getExtensionList(): Promise<IVoipConnectorResult>;
16+
getExtensionDetails(requestParams: any): Promise<IVoipConnectorResult>;
17+
getRegistrationInfo(requestParams: any): Promise<IVoipConnectorResult>;
918
}

server/services/voip/connector/asterisk/Command.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IConnection } from './IConnection';
2-
import { IVoipExtensionConfig, IVoipExtensionBase } from '../../../../../definition/IVoipExtension';
2+
import { IVoipConnectorResult } from '../../../../../definition/IVoipConnectorResult';
3+
34
/**
45
* This class serves as a a base class for the different kind of call server objects
56
* @remarks
@@ -40,14 +41,14 @@ export class Command {
4041
this._connection = connection;
4142
}
4243

43-
private _actionId: any | undefined;
44+
private _actionid: any | undefined;
4445

45-
get actionId(): any {
46-
return this._actionId;
46+
get actionid(): any {
47+
return this._actionid;
4748
}
4849

49-
set actionId(id) {
50-
this._actionId = id;
50+
set actionid(id) {
51+
this._actionid = id;
5152
}
5253

5354
private _result: any;
@@ -83,6 +84,7 @@ export class Command {
8384

8485
constructor(command: string, parametersNeeded: boolean) {
8586
this._commandText = command;
87+
this._actionid = -1;
8688
this._parametersNeeded = parametersNeeded;
8789
this.result = {};
8890
}
@@ -99,7 +101,7 @@ export class Command {
99101
return returnPromise;
100102
}
101103

102-
executeCommand(_data: any): Promise <IVoipExtensionConfig | IVoipExtensionBase []> {
104+
executeCommand(_data: any): Promise <IVoipConnectorResult> {
103105
return new Promise((_resolve, _reject) => {
104106
_reject('unimplemented');
105107
});

server/services/voip/connector/asterisk/CommandHandler.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,52 @@ import { Logger } from '../../../../lib/logger/Logger';
2020
import { CommandType } from './Command';
2121
import { AMIConnection } from './ami/AMIConnection';
2222
import { CommandFactory } from './ami/CommandFactory';
23-
import { IVoipExtensionConfig, IVoipExtensionBase } from '../../../../../definition/IVoipExtension';
23+
import { IVoipConnectorResult } from '../../../../../definition/IVoipConnectorResult';
24+
import { IVoipService } from '../../../../sdk/types/IVoipService';
25+
import { IManagementConfigData, IVoipServerConfig, ServerType } from '../../../../../definition/IVoipServerConfig';
2426

2527
const version = 'Asterisk Connector 1.0';
2628

2729
export class CommandHandler {
2830
private connections: Map<CommandType, IConnection>;
2931

32+
private service: IVoipService;
33+
3034
private logger: Logger;
3135

32-
constructor() {
36+
constructor(service: IVoipService) {
3337
this.logger = new Logger('CommandHandler');
3438
this.connections = new Map<CommandType, IConnection>();
39+
this.service = service;
40+
}
3541

42+
async initConnection(commandType: CommandType): Promise<void> {
3643
// Initialize available connections
3744
// const connection = new AMIConnection();
3845
const connection = new AMIConnection();
39-
/* TODO(Amol) : This information must come from
40-
* an API/Database.
41-
* Currently hardcoded. Hence commenting the code
46+
let config: IVoipServerConfig | null = null;
47+
if (commandType === CommandType.AMI) {
48+
config = await this.service.getServerConfigData(ServerType.MANAGEMENT);
49+
}
50+
if (!config) {
51+
this.logger.warn('Management server configuration not found');
52+
throw Error('Management server configuration not found');
53+
}
54+
/**
55+
* If we have the same type of connection already established, close it
56+
* and remove it from the map.
4257
*/
43-
connection.connect('omni-asterisk.dev.rocket.chat',
44-
'5038',
45-
'amol',
46-
'1234');
47-
this.connections.set(CommandType.AMI, connection);
58+
if (this.connections.get(commandType)?.isConnected()) {
59+
this.logger.error({ msg: 'connection exists. Closing the connection.' });
60+
this.connections.get(commandType)?.closeConnection();
61+
this.connections.delete(commandType);
62+
}
63+
connection.connect(config.host,
64+
(config.configData as IManagementConfigData).port.toString(),
65+
(config.configData as IManagementConfigData).username,
66+
(config.configData as IManagementConfigData).password,
67+
);
68+
this.connections.set(commandType, connection);
4869
}
4970

5071
/* Executes |commandToExecute| on a particular command object
@@ -55,7 +76,7 @@ export class CommandHandler {
5576
* This function returns a promise. Caller can wait for the promise to resolve
5677
* or rejected.
5778
*/
58-
executeCommand(commandToExecute: Commands, commandData: any): Promise<IVoipExtensionConfig | IVoipExtensionBase []> {
79+
executeCommand(commandToExecute: Commands, commandData?: any): Promise<IVoipConnectorResult> {
5980
this.logger.debug({ msg: `executeCommand() executing ${ Commands[commandToExecute] }` });
6081
const command = CommandFactory.getCommandObject(commandToExecute);
6182
command.connection = this.connections.get(command.type) as IConnection;

0 commit comments

Comments
 (0)