@tuanltntu/n8n-nodes-bitrix24
Version:
Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more
379 lines • 16.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TelephonyResourceHandler = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const ResourceHandlerBase_1 = require("./ResourceHandlerBase");
/**
* Handler for Bitrix24 Telephony operations
*/
class TelephonyResourceHandler extends ResourceHandlerBase_1.ResourceHandlerBase {
constructor(executeFunctions, returnData, options = {}) {
super(executeFunctions, returnData, options);
this.endpoints = {
// External Call Operations - Confirmed endpoints
externalCallRegister: "telephony.externalcall.register",
externalCallFinish: "telephony.externalcall.finish",
externalCallHide: "telephony.externalcall.hide",
externalCallShow: "telephony.externalcall.show",
externalCallSearchCrm: "telephony.externalcall.searchcrmentities",
externalCallAttachRecord: "telephony.externalcall.attachrecord",
// External Line Operations - Confirmed endpoints
externalLineGet: "telephony.externalline.get",
externalLineAdd: "telephony.externalline.add",
externalLineUpdate: "telephony.externalline.update",
externalLineDelete: "telephony.externalline.delete",
// Voximplant Operations - Confirmed endpoints
voximplantStatistics: "voximplant.statistic.get",
voximplantLineGet: "voximplant.line.get",
voximplantSipConnectorGet: "voximplant.sip.connector.status",
voximplantSipLineGet: "voximplant.sip.line.get",
voximplantSipLineAdd: "voximplant.sip.line.add",
voximplantSipLineUpdate: "voximplant.sip.line.update",
voximplantSipLineDelete: "voximplant.sip.line.delete",
};
}
/**
* Process Telephony operations
*/
async process() {
for (let i = 0; i < this.items.length; i++) {
try {
const operation = this.getNodeParameter("operation", i);
switch (operation) {
// External Call Operations
case "externalCallRegister":
await this.handleExternalCallRegister(i);
break;
case "externalCallFinish":
await this.handleExternalCallFinish(i);
break;
case "externalCallHide":
await this.handleExternalCallHide(i);
break;
case "externalCallShow":
await this.handleExternalCallShow(i);
break;
case "externalCallSearchCrm":
await this.handleExternalCallSearchCrm(i);
break;
case "externalCallAttachRecord":
await this.handleExternalCallAttachRecord(i);
break;
// External Line Operations
case "externalLineGet":
await this.handleExternalLineGet(i);
break;
case "externalLineAdd":
await this.handleExternalLineAdd(i);
break;
case "externalLineUpdate":
await this.handleExternalLineUpdate(i);
break;
case "externalLineDelete":
await this.handleExternalLineDelete(i);
break;
// Voximplant Operations
case "voximplantStatistics":
await this.handleVoximplantStatistics(i);
break;
case "voximplantLineGet":
await this.handleVoximplantLineGet(i);
break;
case "voximplantSipConnectorGet":
await this.handleVoximplantSipConnectorGet(i);
break;
case "voximplantSipLineGet":
await this.handleVoximplantSipLineGet(i);
break;
case "voximplantSipLineAdd":
await this.handleVoximplantSipLineAdd(i);
break;
case "voximplantSipLineUpdate":
await this.handleVoximplantSipLineUpdate(i);
break;
case "voximplantSipLineDelete":
await this.handleVoximplantSipLineDelete(i);
break;
default:
throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `Operation "${operation}" is not supported for Telephony`, { itemIndex: i });
}
}
catch (error) {
if (this.executeFunctions.continueOnFail()) {
this.returnData.push({ json: { error: error.message } });
continue;
}
throw error;
}
}
return this.returnData;
}
// External Call Operations
/**
* Handle 'externalCallRegister' operation
*/
async handleExternalCallRegister(itemIndex) {
const phoneNumber = this.getNodeParameter("phoneNumber", itemIndex);
const callType = this.getNodeParameter("callType", itemIndex);
const requestParams = {
PHONE_NUMBER: phoneNumber,
TYPE: callType,
};
// Optional parameters
try {
const userId = this.getNodeParameter("userId", itemIndex);
if (userId)
requestParams.USER_ID = userId;
}
catch (error) { }
try {
const lineNumber = this.getNodeParameter("lineNumber", itemIndex);
if (lineNumber)
requestParams.LINE_NUMBER = lineNumber;
}
catch (error) { }
const responseData = await this.makeApiCall(this.endpoints.externalCallRegister, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalCallFinish' operation
*/
async handleExternalCallFinish(itemIndex) {
const callId = this.getNodeParameter("callId", itemIndex);
const requestParams = {
CALL_ID: callId,
};
const responseData = await this.makeApiCall(this.endpoints.externalCallFinish, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalCallHide' operation
*/
async handleExternalCallHide(itemIndex) {
const callId = this.getNodeParameter("callId", itemIndex);
const requestParams = {
CALL_ID: callId,
};
const responseData = await this.makeApiCall(this.endpoints.externalCallHide, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalCallShow' operation
*/
async handleExternalCallShow(itemIndex) {
const callId = this.getNodeParameter("callId", itemIndex);
const requestParams = {
CALL_ID: callId,
};
const responseData = await this.makeApiCall(this.endpoints.externalCallShow, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalCallSearchCrm' operation
*/
async handleExternalCallSearchCrm(itemIndex) {
const phoneNumber = this.getNodeParameter("phoneNumber", itemIndex);
const requestParams = {
PHONE_NUMBER: phoneNumber,
};
const responseData = await this.makeApiCall(this.endpoints.externalCallSearchCrm, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalCallAttachRecord' operation
*/
async handleExternalCallAttachRecord(itemIndex) {
const callId = this.getNodeParameter("callId", itemIndex);
const recordUrl = this.getNodeParameter("recordUrl", itemIndex);
const requestParams = {
CALL_ID: callId,
RECORD_URL: recordUrl,
};
try {
const fileName = this.getNodeParameter("fileName", itemIndex);
if (fileName)
requestParams.FILENAME = fileName;
}
catch (error) { }
const responseData = await this.makeApiCall(this.endpoints.externalCallAttachRecord, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
// External Line Operations
/**
* Handle 'externalLineGet' operation
*/
async handleExternalLineGet(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
const responseData = await this.makeApiCall(this.endpoints.externalLineGet, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalLineAdd' operation
*/
async handleExternalLineAdd(itemIndex) {
const lineName = this.getNodeParameter("lineName", itemIndex);
const lineNumber = this.getNodeParameter("lineNumberAdd", itemIndex);
const requestParams = {
NAME: lineName,
NUMBER: lineNumber,
};
const responseData = await this.makeApiCall(this.endpoints.externalLineAdd, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalLineUpdate' operation
*/
async handleExternalLineUpdate(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const lineName = this.getNodeParameter("lineName", itemIndex);
const lineNumber = this.getNodeParameter("lineNumberAdd", itemIndex);
const requestParams = {
LINE_ID: lineId,
NAME: lineName,
NUMBER: lineNumber,
};
const responseData = await this.makeApiCall(this.endpoints.externalLineUpdate, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'externalLineDelete' operation
*/
async handleExternalLineDelete(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
const responseData = await this.makeApiCall(this.endpoints.externalLineDelete, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
// Voximplant Operations
/**
* Handle 'voximplantStatistics' operation
*/
async handleVoximplantStatistics(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
// Optional date filters
try {
const dateFrom = this.getNodeParameter("dateFrom", itemIndex);
if (dateFrom)
requestParams.DATE_FROM = dateFrom;
}
catch (error) { }
try {
const dateTo = this.getNodeParameter("dateTo", itemIndex);
if (dateTo)
requestParams.DATE_TO = dateTo;
}
catch (error) { }
// Handle additional options
try {
const options = this.getNodeParameter("options", itemIndex, {});
if (options.filter) {
const filter = this.parseJsonParameter(options.filter, "Filter is not valid JSON", itemIndex);
Object.assign(requestParams, filter);
}
if (options.sort) {
const sort = this.parseJsonParameter(options.sort, "Sort is not valid JSON", itemIndex);
requestParams.ORDER = sort;
}
if (options.limit) {
requestParams.LIMIT = options.limit;
}
if (options.start) {
requestParams.START = options.start;
}
}
catch (error) { }
const responseData = await this.makeApiCall(this.endpoints.voximplantStatistics, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantLineGet' operation
*/
async handleVoximplantLineGet(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
const responseData = await this.makeApiCall(this.endpoints.voximplantLineGet, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantSipConnectorGet' operation
*/
async handleVoximplantSipConnectorGet(itemIndex) {
const requestParams = {};
const responseData = await this.makeApiCall(this.endpoints.voximplantSipConnectorGet, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantSipLineGet' operation
*/
async handleVoximplantSipLineGet(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
const responseData = await this.makeApiCall(this.endpoints.voximplantSipLineGet, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantSipLineAdd' operation
*/
async handleVoximplantSipLineAdd(itemIndex) {
const lineName = this.getNodeParameter("lineName", itemIndex);
const lineNumber = this.getNodeParameter("lineNumberAdd", itemIndex);
const sipServer = this.getNodeParameter("sipServer", itemIndex);
const sipLogin = this.getNodeParameter("sipLogin", itemIndex);
const sipPassword = this.getNodeParameter("sipPassword", itemIndex);
const requestParams = {
NAME: lineName,
NUMBER: lineNumber,
SIP_SERVER: sipServer,
SIP_LOGIN: sipLogin,
SIP_PASSWORD: sipPassword,
};
const responseData = await this.makeApiCall(this.endpoints.voximplantSipLineAdd, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantSipLineUpdate' operation
*/
async handleVoximplantSipLineUpdate(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const lineName = this.getNodeParameter("lineName", itemIndex);
const lineNumber = this.getNodeParameter("lineNumberAdd", itemIndex);
const sipServer = this.getNodeParameter("sipServer", itemIndex);
const sipLogin = this.getNodeParameter("sipLogin", itemIndex);
const sipPassword = this.getNodeParameter("sipPassword", itemIndex);
const requestParams = {
LINE_ID: lineId,
NAME: lineName,
NUMBER: lineNumber,
SIP_SERVER: sipServer,
SIP_LOGIN: sipLogin,
SIP_PASSWORD: sipPassword,
};
const responseData = await this.makeApiCall(this.endpoints.voximplantSipLineUpdate, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
/**
* Handle 'voximplantSipLineDelete' operation
*/
async handleVoximplantSipLineDelete(itemIndex) {
const lineId = this.getNodeParameter("lineId", itemIndex);
const requestParams = {
LINE_ID: lineId,
};
const responseData = await this.makeApiCall(this.endpoints.voximplantSipLineDelete, requestParams, {}, itemIndex);
this.addResponseToReturnData(responseData, itemIndex);
}
}
exports.TelephonyResourceHandler = TelephonyResourceHandler;
//# sourceMappingURL=TelephonyResourceHandler.js.map