@tuanltntu/n8n-nodes-bitrix24
Version:
Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more
717 lines • 32.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenLinesResourceHandler = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const ResourceHandlerBase_1 = require("./ResourceHandlerBase");
/**
* Handler for Bitrix24 Open Channels (OpenLines) operations
*/
class OpenLinesResourceHandler extends ResourceHandlerBase_1.ResourceHandlerBase {
constructor(executeFunctions, returnData, options = {}) {
super(executeFunctions, returnData, options);
this.resourceEndpoints = {
// Config Operations
configAdd: "imopenlines.config.add",
configDelete: "imopenlines.config.delete",
configGet: "imopenlines.config.get",
configList: "imopenlines.config.list.get",
configPath: "imopenlines.config.path.get",
configUpdate: "imopenlines.config.update",
networkJoin: "imopenlines.network.join",
revisionGet: "imopenlines.revision.get",
// Bot Session Operations
botSessionFinish: "imopenlines.bot.session.finish",
botSessionMessageSend: "imopenlines.bot.session.message.send",
botSessionOperator: "imopenlines.bot.session.operator",
botSessionTransfer: "imopenlines.bot.session.transfer",
// CRM Chat Operations
crmChatGetLastId: "imopenlines.crm.chat.getLastId",
crmChatGet: "imopenlines.crm.chat.get",
crmChatUserAdd: "imopenlines.crm.chat.user.add",
crmChatUserDelete: "imopenlines.crm.chat.user.delete",
// CRM Message Operations
crmMessageAdd: "imopenlines.crm.message.add",
messageQuickSave: "imopenlines.message.quick.save",
// Operator Operations
operatorAnotherFinish: "imopenlines.operator.another.finish",
operatorAnswer: "imopenlines.operator.answer",
operatorFinish: "imopenlines.operator.finish",
operatorSkip: "imopenlines.operator.skip",
operatorSpam: "imopenlines.operator.spam",
operatorTransfer: "imopenlines.operator.transfer",
// Dialog Operations
crmLeadCreate: "imopenlines.crm.lead.create",
dialogGet: "imopenlines.dialog.get",
messageSessionStart: "imopenlines.message.session.start",
sessionHeadVote: "imopenlines.session.head.vote",
sessionHistoryGet: "imopenlines.session.history.get",
sessionIntercept: "imopenlines.session.intercept",
sessionJoin: "imopenlines.session.join",
sessionModePinAll: "imopenlines.session.mode.pinAll",
sessionModePin: "imopenlines.session.mode.pin",
sessionModeSilent: "imopenlines.session.mode.silent",
sessionModeUnpinAll: "imopenlines.session.mode.unpinAll",
sessionOpen: "imopenlines.session.open",
sessionStart: "imopenlines.session.start",
// Connector Operations
connectorRegister: "imconnector.register",
connectorActivate: "imconnector.activate",
connectorDeactivate: "imconnector.deactivate",
connectorStatus: "imconnector.status",
connectorDataSet: "imconnector.connector.data.set",
connectorList: "imconnector.list",
connectorUnregister: "imconnector.unregister",
// Connector Messages
connectorSendMessages: "imconnector.send.messages",
connectorUpdateMessages: "imconnector.update.messages",
connectorDeleteMessages: "imconnector.delete.messages",
connectorSendStatusDelivery: "imconnector.send.status.delivery",
connectorSendStatusReading: "imconnector.send.status.reading",
connectorChatNameSet: "imconnector.chat.name.set",
};
}
/**
* Process Open Channels operations
*/
async process() {
for (let i = 0; i < this.items.length; i++) {
try {
const operation = this.getNodeParameter("operation", i);
if (!this.resourceEndpoints[operation]) {
throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `The operation "${operation}" is not supported for Open Channels`, { itemIndex: i });
}
const endpoint = this.resourceEndpoints[operation];
let responseData;
// Config Operations
if (operation === "configAdd") {
responseData = await this.handleConfigAdd(endpoint, i);
}
else if (operation === "configDelete") {
responseData = await this.handleConfigDelete(endpoint, i);
}
else if (operation === "configGet") {
responseData = await this.handleConfigGet(endpoint, i);
}
else if (operation === "configList") {
responseData = await this.handleConfigList(endpoint, i);
}
else if (operation === "configPath") {
responseData = await this.handleConfigPath(endpoint, i);
}
else if (operation === "configUpdate") {
responseData = await this.handleConfigUpdate(endpoint, i);
}
else if (operation === "networkJoin") {
responseData = await this.handleNetworkJoin(endpoint, i);
}
else if (operation === "revisionGet") {
responseData = await this.handleRevisionGet(endpoint, i);
}
// Bot Session Operations
else if (operation === "botSessionFinish") {
responseData = await this.handleBotSessionFinish(endpoint, i);
}
else if (operation === "botSessionMessageSend") {
responseData = await this.handleBotSessionMessageSend(endpoint, i);
}
else if (operation === "botSessionOperator") {
responseData = await this.handleBotSessionOperator(endpoint, i);
}
else if (operation === "botSessionTransfer") {
responseData = await this.handleBotSessionTransfer(endpoint, i);
}
// CRM Chat Operations
else if (operation === "crmChatGetLastId") {
responseData = await this.handleCrmChatGetLastId(endpoint, i);
}
else if (operation === "crmChatGet") {
responseData = await this.handleCrmChatGet(endpoint, i);
}
else if (operation === "crmChatUserAdd") {
responseData = await this.handleCrmChatUserAdd(endpoint, i);
}
else if (operation === "crmChatUserDelete") {
responseData = await this.handleCrmChatUserDelete(endpoint, i);
}
// CRM Message Operations
else if (operation === "crmMessageAdd") {
responseData = await this.handleCrmMessageAdd(endpoint, i);
}
else if (operation === "messageQuickSave") {
responseData = await this.handleMessageQuickSave(endpoint, i);
}
// Operator Operations
else if (operation === "operatorAnotherFinish") {
responseData = await this.handleOperatorAnotherFinish(endpoint, i);
}
else if (operation === "operatorAnswer") {
responseData = await this.handleOperatorAnswer(endpoint, i);
}
else if (operation === "operatorFinish") {
responseData = await this.handleOperatorFinish(endpoint, i);
}
else if (operation === "operatorSkip") {
responseData = await this.handleOperatorSkip(endpoint, i);
}
else if (operation === "operatorSpam") {
responseData = await this.handleOperatorSpam(endpoint, i);
}
else if (operation === "operatorTransfer") {
responseData = await this.handleOperatorTransfer(endpoint, i);
}
// Dialog Operations
else if (operation === "crmLeadCreate") {
responseData = await this.handleCrmLeadCreate(endpoint, i);
}
else if (operation === "dialogGet") {
responseData = await this.handleDialogGet(endpoint, i);
}
else if (operation === "messageSessionStart") {
responseData = await this.handleMessageSessionStart(endpoint, i);
}
else if (operation === "sessionHeadVote") {
responseData = await this.handleSessionHeadVote(endpoint, i);
}
else if (operation === "sessionHistoryGet") {
responseData = await this.handleSessionHistoryGet(endpoint, i);
}
else if (operation === "sessionIntercept") {
responseData = await this.handleSessionIntercept(endpoint, i);
}
else if (operation === "sessionJoin") {
responseData = await this.handleSessionJoin(endpoint, i);
}
else if (operation === "sessionModePinAll") {
responseData = await this.handleSessionModePinAll(endpoint, i);
}
else if (operation === "sessionModePin") {
responseData = await this.handleSessionModePin(endpoint, i);
}
else if (operation === "sessionModeSilent") {
responseData = await this.handleSessionModeSilent(endpoint, i);
}
else if (operation === "sessionModeUnpinAll") {
responseData = await this.handleSessionModeUnpinAll(endpoint, i);
}
else if (operation === "sessionOpen") {
responseData = await this.handleSessionOpen(endpoint, i);
}
else if (operation === "sessionStart") {
responseData = await this.handleSessionStart(endpoint, i);
}
// Connector Operations
else if (operation === "connectorRegister") {
responseData = await this.handleConnectorRegister(endpoint, i);
}
else if (operation === "connectorActivate") {
responseData = await this.handleConnectorActivate(endpoint, i);
}
else if (operation === "connectorDeactivate") {
responseData = await this.handleConnectorDeactivate(endpoint, i);
}
else if (operation === "connectorStatus") {
responseData = await this.handleConnectorStatus(endpoint, i);
}
else if (operation === "connectorDataSet") {
responseData = await this.handleConnectorDataSet(endpoint, i);
}
else if (operation === "connectorList") {
responseData = await this.handleConnectorList(endpoint, i);
}
else if (operation === "connectorUnregister") {
responseData = await this.handleConnectorUnregister(endpoint, i);
}
// Connector Messages
else if (operation === "connectorSendMessages") {
responseData = await this.handleConnectorSendMessages(endpoint, i);
}
else if (operation === "connectorUpdateMessages") {
responseData = await this.handleConnectorUpdateMessages(endpoint, i);
}
else if (operation === "connectorDeleteMessages") {
responseData = await this.handleConnectorDeleteMessages(endpoint, i);
}
else if (operation === "connectorSendStatusDelivery") {
responseData = await this.handleConnectorSendStatusDelivery(endpoint, i);
}
else if (operation === "connectorSendStatusReading") {
responseData = await this.handleConnectorSendStatusReading(endpoint, i);
}
else if (operation === "connectorChatNameSet") {
responseData = await this.handleConnectorChatNameSet(endpoint, i);
}
else {
throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `The operation "${operation}" is not implemented`, { itemIndex: i });
}
this.addResponseToReturnData(responseData, i);
}
catch (error) {
if (this.continueOnFail()) {
this.addErrorToReturnData(error, i);
}
else {
throw error;
}
}
}
return this.returnData;
}
// ============= HELPER METHODS =============
/**
* Process sendBody parameter and return body object
*/
getSendBodyParameters(itemIndex) {
const specifyBody = this.getNodeParameter("specifyBody", itemIndex, "fields");
if (specifyBody === "json") {
const bodyJson = this.getNodeParameter("bodyJson", itemIndex, "{}");
try {
return typeof bodyJson === "string" ? JSON.parse(bodyJson) : bodyJson;
}
catch (error) {
throw new Error(`Invalid JSON in Body: ${error.message}`);
}
}
// Using fields below
const bodyParameters = this.getNodeParameter("bodyParameters", itemIndex, {});
const body = {};
if (bodyParameters.parameter && Array.isArray(bodyParameters.parameter)) {
for (const param of bodyParameters.parameter) {
if (param.name) {
body[param.name] = param.value || "";
}
}
}
return body;
}
// ============= CONFIG OPERATIONS =============
async handleConfigAdd(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConfigDelete(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConfigGet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConfigList(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConfigPath(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConfigUpdate(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleNetworkJoin(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleRevisionGet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= BOT SESSION OPERATIONS =============
async handleBotSessionFinish(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleBotSessionMessageSend(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleBotSessionOperator(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleBotSessionTransfer(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= CRM CHAT OPERATIONS =============
async handleCrmChatGetLastId(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleCrmChatGet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleCrmChatUserAdd(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleCrmChatUserDelete(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= CRM MESSAGE OPERATIONS =============
async handleCrmMessageAdd(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleMessageQuickSave(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= OPERATOR OPERATIONS =============
async handleOperatorAnotherFinish(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleOperatorAnswer(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleOperatorFinish(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleOperatorSkip(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleOperatorSpam(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleOperatorTransfer(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= DIALOG OPERATIONS =============
async handleCrmLeadCreate(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleDialogGet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleMessageSessionStart(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionHeadVote(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionHistoryGet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionIntercept(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionJoin(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionModePinAll(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionModePin(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionModeSilent(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionModeUnpinAll(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionOpen(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleSessionStart(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
// ============= CONNECTOR OPERATIONS =============
/**
* Register connector - with proper fields from documentation
*/
async handleConnectorRegister(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorRegisterId", itemIndex);
const connectorName = this.getNodeParameter("connectorRegisterName", itemIndex);
const iconData = this.getNodeParameter("connectorRegisterIcon", itemIndex);
const placementHandler = this.getNodeParameter("connectorRegisterHandler", itemIndex);
const iconDisabled = this.getNodeParameter("connectorRegisterIconDisabled", itemIndex, "");
// Parse ICON JSON
let iconObject;
try {
iconObject =
typeof iconData === "string" ? JSON.parse(iconData) : iconData;
}
catch (error) {
throw new Error(`Invalid JSON in Icon Data: ${error.message}`);
}
const body = {
ID: connectorId,
NAME: connectorName,
ICON: iconObject,
PLACEMENT_HANDLER: placementHandler,
};
// Parse ICON_DISABLED if provided
if (iconDisabled) {
try {
body.ICON_DISABLED =
typeof iconDisabled === "string"
? JSON.parse(iconDisabled)
: iconDisabled;
}
catch (error) {
throw new Error(`Invalid JSON in Icon Disabled: ${error.message}`);
}
}
// Optional toggle fields (convert boolean to Y/N)
const delExternal = this.getNodeParameter("DEL_EXTERNAL_MESSAGES", itemIndex, false);
const editInternal = this.getNodeParameter("EDIT_INTERNAL_MESSAGES", itemIndex, false);
const delInternal = this.getNodeParameter("DEL_INTERNAL_MESSAGES", itemIndex, false);
const newsletter = this.getNodeParameter("NEWSLETTER", itemIndex, false);
const systemMessages = this.getNodeParameter("NEED_SYSTEM_MESSAGES", itemIndex, false);
const signature = this.getNodeParameter("NEED_SIGNATURE", itemIndex, false);
const chatGroup = this.getNodeParameter("CHAT_GROUP", itemIndex, false);
const comment = this.getNodeParameter("COMMENT", itemIndex, "");
body.DEL_EXTERNAL_MESSAGES = delExternal ? "Y" : "N";
body.EDIT_INTERNAL_MESSAGES = editInternal ? "Y" : "N";
body.DEL_INTERNAL_MESSAGES = delInternal ? "Y" : "N";
body.NEWSLETTER = newsletter ? "Y" : "N";
body.NEED_SYSTEM_MESSAGES = systemMessages ? "Y" : "N";
body.NEED_SIGNATURE = signature ? "Y" : "N";
body.CHAT_GROUP = chatGroup ? "Y" : "N";
if (comment) {
body.COMMENT = comment;
}
return this.makeApiCall(endpoint, body);
}
/**
* Activate connector - properly uses CONNECTOR, LINE, ACTIVE
*/
async handleConnectorActivate(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
const active = this.getNodeParameter("active", itemIndex);
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
ACTIVE: active,
});
}
/**
* Deactivate connector - uses Send Body
*/
async handleConnectorDeactivate(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
/**
* Get connector status - uses Send Body
*/
async handleConnectorStatus(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
/**
* Set connector data - uses Send Body for DATA parameter
*/
async handleConnectorDataSet(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
async handleConnectorList(endpoint, itemIndex) {
const bodyParams = this.getSendBodyParameters(itemIndex);
return this.makeApiCall(endpoint, bodyParams);
}
/**
* Unregister connector - only needs ID
*/
async handleConnectorUnregister(endpoint, itemIndex) {
const unregisterConnectorId = this.getNodeParameter("unregisterConnectorId", itemIndex);
return this.makeApiCall(endpoint, {
ID: unregisterConnectorId,
});
}
// ============= CONNECTOR MESSAGES =============
/**
* Send messages - builds MESSAGES array from UI fields
*/
async handleConnectorSendMessages(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
// Build user object
const userId = this.getNodeParameter("messageUserId", itemIndex);
const userDetails = this.getNodeParameter("messageUserDetails", itemIndex, {});
const user = {
id: userId,
...userDetails,
};
// Handle skip_phone_validate boolean -> 'Y'
if (user.skip_phone_validate === true) {
user.skip_phone_validate = "Y";
}
else {
delete user.skip_phone_validate;
}
// Handle picture URL
if (user.picture_url) {
user.picture = {
url: user.picture_url,
};
delete user.picture_url;
}
// Build message object
const messageId = this.getNodeParameter("messageId", itemIndex);
const messageText = this.getNodeParameter("messageText", itemIndex, "");
const messageDate = this.getNodeParameter("messageDate", itemIndex);
const messageOptions = this.getNodeParameter("messageOptions", itemIndex, {});
const message = {
id: messageId,
date: messageDate,
};
if (messageText) {
message.text = messageText;
}
// Handle disable_crm boolean -> 'Y'
if (messageOptions.disable_crm === true) {
message.disable_crm = "Y";
}
// Handle files
if (messageOptions.files) {
try {
message.files =
typeof messageOptions.files === "string"
? JSON.parse(messageOptions.files)
: messageOptions.files;
}
catch (error) {
throw new Error(`Invalid JSON in Files: ${error.message}`);
}
}
// Build chat object
const chatId = this.getNodeParameter("messageChatId", itemIndex);
const chatDetails = this.getNodeParameter("messageChatDetails", itemIndex, {});
const chat = {
id: chatId,
...chatDetails,
};
// Build MESSAGES array
const messagesArray = [
{
user,
message,
chat,
},
];
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
MESSAGES: messagesArray,
});
}
/**
* Update messages - same as send messages
*/
async handleConnectorUpdateMessages(endpoint, itemIndex) {
// Reuse the same logic as send messages
return this.handleConnectorSendMessages(endpoint, itemIndex);
}
/**
* Delete messages - simplified structure (only IDs needed)
*/
async handleConnectorDeleteMessages(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
// Build simplified message structure for delete
const userId = this.getNodeParameter("deleteMessageUserId", itemIndex);
const messageId = this.getNodeParameter("deleteMessageId", itemIndex);
const chatId = this.getNodeParameter("messageChatId", itemIndex);
const messagesArray = [
{
user: {
id: userId,
},
message: {
id: messageId,
},
chat: {
id: chatId,
},
},
];
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
MESSAGES: messagesArray,
});
}
/**
* Send delivery status - uses JSON body (no docs provided)
*/
async handleConnectorSendStatusDelivery(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
const messages = this.getNodeParameter("messages", itemIndex);
let messagesArray;
try {
messagesArray =
typeof messages === "string" ? JSON.parse(messages) : messages;
}
catch (error) {
throw new Error(`Invalid JSON in Messages: ${error.message}`);
}
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
MESSAGES: messagesArray,
});
}
/**
* Send reading status - uses JSON body (no docs provided)
*/
async handleConnectorSendStatusReading(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
const messages = this.getNodeParameter("messages", itemIndex);
let messagesArray;
try {
messagesArray =
typeof messages === "string" ? JSON.parse(messages) : messages;
}
catch (error) {
throw new Error(`Invalid JSON in Messages: ${error.message}`);
}
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
MESSAGES: messagesArray,
});
}
/**
* Set chat name - uses JSON body (no docs provided)
*/
async handleConnectorChatNameSet(endpoint, itemIndex) {
const connectorId = this.getNodeParameter("connectorId", itemIndex);
const lineId = this.getNodeParameter("lineId", itemIndex);
const chatId = this.getNodeParameter("chatId", itemIndex);
const chatName = this.getNodeParameter("chatName", itemIndex);
return this.makeApiCall(endpoint, {
CONNECTOR: connectorId,
LINE: lineId,
CHAT_ID: chatId,
NAME: chatName,
});
}
}
exports.OpenLinesResourceHandler = OpenLinesResourceHandler;
//# sourceMappingURL=OpenLinesResourceHandler.js.map