RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.45k stars 10.53k forks source link

livechat-close method doesn't trigger Rocket.Chat Apps event #33717

Open cuonghuunguyen opened 1 week ago

cuonghuunguyen commented 1 week ago

Description:

The livechat-close message doesn't trigger the message sent methods of Rocket.Chat Apps Engine.

Steps to reproduce:

  1. Close a room with reason

Expected behavior:

The message trigger postMessageSent event and preMessageSent event

Actual behavior:

nothing was triggered

Server Setup Information:

Client Setup Information

Additional context

Caused by this PR https://github.com/RocketChat/Rocket.Chat/pull/32896

Relevant logs:

KevLehman commented 6 days ago

Hello! Actually, it was "broken" by another PR, where this change was introduced:

await Message.saveSystemMessageAndNotifyUser('livechat-close', newRoom._id, params.comment ?? '',    
    chatCloser, {
        groupable: false,
        transcriptRequested,
        ...(isRoomClosedByVisitorParams(params) && { token: params.visitor.token }),
    }
);

Previously, we used the sendMessage function to save these types of messages, but that was wrong. System messages should not produce any app events (cause they're system messages). When the code was updated to use saveSystemMessage, this behavior (sending app events for system messages) was removed as a side effect.

So, you shouldn't expect any app notifications for system messages. To check if a livechat room is closed, pls use the IPostLivechatRoomClosed event.

Tell us a bit more about your use case, and maybe we can improve Apps Engine so you can retrieve those system messages at will 👀