Skip to content

Commit 8b66ed5

Browse files
thassiovd-gubert
andauthored
[NEW][APPS] Get livechat's room transcript via bridge method (#22985)
* Get livechat room messages via livechart bridge * Fix indentation * Add livechat room only filter * Fix indentation * Fix wrong import path to IMessage interface * Adjustments based on linter hints * Make message conversion a parallel operation * Update Apps-Engine version * Adjustments based on review comments * Simplify retrieval of livechat room data * Fix indentation Co-authored-by: Douglas Gubert <[email protected]>
1 parent 0ac3f33 commit 8b66ed5

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

app/apps/server/bridges/livechat.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IDepartment,
99
} from '@rocket.chat/apps-engine/definition/livechat';
1010
import { IUser } from '@rocket.chat/apps-engine/definition/users';
11+
import { IMessage } from '@rocket.chat/apps-engine/definition/messages';
1112

1213
import { getRoom } from '../../../livechat/server/api/lib/livechat';
1314
import { Livechat } from '../../../livechat/server/lib/Livechat';
@@ -222,6 +223,19 @@ export class AppLivechatBridge extends LivechatBridge {
222223
return LivechatDepartment.findEnabledWithAgents().map(boundConverter);
223224
}
224225

226+
protected async _fetchLivechatRoomMessages(appId: string, roomId: string): Promise<Array<IMessage>> {
227+
this.orch.debugLog(`The App ${ appId } is getting the transcript for livechat room ${ roomId }.`);
228+
const messageConverter = this.orch.getConverters()?.get('messages');
229+
230+
if (!messageConverter) {
231+
throw new Error('Could not get the message converter to process livechat room messages');
232+
}
233+
234+
const boundMessageConverter = messageConverter.convertMessage.bind(messageConverter);
235+
236+
return Livechat.getRoomMessages({ rid: roomId }).map(boundMessageConverter);
237+
}
238+
225239
protected async setCustomFields(data: { token: IVisitor['token']; key: string; value: string; overwrite: boolean }, appId: string): Promise<number> {
226240
this.orch.debugLog(`The App ${ appId } is setting livechat visitor's custom fields.`);
227241

app/livechat/server/lib/Livechat.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,20 @@ export const Livechat = {
10961096
return true;
10971097
},
10981098

1099+
getRoomMessages({ rid }) {
1100+
check(rid, String);
1101+
1102+
const isLivechat = Promise.await(Rooms.findByTypeInIds('l', [rid])).count();
1103+
1104+
if (!isLivechat) {
1105+
throw new Meteor.Error('invalid-room');
1106+
}
1107+
1108+
const ignoredMessageTypes = ['livechat_navigation_history', 'livechat_transcript_history', 'command', 'livechat-close', 'livechat-started', 'livechat_video_call'];
1109+
1110+
return Messages.findVisibleByRoomIdNotContainingTypes(rid, ignoredMessageTypes, { sort: { ts: 1 } }).fetch();
1111+
},
1112+
10991113
requestTranscript({ rid, email, subject, user }) {
11001114
check(rid, String);
11011115
check(email, String);

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"@nivo/heatmap": "0.73.0",
159159
"@nivo/line": "0.62.0",
160160
"@nivo/pie": "0.73.0",
161-
"@rocket.chat/apps-engine": "1.28.0-alpha.5370",
161+
"@rocket.chat/apps-engine": "1.28.0-alpha.5379",
162162
"@rocket.chat/css-in-js": "^0.29.0",
163163
"@rocket.chat/emitter": "^0.29.0",
164164
"@rocket.chat/fuselage": "^0.29.0",

0 commit comments

Comments
 (0)