Skip to content

Commit

Permalink
[FIX] changed response for livechat transcript call (#1130)
Browse files Browse the repository at this point in the history
* changed response for livechat transcript call

* fixed lint issue

* changed transcript format to txt

* changed response for livechat transcript call

* fixed lint issue

* changed transcript format to txt

* improve transcript format

* finor fixes

Co-authored-by: Shailesh Baldaniya <shaileshbaldaniya351@gmail.com>
  • Loading branch information
AlexanderKanakis and Shailesh351 authored Apr 28, 2022
1 parent 95e0210 commit 426e4d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
5 changes: 3 additions & 2 deletions app/livechat/server/api/v1/transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ API.v1.addRoute('livechat/transcript', {
});

const { token, rid, email } = this.bodyParams;
if (!Livechat.sendTranscript({ token, rid, email })) {
const transcript = Promise.await(Livechat.sendTranscript({ token, rid, email }));
if (!transcript) {
return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_transcript') });
}

return API.v1.success({ message: TAPi18n.__('Livechat_transcript_sent') });
return API.v1.success({ message: TAPi18n.__('Livechat_transcript_sent'), transcript });
} catch (e) {
return API.v1.failure(e);
}
Expand Down
27 changes: 6 additions & 21 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ export const Livechat = {
});
},

sendTranscript({ token, rid, email, subject, user }) {
async sendTranscript({ token, rid, email, user }) {
check(rid, String);
check(email, String);
Livechat.logger.debug(`Sending conversation transcript of room ${rid} to user with token ${token}`);
Expand Down Expand Up @@ -1219,7 +1219,7 @@ export const Livechat = {
sort: { ts: 1 },
});

let html = '<div> <hr>';
let text = '';
messages.forEach((message) => {
let author;
if (message.u._id === visitor._id) {
Expand All @@ -1229,26 +1229,11 @@ export const Livechat = {
}

const datetime = moment.tz(message.ts, timezone).locale(userLanguage).format('LLL');
const singleMessage = `
<p><strong>${author}</strong> <em>${datetime}</em></p>
<p>${message.msg}</p>
`;
html += singleMessage;
const singleMessage = `(${datetime}) ${author}:\n${message.msg}\n---\n\n`;
text += singleMessage;
});

html = `${html}</div>`;

let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);

if (fromEmail) {
fromEmail = fromEmail[0];
} else {
fromEmail = settings.get('From_Email');
}

const mailSubject = subject || TAPi18n.__('Transcript_of_your_livechat_conversation', { lng: userLanguage });

this.sendEmail(fromEmail, email, fromEmail, mailSubject, html);
text = `${text}`;

Meteor.defer(() => {
callbacks.run('livechat.sendTranscript', messages, email);
Expand All @@ -1263,7 +1248,7 @@ export const Livechat = {
Messages.createTranscriptHistoryWithRoomIdMessageAndUser(room._id, '', user, {
requestData: { type, visitor, user },
});
return true;
return text;
},

getRoomMessages({ rid }) {
Expand Down

0 comments on commit 426e4d0

Please sign in to comment.