2022-03-07 21:16:20 +00:00
|
|
|
import sdk from '../../../lib/rocketchat/services/sdk';
|
|
|
|
import { IUser } from '../../../definitions';
|
2020-08-28 19:41:08 +00:00
|
|
|
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
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
export const isOmnichannelStatusAvailable = (user: IUser): boolean => user?.statusLivechat === 'available';
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
// RC 0.26.0
|
2022-03-07 21:16:20 +00:00
|
|
|
export const changeLivechatStatus = () => sdk.methodCallWrapper('livechat:changeLivechatStatus');
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
// RC 2.4.0
|
2022-03-07 21:16:20 +00:00
|
|
|
// @ts-ignore
|
|
|
|
export const getInquiriesQueued = () => sdk.get('livechat/inquiries.queued');
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
// this inquiry is added to the db by the subscriptions stream
|
|
|
|
// and will be removed by the queue stream
|
|
|
|
// RC 2.4.0
|
2022-03-07 21:16:20 +00:00
|
|
|
export const takeInquiry = (inquiryId: string) => sdk.methodCallWrapper('livechat:takeInquiry', inquiryId);
|
2020-08-28 19:41:08 +00:00
|
|
|
|
|
|
|
class Omnichannel {
|
2022-03-07 21:16:20 +00:00
|
|
|
private inquirySub: { stop: () => void } | null;
|
2020-08-28 19:41:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2020-08-28 19:41:08 +00:00
|
|
|
const omnichannel = new Omnichannel();
|