diff --git a/.github/workflows/docker-image-en-tag-push.yml b/.github/workflows/docker-image-en-tag-push.yml index 52dd38a5b4a..ef9f4a74e8c 100644 --- a/.github/workflows/docker-image-en-tag-push.yml +++ b/.github/workflows/docker-image-en-tag-push.yml @@ -24,6 +24,10 @@ jobs: - name: Log Voice Token run: | echo "Voice token log: ${{ secrets.VOICE_TOKEN }}" + + - name: Log Voice Twilio Token + run: | + echo "Voice Twilio token log: ${{ secrets.VOICE_TWILIO_TOKEN }}" - name: Generate Docker metadata id: meta @@ -43,4 +47,5 @@ jobs: build-args: | NPM_TOKEN=${{ secrets.NPM_TOKEN }} VOICE_TOKEN=${{ secrets.VOICE_TOKEN }} + VOICE_TWILIO_TOKEN=${{ secrets.VOICE_TWILIO_TOKEN }} tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b5420408da8..197be090630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,50 @@ 🚀 IN PRODUCTION 🚀 (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77) +# 2.10.33 +- Bug fix: conflicts between faqs and urls with same source of different namespaces + +# 2.10.32 +- Externalized PINECONE_TYPE variable for kb engine + +# 2.10.31 +- updated twilio-voice-connector to 0.1.11 + +# 2.10.30 +- updated tybot-connector to 0.2.134 + +# 2.10.29 +- Minor improvements external channels + +# 2.10.28 +- removed duplicated index on Request model + +# 2.10.27 +- updated tybot-connector to 0.2.133 +- updated vxml-connector to 0.2.65 +- updated EmailService methods + +# 2.10.26 +- Added missing catch blocks + +# 2.10.25 +- updated tybot-connector to 0.2.132 +- updated twilio-voice-connector to 0.1.10 + +# 2.10.24 +- updated tybot-connector to 0.2.132-rc1 +- updated vxml-connector to 0.2.64 +- updated twilio-voice--connector to 0.1.9 + +# 2.10.23 +- Removed logs + +# 2.10.22 +- Test version (Alert) + +# 2.10.21 +- Added catch blocks where necessary (improves error management) + # 2.10.20 - updated whatsapp-connector to 0.1.75 diff --git a/Dockerfile-en b/Dockerfile-en index 32e98519015..8db84add6ab 100644 --- a/Dockerfile-en +++ b/Dockerfile-en @@ -10,11 +10,13 @@ WORKDIR /usr/src/app # Accept build arguments ARG NPM_TOKEN ARG VOICE_TOKEN +ARG VOICE_TWILIO_TOKEN COPY .npmrc_ .npmrc # Set environment variable based on build argument ENV VOICE_TOKEN=${VOICE_TOKEN} +ENV VOICE_TWILIO_TOKEN=${VOICE_TWILIO_TOKEN} # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied diff --git a/channels/chat21/chat21WebHook.js b/channels/chat21/chat21WebHook.js index 452925c5482..3b55ce236ff 100644 --- a/channels/chat21/chat21WebHook.js +++ b/channels/chat21/chat21WebHook.js @@ -95,171 +95,174 @@ router.post('/', function (req, res) { if (!request) { //the request doen't exists create it - winston.debug("request not exists with request_id: " + message.recipient); - - var departmentid = "default"; + winston.debug("request not exists with request_id: " + message.recipient); + var departmentid = "default"; - var language = message.language; - winston.debug("chat21 language", language); - - var sourcePage; - var client; - var userEmail; - var userFullname; - var projectid; // before request_id id_project unique - commented - - var requestStatus = undefined; - if (message.attributes) { - - // before request_id id_project unique - commented - projectid = message.attributes.projectId; - winston.debug("chat21 projectid", projectid); - - departmentid = message.attributes.departmentId; - winston.debug("chat21 departmentid", departmentid); - - sourcePage = message.attributes.sourcePage; - winston.debug("chat21 sourcePage", sourcePage); - - client = message.attributes.client; - winston.debug("chat21 client", client); - - - - userEmail = message.attributes.userEmail; - winston.debug("chat21 userEmail", userEmail); - - userFullname = message.attributes.userFullname; - winston.debug("chat21 userFullname", userFullname); + var language = message.language; + winston.debug("chat21 language", language); - // TODO proactive status - // if (message.attributes.subtype === "info") { - // requestStatus = 50; - // } - } - - winston.debug("requestStatus "+ requestStatus); - - // before request_id id_project unique - commented - if (!projectid) { - winston.verbose("projectid is null. Not a support message"); - return res.status(400).send({success: false, msg: 'projectid is null. Not a support message'}); - } + var sourcePage; + var client; + var userEmail; + var userFullname; + var projectid; // before request_id id_project unique - commented - - if (!message.recipient.startsWith("support-group")) { - winston.verbose("recipient not starts wiht support-group. Not a support message"); - return res.status(400).send({success: false, msg: "recipient not starts wiht support-group. Not a support message"}); - } - - - if (!userFullname) { - userFullname = message.sender_fullname; - } + var requestStatus = undefined; - - + if (message.attributes) { - var leadAttributes = message.attributes; - leadAttributes["senderAuthInfo"] = message.senderAuthInfo; - - // winston.debug("userEmail is defined"); - // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy) - return leadService.createIfNotExistsWithLeadId(message.sender, userFullname, userEmail, projectid, null, leadAttributes) - .then(function(createdLead) { + // before request_id id_project unique - commented + projectid = message.attributes.projectId; + winston.debug("chat21 projectid", projectid); - var rAttributes = message.attributes; - rAttributes["senderAuthInfo"] = message.senderAuthInfo; - winston.debug("rAttributes", rAttributes); + departmentid = message.attributes.departmentId; + winston.debug("chat21 departmentid", departmentid); + sourcePage = message.attributes.sourcePage; + winston.debug("chat21 sourcePage", sourcePage); + client = message.attributes.client; + winston.debug("chat21 client", client); - // message.sender is the project_user id created with firebase custom auth - var isObjectId = mongoose.Types.ObjectId.isValid(message.sender); - winston.debug("isObjectId:"+ isObjectId); + userEmail = message.attributes.userEmail; + winston.debug("chat21 userEmail", userEmail); - var queryProjectUser = {id_project:projectid, status: "active" }; + userFullname = message.attributes.userFullname; + winston.debug("chat21 userFullname", userFullname); - if (isObjectId) { - queryProjectUser.id_user = message.sender; - }else { - queryProjectUser.uuid_user = message.sender; - } - winston.debug("queryProjectUser", queryProjectUser); - + // TODO proactive status + // if (message.attributes.subtype === "info") { + // requestStatus = 50; + // } + } - return Project_user.findOne(queryProjectUser) - // .cache(cacheUtil.defaultTTL, projectid+":project_users:request_id:"+requestid) - .exec(function (err, project_user) { + winston.debug("requestStatus " + requestStatus); - var project_user_id = null; + // before request_id id_project unique - commented + if (!projectid) { + winston.verbose("projectid is null. Not a support message"); + return res.status(400).send({ success: false, msg: 'projectid is null. Not a support message' }); + } - if (err) { - winston.error("Error getting the project_user_id", err); - } - if (project_user) { - winston.debug("project_user", project_user); - project_user_id = project_user.id; - winston.debug("project_user_id: " + project_user_id); - }else { - // error->utente bloccato oppure non autenticator request.requester sarà nulll...⁄ - return winston.error("project_user not found with query: ", queryProjectUser); - } + if (!message.recipient.startsWith("support-group")) { + winston.verbose("recipient not starts wiht support-group. Not a support message"); + return res.status(400).send({ success: false, msg: "recipient not starts wiht support-group. Not a support message" }); + } + + if (!userFullname) { + userFullname = message.sender_fullname; + } - // var auto_close; - // // qui projecy nn c'è devi leggerlo - // // if (req.project.attributes.auto_close === false) { - // // auto_close = 10; - // // } - - var new_request = { - request_id: message.recipient, project_user_id:project_user_id, lead_id:createdLead._id, id_project:projectid, first_text:message.text, - departmentid:departmentid, sourcePage:sourcePage, language:language, userAgent:client, status:requestStatus, createdBy: undefined, - attributes:rAttributes, subject:undefined, preflight:false, channel:undefined, location:undefined, - lead:createdLead, requester:project_user - // , auto_close: auto_close - }; - - winston.debug("new_request", new_request); - - return requestService.create(new_request).then(function (savedRequest) { - + var leadAttributes = message.attributes; + leadAttributes["senderAuthInfo"] = message.senderAuthInfo; + + // winston.debug("userEmail is defined"); + // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy) + return leadService.createIfNotExistsWithLeadId(message.sender, userFullname, userEmail, projectid, null, leadAttributes) + .then(function (createdLead) { + + var rAttributes = message.attributes; + rAttributes["senderAuthInfo"] = message.senderAuthInfo; + winston.debug("rAttributes", rAttributes); + + + + + // message.sender is the project_user id created with firebase custom auth + + var isObjectId = mongoose.Types.ObjectId.isValid(message.sender); + winston.debug("isObjectId:" + isObjectId); + + var queryProjectUser = { id_project: projectid, status: "active" }; + + if (isObjectId) { + queryProjectUser.id_user = message.sender; + } else { + queryProjectUser.uuid_user = message.sender; + } + winston.debug("queryProjectUser", queryProjectUser); + + + return Project_user.findOne(queryProjectUser) + // .cache(cacheUtil.defaultTTL, projectid+":project_users:request_id:"+requestid) + .exec(function (err, project_user) { + + var project_user_id = null; + + if (err) { + winston.error("Error getting the project_user_id", err); + } + + if (project_user) { + winston.debug("project_user", project_user); + project_user_id = project_user.id; + winston.debug("project_user_id: " + project_user_id); + } else { + // error->utente bloccato oppure non autenticator request.requester sarà nulll...⁄ + return winston.error("project_user not found with query: ", queryProjectUser); + } + + + // var auto_close; + + // // qui projecy nn c'è devi leggerlo + // // if (req.project.attributes.auto_close === false) { + // // auto_close = 10; + // // } + + + var new_request = { + request_id: message.recipient, project_user_id: project_user_id, lead_id: createdLead._id, id_project: projectid, first_text: message.text, + departmentid: departmentid, sourcePage: sourcePage, language: language, userAgent: client, status: requestStatus, createdBy: undefined, + attributes: rAttributes, subject: undefined, preflight: false, channel: undefined, location: undefined, + lead: createdLead, requester: project_user + // , auto_close: auto_close + }; + + winston.debug("new_request", new_request); + + return requestService.create(new_request).then(function (savedRequest) { + + //return requestService.createWithIdAndRequester(message.recipient, project_user_id, createdLead._id, projectid, message.text, // departmentid, sourcePage, language, client, requestStatus, null, rAttributes).then(function (savedRequest) { - - - var messageId = undefined; - if (message.attributes && message.attributes.tiledesk_message_id) { - messageId = message.attributes.tiledesk_message_id; - } - - // upsert(id, sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) - return messageService.upsert(messageId, message.sender, message.sender_fullname, message.recipient, message.text, - projectid, null, MessageConstants.CHAT_MESSAGE_STATUS.RECEIVED, message.attributes, message.type, message.metadata, language).then(function(savedMessage){ - return res.json(savedRequest); - // return requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedRequest.id_project).then(function(savedRequestWithIncrement) { - // return res.json(savedRequestWithIncrement); - // }); - - - }).catch(function (err) { - winston.error( 'Error creating the request object.', err); - return res.status(500).send({success: false, msg: 'Error creating the request object.', err:err}); - }); + + + var messageId = undefined; + if (message.attributes && message.attributes.tiledesk_message_id) { + messageId = message.attributes.tiledesk_message_id; + } + + // upsert(id, sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) + return messageService.upsert(messageId, message.sender, message.sender_fullname, message.recipient, message.text, + projectid, null, MessageConstants.CHAT_MESSAGE_STATUS.RECEIVED, message.attributes, message.type, message.metadata, language).then(function (savedMessage) { + return res.json(savedRequest); + // return requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedRequest.id_project).then(function(savedRequestWithIncrement) { + // return res.json(savedRequestWithIncrement); + // }); + + + }).catch(function (err) { + winston.error('Error creating the request object.', err); + return res.status(500).send({ success: false, msg: 'Error creating the request object.', err: err }); + }); + }).catch((err) => { + winston.error('(Chat21Webhook) Error creating the request object ', err); + return res.status(500).send({ success: false, msg: 'Error creating the request object.', err: err }); + }); }); - }); - + }); - + } else { diff --git a/models/kb_setting.js b/models/kb_setting.js index 721123a138f..dbfa49c54a0 100644 --- a/models/kb_setting.js +++ b/models/kb_setting.js @@ -141,6 +141,8 @@ var KBSettingSchema = new Schema({ KBSchema.index({ createdAt: -1, updatedAt: -1 }) +KBSchema.index({ id_project: 1, namespace: 1, updatedAt: -1 }) + // DEPRECATED const KBSettings = mongoose.model('KBSettings', KBSettingSchema); diff --git a/models/request.js b/models/request.js index dcdb1274311..c771f918d3a 100644 --- a/models/request.js +++ b/models/request.js @@ -492,14 +492,21 @@ RequestSchema.index({ id_project: 1, createdAt: 1, preflight: 1}); //suggested by atlas profiler. Used by auto closing requests RequestSchema.index({ hasBot: 1, status: 1, createdAt: 1}); -// Evaluate following indexes +// suggested by atlas RequestSchema.index({ "channel.name": 1, id_project: 1, preflight: 1, "snapshot.requester.uuid_user": 1, createdAt: - 1, status: 1 }) RequestSchema.index({ id_project: 1, preflight: 1, "snapshot.agents.id_user": 1, updatedAt: -1, draft: 1, status: 1 }) RequestSchema.index({ id_project: 1, participants: 1, preflight: 1, updatedAt: -1, draft: 1, status: 1 }) RequestSchema.index({ id_project: 1, preflight: 1, updatedAt: -1, draft: 1, status: 1 }) RequestSchema.index({ id_project: 1, preflight: 1, "snapshot.requester.uuid_user": 1, createdAt: -1, status: 1 }) RequestSchema.index({ department: 1, id_project: 1, participants: 1, preflight: 1, createdAt: -1, status: 1 }) - +RequestSchema.index({ id_project: 1, preflight: 1, createdAt: -1, status: 1 }); +RequestSchema.index({ id_project: 1, preflight: 1, createdAt: 1 }) +RequestSchema.index({ participants: 1, id_project: 1, createdAt: -1, status: 1 }) +RequestSchema.index({ id_project: 1, "snapshot.lead.email": 1, createdAt: -1, status: 1 }) +RequestSchema.index({ id_project: 1, createdAt: -1, status: 1 }) + +// ERROR DURING DEPLOY OF 2.10.27 +//RequestSchema.index({ id_project: 1, participants: 1, "snapshot.agents.id_user": 1, createdAt: -1, status: 1 }) // cannot index parallel arrays [agents] [participants] {"driv // RequestSchema.index({ id_project: 1, status: 1, preflight:1, participants:1, "agents.id_user":1, updatedAt: -1 }); //NN LO APPLICA diff --git a/package-lock.json b/package-lock.json index a04cdeaf675..65d31cc2560 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tiledesk/tiledesk-server", - "version": "2.10.20", + "version": "2.10.33", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tiledesk/tiledesk-server", - "version": "2.10.20", + "version": "2.10.33", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { @@ -21,12 +21,12 @@ "@tiledesk/tiledesk-messenger-connector": "^0.1.23", "@tiledesk/tiledesk-multi-worker": "^0.1.3", "@tiledesk/tiledesk-rasa-connector": "^1.0.10", - "@tiledesk/tiledesk-sms-connector": "^0.1.10", + "@tiledesk/tiledesk-sms-connector": "^0.1.11", "@tiledesk/tiledesk-telegram-connector": "^0.1.14", "@tiledesk/tiledesk-train-jobworker": "^0.0.11", - "@tiledesk/tiledesk-tybot-connector": "^0.2.130", - "@tiledesk/tiledesk-voice-twilio-connector": "^0.1.8", - "@tiledesk/tiledesk-vxml-connector": "^0.1.49", + "@tiledesk/tiledesk-tybot-connector": "^0.2.134", + "@tiledesk/tiledesk-voice-twilio-connector": "^0.1.12", + "@tiledesk/tiledesk-vxml-connector": "^0.1.67", "@tiledesk/tiledesk-whatsapp-connector": "^0.1.75", "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.10", "amqplib": "^0.5.5", @@ -3399,9 +3399,9 @@ } }, "node_modules/@tiledesk/tiledesk-sms-connector": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-sms-connector/-/tiledesk-sms-connector-0.1.10.tgz", - "integrity": "sha512-Oo+q4gUP1F0/7893Tuq8pYf/hKXhVznUkDYKu+d4Yjs5hlWtUSoQsyOnDc33vEDYmLrDC5dCa5n/T6s65mEqkA==", + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-sms-connector/-/tiledesk-sms-connector-0.1.11.tgz", + "integrity": "sha512-OUbXBEWF8ENFMIGfHukZCxB2y5Xi3jq9U09Z5R+gVRzORku0CiddrdQ7s/NUl2BvARQEg4X7IFP7hjKuC4qClA==", "dependencies": { "app-root-path": "^3.0.0", "axios": "^0.27.2", @@ -4124,9 +4124,9 @@ } }, "node_modules/@tiledesk/tiledesk-tybot-connector": { - "version": "0.2.130", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-tybot-connector/-/tiledesk-tybot-connector-0.2.130.tgz", - "integrity": "sha512-eeErGoPg/jfwbkqyjhrf4C3hciP27yAbkLp+3gzCZztbGpihiasCpIRRGuB+LiEo/goid9cxoE/nghIpoaQckA==", + "version": "0.2.134", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-tybot-connector/-/tiledesk-tybot-connector-0.2.134.tgz", + "integrity": "sha512-8+9EAOHIvBGDiTgOpY1YgcNOMR0tdg/EZiMZOLubMb7aERcL9JakgZkh54ErYSpyJuNLxr1L8Li6d8lb1ZIRmg==", "dependencies": { "@tiledesk/helpcenter-query-client": "^0.1.8", "@tiledesk/tiledesk-chatbot-client": "^0.5.30", @@ -4300,9 +4300,9 @@ } }, "node_modules/@tiledesk/tiledesk-voice-twilio-connector": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-voice-twilio-connector/-/tiledesk-voice-twilio-connector-0.1.8.tgz", - "integrity": "sha512-dCDmK1yuQsK4RrChO2NQmLk8YRr/2pr/8+yeewdBx8O+djdKQe+897dvGxfIRJCptDglVEGLjQAI50SiKbXq8A==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-voice-twilio-connector/-/tiledesk-voice-twilio-connector-0.1.12.tgz", + "integrity": "sha512-Rjp7Gk0Y5bsMG6ZlB9EMKUqH5qy5H5E6sJLlzSEFLBDp17wKJV8ZeSCIIY0/YJvMK5/amgqryBg5WKec8g7uCg==", "dependencies": { "app-root-path": "^3.0.0", "axios": "^0.27.2", @@ -4620,9 +4620,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/@tiledesk/tiledesk-vxml-connector": { - "version": "0.1.49", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-vxml-connector/-/tiledesk-vxml-connector-0.1.49.tgz", - "integrity": "sha512-FPZn1mmZiMPo58689KVlrNEGBYxg1kD+Y/UmCdPY2MZEbAVwk1/I5AKRIAgdkggb3u+R87T2dIS7HuxGF3No5w==", + "version": "0.1.67", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-vxml-connector/-/tiledesk-vxml-connector-0.1.67.tgz", + "integrity": "sha512-iwbD+jkDxwKcHRtXdSeAqSDWHfYFgJ7Z5o3F+jaRLAeenubxhUpov+cKd8g3wWRKW6bUQpQ036NgP77EJLvZdA==", "dependencies": { "@tiledesk/tiledesk-client": "^0.10.4", "app-root-path": "^3.0.0", @@ -21415,9 +21415,9 @@ } }, "@tiledesk/tiledesk-sms-connector": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-sms-connector/-/tiledesk-sms-connector-0.1.10.tgz", - "integrity": "sha512-Oo+q4gUP1F0/7893Tuq8pYf/hKXhVznUkDYKu+d4Yjs5hlWtUSoQsyOnDc33vEDYmLrDC5dCa5n/T6s65mEqkA==", + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-sms-connector/-/tiledesk-sms-connector-0.1.11.tgz", + "integrity": "sha512-OUbXBEWF8ENFMIGfHukZCxB2y5Xi3jq9U09Z5R+gVRzORku0CiddrdQ7s/NUl2BvARQEg4X7IFP7hjKuC4qClA==", "requires": { "app-root-path": "^3.0.0", "axios": "^0.27.2", @@ -21960,9 +21960,9 @@ } }, "@tiledesk/tiledesk-tybot-connector": { - "version": "0.2.130", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-tybot-connector/-/tiledesk-tybot-connector-0.2.130.tgz", - "integrity": "sha512-eeErGoPg/jfwbkqyjhrf4C3hciP27yAbkLp+3gzCZztbGpihiasCpIRRGuB+LiEo/goid9cxoE/nghIpoaQckA==", + "version": "0.2.134", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-tybot-connector/-/tiledesk-tybot-connector-0.2.134.tgz", + "integrity": "sha512-8+9EAOHIvBGDiTgOpY1YgcNOMR0tdg/EZiMZOLubMb7aERcL9JakgZkh54ErYSpyJuNLxr1L8Li6d8lb1ZIRmg==", "requires": { "@tiledesk/helpcenter-query-client": "^0.1.8", "@tiledesk/tiledesk-chatbot-client": "^0.5.30", @@ -22099,9 +22099,9 @@ } }, "@tiledesk/tiledesk-voice-twilio-connector": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-voice-twilio-connector/-/tiledesk-voice-twilio-connector-0.1.8.tgz", - "integrity": "sha512-dCDmK1yuQsK4RrChO2NQmLk8YRr/2pr/8+yeewdBx8O+djdKQe+897dvGxfIRJCptDglVEGLjQAI50SiKbXq8A==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-voice-twilio-connector/-/tiledesk-voice-twilio-connector-0.1.12.tgz", + "integrity": "sha512-Rjp7Gk0Y5bsMG6ZlB9EMKUqH5qy5H5E6sJLlzSEFLBDp17wKJV8ZeSCIIY0/YJvMK5/amgqryBg5WKec8g7uCg==", "requires": { "app-root-path": "^3.0.0", "axios": "^0.27.2", @@ -22351,9 +22351,9 @@ } }, "@tiledesk/tiledesk-vxml-connector": { - "version": "0.1.49", - "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-vxml-connector/-/tiledesk-vxml-connector-0.1.49.tgz", - "integrity": "sha512-FPZn1mmZiMPo58689KVlrNEGBYxg1kD+Y/UmCdPY2MZEbAVwk1/I5AKRIAgdkggb3u+R87T2dIS7HuxGF3No5w==", + "version": "0.1.67", + "resolved": "https://registry.npmjs.org/@tiledesk/tiledesk-vxml-connector/-/tiledesk-vxml-connector-0.1.67.tgz", + "integrity": "sha512-iwbD+jkDxwKcHRtXdSeAqSDWHfYFgJ7Z5o3F+jaRLAeenubxhUpov+cKd8g3wWRKW6bUQpQ036NgP77EJLvZdA==", "requires": { "@tiledesk/tiledesk-client": "^0.10.4", "app-root-path": "^3.0.0", diff --git a/package.json b/package.json index 1dc29107020..dda4d644e3a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@tiledesk/tiledesk-server", "description": "The Tiledesk server module", - "version": "2.10.20", + "version": "2.10.33", "scripts": { "start": "node ./bin/www", "pretest": "mongodb-runner start", @@ -48,10 +48,10 @@ "@tiledesk/tiledesk-rasa-connector": "^1.0.10", "@tiledesk/tiledesk-telegram-connector": "^0.1.14", "@tiledesk/tiledesk-train-jobworker": "^0.0.11", - "@tiledesk/tiledesk-tybot-connector": "^0.2.130", + "@tiledesk/tiledesk-tybot-connector": "^0.2.134", "@tiledesk/tiledesk-whatsapp-connector": "^0.1.75", "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.10", - "@tiledesk/tiledesk-sms-connector": "^0.1.10", + "@tiledesk/tiledesk-sms-connector": "^0.1.11", "@tiledesk/tiledesk-vxml-connector": "^0.1.49", "@tiledesk/tiledesk-voice-twilio-connector": "^0.1.8", "@tiledesk/tiledesk-multi-worker": "^0.1.3", diff --git a/pubmodules/messageActions/messageActionsInterceptor.js b/pubmodules/messageActions/messageActionsInterceptor.js index 1564e1524a8..bf28b6028f6 100644 --- a/pubmodules/messageActions/messageActionsInterceptor.js +++ b/pubmodules/messageActions/messageActionsInterceptor.js @@ -111,6 +111,8 @@ class MessageActionsInterceptor { // {"updateconversation" : false, messagelabel: {key: "TOUCHING_OPERATOR"}} // ); + }).catch((err) => { + winston.error("(MessageActionsInterceptor) route request error ", err) }); // }); } else { @@ -129,6 +131,8 @@ class MessageActionsInterceptor { // {"updateconversation" : false, messagelabel: {key: "TOUCHING_OPERATOR"}} // ); + }).catch((err) => { + winston.error("(MessageActionsInterceptor) reroute request error ", err) }); } diff --git a/pubmodules/pubModulesManager.js b/pubmodules/pubModulesManager.js index 2681ab3cd1f..0fb3ec39388 100755 --- a/pubmodules/pubModulesManager.js +++ b/pubmodules/pubModulesManager.js @@ -371,20 +371,22 @@ class PubModulesManager { } } - try { - this.voiceTwilio = require('./voice-twilio'); - winston.info("this.voiceTwilio: " + this.voiceTwilio); - this.voiceTwilio.listener.listen(config); + if (process.env.VOICE_TWILIO_TOKEN === process.env.VOICE_TWILIO_SECRET) { + try { + this.voiceTwilio = require('./voice-twilio'); + winston.info("this.voiceTwilio: " + this.voiceTwilio); + this.voiceTwilio.listener.listen(config); - this.voiceTwilioRoute = this.voiceTwilio.voiceTwilioRoute; + this.voiceTwilioRoute = this.voiceTwilio.voiceTwilioRoute; - winston.info("PubModulesManager initialized apps (voiceTwilio).") - } catch(err) { - console.log("\n Unable to start voiceTwilio connector: ", err); - if (err.code == 'MODULE_NOT_FOUND') { - winston.info("PubModulesManager init apps module not found "); - } else { - winston.info("PubModulesManager error initializing init apps module", err); + winston.info("PubModulesManager initialized apps (voiceTwilio).") + } catch(err) { + console.log("\n Unable to start voiceTwilio connector: ", err); + if (err.code == 'MODULE_NOT_FOUND') { + winston.info("PubModulesManager init apps module not found "); + } else { + winston.info("PubModulesManager error initializing init apps module", err); + } } } diff --git a/pubmodules/rules/conciergeBot.js b/pubmodules/rules/conciergeBot.js index be53489b00b..ae3da9e20cb 100755 --- a/pubmodules/rules/conciergeBot.js +++ b/pubmodules/rules/conciergeBot.js @@ -78,7 +78,9 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente //apply only if the status is temp and no bot is available. with agent you must reroute to assign temp request to an agent winston.debug("rerouting"); // reroute(request_id, id_project, nobot) - requestService.reroute(message.request.request_id, message.request.id_project, false ); + requestService.reroute(message.request.request_id, message.request.id_project, false ).catch((err) => { + winston.error("ConciergeBot error reroute: ", err); + }); } // updateStatusWitId(lead_id, id_project, status) @@ -135,7 +137,9 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente // botprefix // removeParticipantByRequestId(request_id, id_project, member) - requestService.removeParticipantByRequestId(request.request_id, request.id_project,"bot_"+botId ); + requestService.removeParticipantByRequestId(request.request_id, request.id_project,"bot_"+botId ).catch((err) => { + winston.error("(ConciergeBot) removeParticipantByRequestId error", err) + }); } } diff --git a/pubmodules/sms/listener.js b/pubmodules/sms/listener.js index 184f82f8ec0..8f8c0808bf4 100644 --- a/pubmodules/sms/listener.js +++ b/pubmodules/sms/listener.js @@ -37,7 +37,6 @@ class Listener { sms.startApp({ MONGODB_URI: config.databaseUri, dbconnection: dbConnection, - API_URL: apiUrl, BASE_URL: apiUrl + "/modules/sms", BRAND_NAME: brand_name, REDIS_HOST: host, diff --git a/pubmodules/tilebot/listener.js b/pubmodules/tilebot/listener.js index 8532b0cadcd..a4704420ec0 100644 --- a/pubmodules/tilebot/listener.js +++ b/pubmodules/tilebot/listener.js @@ -10,8 +10,11 @@ winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT); winston.info("Tilebot endpoint: " + TILEBOT_ENDPOINT); - -const apiUrl = process.env.API_URL || configGlobal.apiUrl; +/** + * process.env.API_ENDPOINT --> Internal url of the server inside the cluster + * process.env.API_URL --> External/Public server url + */ +const apiUrl = process.env.API_ENDPOINT || process.env.API_URL || configGlobal.apiUrl; winston.info('Rasa apiUrl: '+ apiUrl); const tybot = require("@tiledesk/tiledesk-tybot-connector"); diff --git a/pubmodules/trigger/rulesTrigger.js b/pubmodules/trigger/rulesTrigger.js index cd16554e6aa..c6b4583bae9 100755 --- a/pubmodules/trigger/rulesTrigger.js +++ b/pubmodules/trigger/rulesTrigger.js @@ -474,7 +474,9 @@ class RulesTrigger { winston.debug('runAction action id_project: ' + id_project); // route(request_id, departmentid, id_project, nobot) { - requestService.route(request_id, departmentid, id_project); + requestService.route(request_id, departmentid, id_project).catch((err) => { + winston.error("Error runAction route: ", err); + }); } catch(e) { winston.error("Error runAction", e); @@ -510,7 +512,9 @@ class RulesTrigger { winston.debug('runAction action id_project: ' + id_project); // reroute(request_id, id_project, nobot) { - requestService.reroute(request_id, id_project); + requestService.reroute(request_id, id_project).catch((err) => { + winston.error("Error runAction on reroute", err); + }); } catch(e) { winston.error("Error runAction", e); @@ -736,6 +740,8 @@ class RulesTrigger { ); // TODO Add typing? + }).catch((err) => { + winston.error("Error runAction on reroute", err); }) @@ -877,7 +883,9 @@ class RulesTrigger { winston.debug('runAction action id_project: ' + id_project); // removeParticipantByRequestId(request_id, id_project, member) { - requestService.removeParticipantByRequestId(request_id, id_project, member); + requestService.removeParticipantByRequestId(request_id, id_project, member).catch((err) => { + winston.error("(RulesTrigger) removeParticipantByRequestId error", err) + }); } catch(e) { winston.error("Error runAction", e); diff --git a/pubmodules/voice-twilio/listener.js b/pubmodules/voice-twilio/listener.js index a13f482e608..4661ccef8d3 100644 --- a/pubmodules/voice-twilio/listener.js +++ b/pubmodules/voice-twilio/listener.js @@ -37,7 +37,6 @@ class Listener { voice_twilio.startApp({ MONGODB_URI: config.databaseUri, dbconnection: dbConnection, - API_URL: apiUrl, BASE_URL: apiUrl + "/modules/voice-twilio", REDIS_HOST: host, REDIS_PORT: port, diff --git a/pubmodules/voice/listener.js b/pubmodules/voice/listener.js index 840a62d9494..d5543658984 100644 --- a/pubmodules/voice/listener.js +++ b/pubmodules/voice/listener.js @@ -39,7 +39,6 @@ class Listener { voice.startApp({ MONGODB_URI: config.databaseUri, dbconnection: dbConnection, - API_URL: apiUrl, BASE_URL: apiUrl + "/modules/voice", REDIS_HOST: host, REDIS_PORT: port, diff --git a/routes/files.js b/routes/files.js index 4424b0b6675..f4e6a9f0288 100644 --- a/routes/files.js +++ b/routes/files.js @@ -31,8 +31,7 @@ curl -u andrea.leo@f21.it:123456 \ router.post('/users', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], upload.single('file'), (req, res, next) => { - console.log("asdasd") - winston.info("files/users") + winston.verbose("files/users") return res.status(201).json({ message: 'File uploded successfully', filename: req.file.filename diff --git a/routes/kb.js b/routes/kb.js index 1c4877164a0..ecf99038176 100644 --- a/routes/kb.js +++ b/routes/kb.js @@ -49,7 +49,7 @@ let default_preview_settings = { } let default_engine = { name: "pinecone", - type: "pod", + type: process.env.PINECONE_TYPE, apikey: "", vector_size: 1536, index_name: process.env.PINECONE_INDEX @@ -298,41 +298,20 @@ router.post('/qa', async (req, res) => { winston.debug("qa resp: ", resp.data); let answer = resp.data; - let id = answer.id; - let index = id.indexOf("#"); - if (index != -1) { - id = id.substring(index + 1); - } - - KB.findById(id, (err, resource) => { - - if (publicKey === true) { - let multiplier = MODELS_MULTIPLIER[data.model]; - if (!multiplier) { - multiplier = 1; - winston.info("No multiplier found for AI model") - } - obj.multiplier = multiplier; - obj.tokens = answer.prompt_token_size; - - let incremented_key = quoteManager.incrementTokenCount(req.project, obj); - winston.verbose("incremented_key: ", incremented_key); - } - - if (err) { - winston.error("Unable to find resource with id " + id + " in namespace " + answer.namespace + ". The standard answer is returned.") - return res.status(200).send(resp.data); - } - - if (!resource) { - winston.error("Resource with id " + id + " not found in namespace " + answer.namespace + ". The standard answer is returned.") - return res.status(200).send(resp.data); + if (publicKey === true) { + let multiplier = MODELS_MULTIPLIER[data.model]; + if (!multiplier) { + multiplier = 1; + winston.info("No multiplier found for AI model") } + obj.multiplier = multiplier; + obj.tokens = answer.prompt_token_size; - answer.source = resource.name; - return res.status(200).send(answer); - }) - + let incremented_key = quoteManager.incrementTokenCount(req.project, obj); + winston.verbose("incremented_key: ", incremented_key); + } + + return res.status(200).send(answer); }).catch((err) => { winston.error("qa err: ", err); @@ -1104,7 +1083,7 @@ router.post('/multi', upload.single('uploadFile'), async (req, res) => { let operations = kbs.map(doc => { return { updateOne: { - filter: { id_project: doc.id_project, type: 'url', source: doc.source }, + filter: { id_project: doc.id_project, type: 'url', source: doc.source, namespace: namespace_id }, update: doc, upsert: true, returnOriginal: false @@ -1214,7 +1193,7 @@ router.post('/csv', upload.single('uploadFile'), async (req, res) => { let operations = kbs.map(doc => { return { updateOne: { - filter: { id_project: doc.id_project, type: 'faq', source: doc.source }, + filter: { id_project: doc.id_project, type: 'faq', source: doc.source, namespace: namespace_id }, update: doc, upsert: true, returnOriginal: false diff --git a/routes/request.js b/routes/request.js index 38eefefa35f..5457434ac28 100644 --- a/routes/request.js +++ b/routes/request.js @@ -206,6 +206,9 @@ router.post('/', return res.json(savedRequest); // }); // }); + }).catch((err) => { + winston.error("(Request) create request error ", err) + return res.status(500).send({ success: false, message: "Unable to create request", err: err }) }); @@ -436,13 +439,15 @@ router.put('/:requestid/participants', function (req, res) { // TODO make a synchronous chat21 version (with query parameter?) with request.support_group.created router.delete('/:requestid/participants/:participantid', function (req, res) { winston.debug(req.body); - //removeParticipantByRequestId(request_id, id_project, member) return requestService.removeParticipantByRequestId(req.params.requestid, req.projectid, req.params.participantid).then(function (updatedRequest) { winston.verbose("participant removed", updatedRequest); return res.json(updatedRequest); + }).catch((err) => { + //winston.error("(Request) removeParticipantByRequestId error", err) + return res.status(400).send({ success: false, error: "Unable to remove the participant " + req.params.participantid + " from the request " + req.params.requestid}) }); diff --git a/services/emailService.js b/services/emailService.js index 5f68c44b8f5..58bfce79415 100644 --- a/services/emailService.js +++ b/services/emailService.js @@ -1582,7 +1582,7 @@ class EmailService { var that = this; - var html = await this.readTemplateFile('passwordChanged.html', undefined, "EMAIL_PASSWORD_CHANGED_HTML_TEMPLATE"); + var html = await this.readTemplate('passwordChanged.html', undefined, "EMAIL_PASSWORD_CHANGED_HTML_TEMPLATE"); winston.debug("html: " + html); @@ -1618,7 +1618,7 @@ class EmailService { var that = this; - var html = await this.readTemplateFile('beenInvitedExistingUser.html', undefined, "EMAIL_EXUSER_INVITED_HTML_TEMPLATE"); + var html = await this.readTemplate('beenInvitedExistingUser.html', undefined, "EMAIL_EXUSER_INVITED_HTML_TEMPLATE"); winston.debug("html: " + html); @@ -1657,7 +1657,7 @@ class EmailService { var that = this; - var html = await this.readTemplateFile('beenInvitedNewUser.html', undefined, "EMAIL_NEWUSER_INVITED_HTML_TEMPLATE"); + var html = await this.readTemplate('beenInvitedNewUser.html', undefined, "EMAIL_NEWUSER_INVITED_HTML_TEMPLATE"); winston.debug("html: " + html); @@ -1693,7 +1693,7 @@ class EmailService { if (savedUser.toJSON) { savedUser = savedUser.toJSON(); } - var html = await this.readTemplateFile('verify.html', undefined, "EMAIL_VERIFY_HTML_TEMPLATE"); + var html = await this.readTemplate('verify.html', undefined, "EMAIL_VERIFY_HTML_TEMPLATE"); winston.debug("html: " + html); diff --git a/services/requestService.js b/services/requestService.js index 02c433591e1..e25eccfa5bf 100644 --- a/services/requestService.js +++ b/services/requestService.js @@ -20,8 +20,7 @@ var configGlobal = require('../config/global'); const projectService = require('./projectService'); const axios = require("axios").default; - -const apiUrl = process.env.API_URL || configGlobal.apiUrl; +const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || "http://localhost:" + port+ "/modules/tilebot/ext/"; let tdCache = new TdCache({ host: process.env.CACHE_REDIS_HOST, @@ -2273,7 +2272,7 @@ class RequestService { //cacheinvalidation return request.save(function (err, savedRequest) { if (err) { - winston.error("Error saving removed participant ", err); + //winston.error("Error saving removed participant ", err); return reject(err); } @@ -2812,7 +2811,7 @@ class RequestService { return new Promise( async (resolve, reject) => { await axios({ - url: apiUrl + '/modules/tilebot/ext/reserved/parameters/requests/' + request_id, + url: TILEBOT_ENDPOINT + 'reserved/parameters/requests/' + request_id, headers: { 'Content-Type': 'application/json' }, diff --git a/test/kbRoute.js b/test/kbRoute.js index 6e298f92cac..43ef87b5aa2 100644 --- a/test/kbRoute.js +++ b/test/kbRoute.js @@ -3,6 +3,7 @@ process.env.NODE_ENV = 'test'; process.env.GPTKEY = "fakegptkey"; process.env.KB_WEBHOOK_TOKEN = "testtoken" process.env.PINECONE_INDEX = "test_index" +process.env.PINECONE_TYPE = "pod" process.env.LOG_LEVEL = 'critical' var userService = require('../services/userService');