1- import { Omnichannel } from '@rocket.chat/core-services' ;
21import type { ServerMethods } from '@rocket.chat/ddp-client' ;
3- import { LivechatInquiry , LivechatRooms , Users } from '@rocket.chat/models' ;
42import { Meteor } from 'meteor/meteor' ;
53
64import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission' ;
7- import { settings } from '../../../settings/server' ;
8- import { RoutingManager } from '../lib/RoutingManager' ;
9- import { isAgentAvailableToTakeContactInquiry } from '../lib/contacts/isAgentAvailableToTakeContactInquiry' ;
10- import { migrateVisitorIfMissingContact } from '../lib/contacts/migrateVisitorIfMissingContact' ;
5+ import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger' ;
6+ import { takeInquiry } from '../lib/takeInquiry' ;
117
128declare module '@rocket.chat/ddp-client' {
139 // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -19,72 +15,22 @@ declare module '@rocket.chat/ddp-client' {
1915 }
2016}
2117
22- export const takeInquiry = async (
23- userId : string ,
24- inquiryId : string ,
25- options ?: { clientAction : boolean ; forwardingToDepartment ?: { oldDepartmentId : string ; transferData : any } } ,
26- ) : Promise < void > => {
27- if ( ! userId || ! ( await hasPermissionAsync ( userId , 'view-l-room' ) ) ) {
28- throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , {
29- method : 'livechat:takeInquiry' ,
30- } ) ;
31- }
32-
33- const inquiry = await LivechatInquiry . findOneById ( inquiryId ) ;
34-
35- if ( ! inquiry ) {
36- throw new Meteor . Error ( 'error-not-found' , 'Inquiry not found' , {
37- method : 'livechat:takeInquiry' ,
38- } ) ;
39- }
40-
41- if ( inquiry . status === 'taken' ) {
42- throw new Meteor . Error ( 'error-inquiry-taken' , 'Inquiry already taken' , {
43- method : 'livechat:takeInquiry' ,
44- } ) ;
45- }
46-
47- const user = await Users . findOneOnlineAgentById ( userId , settings . get < boolean > ( 'Livechat_enabled_when_agent_idle' ) ) ;
48- if ( ! user ) {
49- throw new Meteor . Error ( 'error-agent-status-service-offline' , 'Agent status is offline or Omnichannel service is not active' , {
50- method : 'livechat:takeInquiry' ,
51- } ) ;
52- }
53-
54- const room = await LivechatRooms . findOneById ( inquiry . rid ) ;
55- if ( ! room || ! ( await Omnichannel . isWithinMACLimit ( room ) ) ) {
56- throw new Meteor . Error ( 'error-mac-limit-reached' ) ;
57- }
58-
59- const contactId = room . contactId ?? ( await migrateVisitorIfMissingContact ( room . v . _id , room . source ) ) ;
60- if ( contactId ) {
61- const isAgentAvailableToTakeContactInquiryResult = await isAgentAvailableToTakeContactInquiry ( inquiry . v . _id , room . source , contactId ) ;
62- if ( ! isAgentAvailableToTakeContactInquiryResult . value ) {
63- throw new Meteor . Error ( isAgentAvailableToTakeContactInquiryResult . error ) ;
64- }
65- }
66-
67- const agent = {
68- agentId : user . _id ,
69- username : user . username ,
70- } ;
71-
72- try {
73- await RoutingManager . takeInquiry ( inquiry , agent , options ?? { } , room ) ;
74- } catch ( e : any ) {
75- throw new Meteor . Error ( e . message ) ;
76- }
77- } ;
78-
7918Meteor . methods < ServerMethods > ( {
8019 async 'livechat:takeInquiry' ( inquiryId , options ) {
20+ methodDeprecationLogger . method ( 'livechat:takeInquiry' , '8.0.0' , '/v1/livechat/inquiries.take' ) ;
8121 const uid = Meteor . userId ( ) ;
8222 if ( ! uid ) {
8323 throw new Meteor . Error ( 'error-not-allowed' , 'Invalid User' , {
8424 method : 'livechat:takeInquiry' ,
8525 } ) ;
8626 }
8727
28+ if ( ! ( await hasPermissionAsync ( uid , 'view-l-room' ) ) ) {
29+ throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , {
30+ method : 'livechat:takeInquiry' ,
31+ } ) ;
32+ }
33+
8834 return takeInquiry ( uid , inquiryId , options ) ;
8935 } ,
9036} ) ;
0 commit comments