Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
try {
await Rooms.resetLastMessageById(rid, null);
} catch (e) {
this._logger.warn(`Failed to update last message of room ${rid}`);
this._logger.warn({ msg: 'Failed to update last message of room', roomId: rid });
this._logger.error(e);
}
}
Expand All @@ -55,7 +55,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {

const creator = await this._cache.findImportedUser(data.u._id);
if (!creator) {
this._logger.warn(`Imported user not found: ${data.u._id}`);
this._logger.warn({ msg: 'Imported user not found', userId: data.u._id });
throw new Error('importer-message-unknown-user');
}
const rid = await this._cache.findImportedRoomId(data.rid);
Expand All @@ -71,7 +71,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
try {
await insertMessage(creator, msgObj as unknown as IDBMessage, rid, true);
} catch (e) {
this._logger.warn(`Failed to import message with timestamp ${String(msgObj.ts)} to room ${rid}`);
this._logger.warn({ msg: 'Failed to import message', timestamp: msgObj.ts, roomId: rid });
this._logger.error(e);
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
const { name, _id } = (await this.getMentionedChannelData(importId)) || {};

if (!_id || !name) {
this._logger.warn(`Mentioned room not found: ${importId}`);
this._logger.warn({ msg: 'Mentioned room not found', importId });
continue;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
const data = await this._cache.findImportedUser(importId);

if (!data) {
this._logger.warn(`Mentioned user not found: ${importId}`);
this._logger.warn({ msg: 'Mentioned user not found', importId });
continue;
}

Expand Down
60 changes: 34 additions & 26 deletions apps/meteor/app/integrations/server/lib/triggerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RocketChatIntegrationHandler {
}

addIntegration(record: IOutgoingIntegration): void {
outgoingLogger.debug(`Adding the integration ${record.name} of the event ${record.event}!`);
outgoingLogger.debug({ msg: 'Adding integration', integrationName: record.name, event: record.event });
let channels = [];
if (record.event && !outgoingEvents[record.event].use.channel) {
outgoingLogger.debug('The integration doesnt rely on channels.');
Expand All @@ -79,7 +79,7 @@ class RocketChatIntegrationHandler {
outgoingLogger.debug('The integration had an empty channel property, so it is going on all the public channels.');
channels = ['all_public_channels'];
} else {
outgoingLogger.debug('The integration is going on these channels:', record.channel);
outgoingLogger.debug({ msg: 'The integration is going on these channels', channels: record.channel });
channels = ([] as string[]).concat(record.channel);
}

Expand Down Expand Up @@ -140,7 +140,7 @@ class RocketChatIntegrationHandler {
}

if (!user) {
outgoingLogger.error(`The user "${trigger.username}" doesn't exist, so we can't send the message.`);
outgoingLogger.error({ msg: 'Integration user not found', username: trigger.username });
return;
}

Expand All @@ -164,7 +164,7 @@ class RocketChatIntegrationHandler {
return;
}

outgoingLogger.debug(`Found a room for ${trigger.name} which is: ${tmpRoom.name} with a type of ${tmpRoom.t}`);
outgoingLogger.debug({ msg: 'Found room for integration', integrationName: trigger.name, roomName: tmpRoom.name, roomType: tmpRoom.t });

message.bot = { i: trigger._id };

Expand Down Expand Up @@ -233,13 +233,14 @@ class RocketChatIntegrationHandler {
}
break;
default:
outgoingLogger.warn(`An Unhandled Trigger Event was called: ${argObject.event}`);
outgoingLogger.warn({ msg: 'Unhandled trigger event', event: argObject.event });
argObject.event = undefined;
break;
}

outgoingLogger.debug({
msg: `Got the event arguments for the event: ${argObject.event}`,
msg: 'Got the event arguments for the event',
event: argObject.event,
messageId: argObject.message?._id,
roomId: argObject.room?._id,
userId: argObject.user?._id || argObject.owner?._id,
Expand All @@ -264,7 +265,7 @@ class RocketChatIntegrationHandler {
const ownerWithoutServicesField = owner?.services ? omitServicesField(owner) : owner;

if (!room || !message) {
outgoingLogger.warn(`The integration ${event} was called but the room or message was not defined.`);
outgoingLogger.warn({ msg: 'Integration called without room or message', event });
return;
}

Expand Down Expand Up @@ -317,7 +318,7 @@ class RocketChatIntegrationHandler {
break;
case 'roomCreated':
if (!owner) {
outgoingLogger.warn(`The integration ${event} was called but the owner was not defined.`);
outgoingLogger.warn({ msg: 'Integration called without owner data', event });
return;
}
data.channel_id = room._id;
Expand All @@ -332,7 +333,7 @@ class RocketChatIntegrationHandler {
case 'roomJoined':
case 'roomLeft':
if (!user) {
outgoingLogger.warn(`The integration ${event} was called but the owner was not defined.`);
outgoingLogger.warn({ msg: 'Integration called without owner data', event });
return;
}
data.timestamp = new Date();
Expand All @@ -349,7 +350,7 @@ class RocketChatIntegrationHandler {
break;
case 'userCreated':
if (!user) {
outgoingLogger.warn(`The integration ${event} was called but the owner was not defined.`);
outgoingLogger.warn({ msg: 'Integration called without owner data', event });
return;
}
data.timestamp = user.createdAt;
Expand Down Expand Up @@ -450,7 +451,7 @@ class RocketChatIntegrationHandler {
return;
}

outgoingLogger.debug(`Starting search for triggers for the room: ${room ? room._id : '__any'}`);
outgoingLogger.debug({ msg: 'Starting search for triggers for room', roomId: room ? room._id : '__any' });

const triggersToExecute = this.getTriggersToExecute(room, message);

Expand All @@ -461,12 +462,15 @@ class RocketChatIntegrationHandler {
}
}

outgoingLogger.debug(`Found ${triggersToExecute.length} to iterate over and see if the match the event.`);
outgoingLogger.debug({ msg: 'Found triggers to iterate over', triggerCount: triggersToExecute.length, event });

for await (const triggerToExecute of triggersToExecute) {
outgoingLogger.debug(
`Is "${triggerToExecute.name}" enabled, ${triggerToExecute.enabled}, and what is the event? ${triggerToExecute.event}`,
);
outgoingLogger.debug({
msg: 'Checking trigger execution eligibility',
triggerName: triggerToExecute.name,
isEnabled: triggerToExecute.enabled,
triggerEvent: triggerToExecute.event,
});
if (triggerToExecute.enabled === true && triggerToExecute.event === event) {
await this.executeTrigger(triggerToExecute, argObject);
}
Expand Down Expand Up @@ -495,11 +499,11 @@ class RocketChatIntegrationHandler {

async executeTriggerUrl(url: string, trigger: IOutgoingIntegration, { event, message, room, owner, user }: ArgumentsObject, tries = 0) {
if (!this.isTriggerEnabled(trigger)) {
outgoingLogger.warn(`The trigger "${trigger.name}" is no longer enabled, stopping execution of it at try: ${tries}`);
outgoingLogger.warn({ msg: 'Trigger is not enabled', triggerName: trigger.name, tries });
return;
}

outgoingLogger.debug(`Starting to execute trigger: ${trigger.name} (${trigger._id})`);
outgoingLogger.debug({ msg: 'Starting to execute trigger', triggerName: trigger.name, triggerId: trigger._id });

let word;
// Not all triggers/events support triggerWords
Expand All @@ -517,14 +521,14 @@ class RocketChatIntegrationHandler {

// Stop if there are triggerWords but none match
if (!word) {
outgoingLogger.debug(`The trigger word which "${trigger.name}" was expecting could not be found, not executing.`);
outgoingLogger.debug({ msg: 'Trigger word not found', triggerName: trigger.name });
return;
}
}
}

if (message && message.editedAt && !trigger.runOnEdits) {
outgoingLogger.debug(`The trigger "${trigger.name}"'s run on edits is disabled and the message was edited.`);
outgoingLogger.debug({ msg: 'Trigger run on edits disabled and message was edited', triggerName: trigger.name });
return;
}

Expand All @@ -547,7 +551,7 @@ class RocketChatIntegrationHandler {
this.mapEventArgsToData(data, { event, message, room, owner, user });
await updateHistory({ historyId, step: 'mapped-args-to-data', data, triggerWord: word });

outgoingLogger.info(`Will be executing the Integration "${trigger.name}" to the url: ${url}`);
outgoingLogger.info({ msg: 'Will be executing integration', integrationName: trigger.name, url });
outgoingLogger.debug({ data });

const scriptEngine = this.getEngine(trigger);
Expand Down Expand Up @@ -620,9 +624,9 @@ class RocketChatIntegrationHandler {
.then(async (res) => {
const content = await res.text();
if (!content) {
outgoingLogger.warn(`Result for the Integration ${trigger.name} to ${url} is empty`);
outgoingLogger.warn({ msg: 'Integration result is empty', integrationName: trigger.name, url });
} else {
outgoingLogger.info(`Status code for the Integration ${trigger.name} to ${url} is ${res.status}`);
outgoingLogger.info({ msg: 'Integration HTTP status', integrationName: trigger.name, url, status: res.status });
}

const data = (() => {
Expand Down Expand Up @@ -686,13 +690,15 @@ class RocketChatIntegrationHandler {
if (!content || !this.successResults.includes(res.status)) {
if (content) {
outgoingLogger.error({
msg: `Error for the Integration "${trigger.name}" to ${url}`,
msg: 'Error for integration request',
integrationName: trigger.name,
url,
result: content,
});

if (res.status === 410) {
await updateHistory({ historyId, step: 'after-process-http-status-410', error: true });
outgoingLogger.error(`Disabling the Integration "${trigger.name}" because the status code was 401 (Gone).`);
outgoingLogger.error({ msg: 'Disabling integration due to 410 (Gone) status', integrationName: trigger.name });
await Integrations.updateOne({ _id: trigger._id }, { $set: { enabled: false } });
void notifyOnIntegrationChangedById(trigger._id);
return;
Expand All @@ -701,7 +707,9 @@ class RocketChatIntegrationHandler {
if (res.status === 500) {
await updateHistory({ historyId, step: 'after-process-http-status-500', error: true });
outgoingLogger.error({
msg: `Error "500" for the Integration "${trigger.name}" to ${url}.`,
msg: 'Error 500 for integration request',
integrationName: trigger.name,
url,
content,
});
return;
Expand Down Expand Up @@ -738,7 +746,7 @@ class RocketChatIntegrationHandler {
return;
}

outgoingLogger.info(`Trying the Integration ${trigger.name} to ${url} again in ${waitTime} milliseconds.`);
outgoingLogger.info({ msg: 'Retrying integration', integrationName: trigger.name, url, waitTime });
setTimeout(() => {
void this.executeTriggerUrl(url, trigger, { event, message, room, owner, user }, tries + 1);
}, waitTime);
Expand Down
18 changes: 9 additions & 9 deletions apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class QueueManager {
await Promise.all([afterInquiryQueued(inquiry), afterRoomQueued(room)]);

if (defaultAgent) {
logger.debug(`Setting default agent for inquiry ${inquiry._id} to ${defaultAgent.username}`);
logger.debug({ msg: 'Setting default agent for inquiry', inquiryId: inquiry._id, agentUsername: defaultAgent.username });
await LivechatInquiry.setDefaultAgentById(inquiry._id, defaultAgent);
}

Expand Down Expand Up @@ -225,7 +225,7 @@ export class QueueManager {
});

if (!newRoom) {
logger.error(`Room with id ${room._id} not found after inquiry verification.`);
logger.error({ msg: 'Room not found after inquiry verification', roomId: room._id });
throw new Error('room-not-found');
}

Expand Down Expand Up @@ -259,7 +259,7 @@ export class QueueManager {
try {
session.startTransaction();
const room = await createLivechatRoom(insertionRoom, session);
logger.debug(`Room for visitor ${guest._id} created with id ${room._id}`);
logger.debug({ msg: 'Room created for visitor', visitorId: guest._id, roomId: room._id });
const inquiry = await createLivechatInquiry({
rid,
name: room.fname,
Expand Down Expand Up @@ -301,7 +301,7 @@ export class QueueManager {
agent?: SelectedAgent;
extraData?: IOmnichannelRoomExtraData;
}) {
logger.debug(`Requesting a room for guest ${guest._id}`);
logger.debug({ msg: 'Requesting room for guest', guestId: guest._id });
check(
guest,
Match.ObjectIncluding({
Expand Down Expand Up @@ -386,7 +386,7 @@ export class QueueManager {
const newRoom = await LivechatRooms.findOneById(rid);

if (!newRoom) {
logger.error(`Room with id ${rid} not found`);
logger.error({ msg: 'Room not found', roomId: rid });
throw new Error('room-not-found');
}

Expand Down Expand Up @@ -427,11 +427,11 @@ export class QueueManager {
return archivedRoom;
}

logger.debug(`Attempting to unarchive room with id ${rid}`);
logger.debug({ msg: 'Attempting to unarchive room', roomId: rid });

const oldInquiry = await LivechatInquiry.findOneByRoomId<Pick<ILivechatInquiryRecord, '_id'>>(rid, { projection: { _id: 1 } });
if (oldInquiry) {
logger.debug(`Removing old inquiry (${oldInquiry._id}) for room ${rid}`);
logger.debug({ msg: 'Removing old inquiry before unarchiving room', inquiryId: oldInquiry._id, roomId: rid });
await LivechatInquiry.removeByRoomId(rid);
void notifyOnLivechatInquiryChangedById(oldInquiry._id, 'removed');
}
Expand Down Expand Up @@ -467,7 +467,7 @@ export class QueueManager {
}

await this.requeueInquiry(inquiry, room, defaultAgent);
logger.debug(`Inquiry ${inquiry._id} queued`);
logger.debug({ msg: 'Inquiry queued', inquiryId: inquiry._id });

return room;
}
Expand All @@ -477,7 +477,7 @@ export class QueueManager {
return;
}

logger.debug(`Notifying agents of new inquiry ${inquiry._id} queued`);
logger.debug({ msg: 'Notifying agents of queued inquiry', inquiryId: inquiry._id });

const { department, rid, v } = inquiry;
// Alert only the online agents of the queued request
Expand Down
Loading
Loading