Skip to content

Commit

Permalink
Merge branch 'master' into features-nov24/add-tags-endpoint-prod1
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
  • Loading branch information
Giovanni Troisi committed Dec 9, 2024
2 parents 444b043 + 990096e commit c56e010
Show file tree
Hide file tree
Showing 22 changed files with 305 additions and 241 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/docker-image-en-tag-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-en
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
277 changes: 140 additions & 137 deletions channels/chat21/chat21WebHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit c56e010

Please sign in to comment.