2020-08-28 19:41:08 +00:00
|
|
|
import RocketChat from '../../../lib/rocketchat';
|
|
|
|
import EventEmitter from '../../../utils/events';
|
2021-09-13 20:41:05 +00:00
|
|
|
import subscribeInquiry from './subscriptions/inquiry';
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
export const isOmnichannelStatusAvailable = user => user?.statusLivechat === 'available';
|
|
|
|
|
|
|
|
// RC 0.26.0
|
|
|
|
export const changeLivechatStatus = () => RocketChat.methodCallWrapper('livechat:changeLivechatStatus');
|
|
|
|
|
|
|
|
// RC 2.4.0
|
|
|
|
export const getInquiriesQueued = () => RocketChat.sdk.get('livechat/inquiries.queued');
|
|
|
|
|
|
|
|
// this inquiry is added to the db by the subscriptions stream
|
|
|
|
// and will be removed by the queue stream
|
|
|
|
// RC 2.4.0
|
|
|
|
export const takeInquiry = inquiryId => RocketChat.methodCallWrapper('livechat:takeInquiry', inquiryId);
|
|
|
|
|
|
|
|
class Omnichannel {
|
|
|
|
constructor() {
|
|
|
|
this.inquirySub = null;
|
|
|
|
EventEmitter.addEventListener('INQUIRY_SUBSCRIBE', this.subscribeInquiry);
|
|
|
|
EventEmitter.addEventListener('INQUIRY_UNSUBSCRIBE', this.unsubscribeInquiry);
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
subscribeInquiry = async () => {
|
2020-08-28 19:41:08 +00:00
|
|
|
console.log('[RCRN] Subscribing to inquiry');
|
|
|
|
this.inquirySub = await subscribeInquiry();
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
unsubscribeInquiry = () => {
|
|
|
|
if (this.inquirySub) {
|
|
|
|
console.log('[RCRN] Unsubscribing from inquiry');
|
|
|
|
this.inquirySub.stop();
|
|
|
|
this.inquirySub = null;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-08-28 19:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const omnichannel = new Omnichannel();
|