-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Filipe Marins <filipe.marins@rocket.chat> Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com> Co-authored-by: murtaza98 <murtaza.patrawala@rocket.chat>
- Loading branch information
1 parent
85f61de
commit ef60939
Showing
71 changed files
with
1,697 additions
and
256 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ import './tags'; | |
import './units'; | ||
import './business-hours'; | ||
import './rooms'; | ||
import './transcript'; |
37 changes: 37 additions & 0 deletions
37
apps/meteor/ee/app/livechat-enterprise/server/api/transcript.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { LivechatRooms } from '@rocket.chat/models'; | ||
import { OmnichannelTranscript } from '@rocket.chat/core-services'; | ||
|
||
import { API } from '../../../../../app/api/server'; | ||
import { canAccessRoomAsync } from '../../../../../app/authorization/server/functions/canAccessRoom'; | ||
|
||
API.v1.addRoute( | ||
'omnichannel/:rid/request-transcript', | ||
{ authRequired: true, permissionsRequired: ['request-pdf-transcript'] }, | ||
{ | ||
async post() { | ||
const room = await LivechatRooms.findOneById(this.urlParams.rid); | ||
if (!room) { | ||
throw new Error('error-invalid-room'); | ||
} | ||
|
||
if (!(await canAccessRoomAsync(room, { _id: this.userId }))) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
|
||
// Flow is as follows: | ||
// 1. Call OmnichannelTranscript.requestTranscript() | ||
// 2. OmnichannelTranscript.requestTranscript() calls QueueWorker.queueWork() | ||
// 3. QueueWorker.queueWork() eventually calls OmnichannelTranscript.workOnPdf() | ||
// 4. OmnichannelTranscript.workOnPdf() calls OmnichannelTranscript.pdfComplete() when processing ends | ||
// 5. OmnichannelTranscript.pdfComplete() sends the messages to the user, and updates the room with the flags | ||
await OmnichannelTranscript.requestTranscript({ | ||
details: { | ||
userId: this.userId, | ||
rid: this.urlParams.rid, | ||
}, | ||
}); | ||
|
||
return API.v1.success(); | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Users } from '@rocket.chat/models'; | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
import type { IMessageService } from '@rocket.chat/core-services'; | ||
import { ServiceClassInternal } from '@rocket.chat/core-services'; | ||
|
||
import { createDirectMessage } from '../../methods/createDirectMessage'; | ||
import { executeSendMessage } from '../../../app/lib/server/methods/sendMessage'; | ||
|
||
export class MessageService extends ServiceClassInternal implements IMessageService { | ||
protected name = 'message'; | ||
|
||
async createDirectMessage({ to, from }: { to: string; from: string }): Promise<{ rid: string }> { | ||
const [toUser, fromUser] = await Promise.all([ | ||
Users.findOneById(to, { projection: { username: 1 } }), | ||
Users.findOneById(from, { projection: { _id: 1 } }), | ||
]); | ||
|
||
if (!toUser || !fromUser) { | ||
throw new Error('error-invalid-user'); | ||
} | ||
return createDirectMessage([toUser.username], fromUser._id); | ||
} | ||
|
||
async sendMessage({ fromId, rid, msg }: { fromId: string; rid: string; msg: string }): Promise<IMessage> { | ||
return executeSendMessage(fromId, { rid, msg }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ISettingsService } from '@rocket.chat/core-services'; | ||
import { ServiceClassInternal } from '@rocket.chat/core-services'; | ||
|
||
import { settings } from '../../../app/settings/server'; | ||
|
||
export class SettingsService extends ServiceClassInternal implements ISettingsService { | ||
protected name = 'settings'; | ||
|
||
async get<T>(settingId: string): Promise<T> { | ||
return settings.get<T>(settingId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; | ||
import { Settings } from '@rocket.chat/models'; | ||
import type { IUser } from '@rocket.chat/core-typings'; | ||
import mem from 'mem'; | ||
import { ServiceClassInternal } from '@rocket.chat/core-services'; | ||
import type { ITranslationService } from '@rocket.chat/core-services'; | ||
|
||
export class TranslationService extends ServiceClassInternal implements ITranslationService { | ||
protected name = 'translation'; | ||
|
||
// Cache the server language for 1 hour | ||
private getServerLanguageCached = mem(this.getServerLanguage.bind(this), { maxAge: 1000 * 60 * 60 }); | ||
|
||
private async getServerLanguage(): Promise<string> { | ||
return ((await Settings.findOneById('Language'))?.value as string) || 'en'; | ||
} | ||
|
||
// Use translateText when you already know the language, or want to translate to a predefined language | ||
translateText(text: string, targetLanguage: string): Promise<string> { | ||
return Promise.resolve(TAPi18n.__(text, { lng: targetLanguage })); | ||
} | ||
|
||
// Use translate when you want to translate to the user's language, or server's as a fallback | ||
async translate(text: string, user: IUser): Promise<string> { | ||
const language = user.language || (await this.getServerLanguageCached()); | ||
|
||
return this.translateText(text, language); | ||
} | ||
|
||
async translateToServerLanguage(text: string): Promise<string> { | ||
const language = await this.getServerLanguageCached(); | ||
|
||
return this.translateText(text, language); | ||
} | ||
} |
Oops, something went wrong.