Skip to content

Comments

[FIX] Update visitor info on email reception based on current inbox settings#23280

Merged
KevLehman merged 3 commits intodevelopfrom
fix/email-inboxes
Sep 28, 2021
Merged

[FIX] Update visitor info on email reception based on current inbox settings#23280
KevLehman merged 3 commits intodevelopfrom
fix/email-inboxes

Conversation

@KevLehman
Copy link
Member

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

@KevLehman KevLehman requested a review from murtaza98 September 23, 2021 21:22
@murtaza98 murtaza98 self-requested a review September 27, 2021 07:03
@KevLehman KevLehman merged commit c5a13a7 into develop Sep 28, 2021
@KevLehman KevLehman deleted the fix/email-inboxes branch September 28, 2021 16:54
@KevLehman KevLehman added this to the 4.0.0 milestone Sep 28, 2021
Copy link
Member

@sampaiodiego sampaiodiego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it is already merged some changes would be good to do.


for await (const emailInboxRecord of emailInboxesCursor) {
console.log('Setting up email interceptor for', emailInboxRecord.email);
logger.info('Setting up email interceptor for', emailInboxRecord.email);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this usage will be deprecated (we need to add a warning for that)

please log either an object or use placeholders: https://github.com/pinojs/pino/blob/master/docs/api.md#message-string

} catch (e) {
} catch (e: any) {
// In case the email message history has been received by other instance..
logger.error(e.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have an error object, you can log it entirely

logger.error(e);

if for some reason TS complains about it, you can add the error object to the err key

logger.error({ err: e });

});
}).catch((error) => {
Livechat.logger.log('Error receiving Email: %s', error.message);
console.log(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid using console.log

}).catch((error) => {
Livechat.logger.log('Error receiving Email: %s', error.message);
console.log(error);
Livechat.logger.error('Error receiving Email: %s', error.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with logging the error object. if you need to add a message to the log, you can add the msg key:

Livechat.logger.error({
  msg: 'Error receiving Email',
  err: error,
});

if (guest) {
logger.debug(`Guest with email ${ email } found with id ${ guest._id }`);
if (guest.department !== department) {
logger.debug(`Switching departments for guest ${ guest._id }. Previous: ${ guest.department } New: ${ department }`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for debugging purposes might be useful to add extra data, for this it is useful logging big objects with an additional message, like:

logger.debug({
  msg: 'Switching departments for guest',
  guest,
  new: department,
});

let room = LivechatRooms.findOneByVisitorTokenAndEmailThread(guest.token, thread, {});
logger.debug(`Guest ${ guest._id } obtained. Attempting to find or create a room on department ${ department }`);
let room = LivechatRooms.findOneByVisitorTokenAndEmailThreadAndDepartment(guest.token, thread, department, {});
logger.debug(`Room ${ room?._id } found for guest ${ guest._id }`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with debugging info:

logger.debug({
  msg: 'Room found for guest',
  room,
  guest,
});

@KevLehman
Copy link
Member Author

Hey @sampaiodiego , i wasn't aware of those new conventions for logs, would be good to create a "log documentation" page somewhere to describe conventions and best practices, wdyt? 👀

@sampaiodiego
Copy link
Member

Hey @sampaiodiego , i wasn't aware of those new conventions for logs, would be good to create a "log documentation" page somewhere to describe conventions and best practices, wdyt? 👀

definitely a good idea.. I'll try to draft something 👍

@sampaiodiego sampaiodiego modified the milestones: 4.0.0, 3.18.2 Oct 1, 2021
sampaiodiego pushed a commit that referenced this pull request Oct 1, 2021
Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com>
@sampaiodiego sampaiodiego mentioned this pull request Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants