Skip to content

Commit

Permalink
omni
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jul 3, 2023
1 parent cecac0e commit fffa157
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default (): void => {

b.on('getRoutingConfig', async () => {
const agent = rand(agents);

if (!agent) {
return;
}
await agent.getRoutingConfig();
const { departments } = (await agent.getAgentDepartments()) || {
departments: [],
Expand All @@ -151,11 +155,17 @@ export default (): void => {

b.on('getQueuedInquiries', async () => {
const agent = rand(agents);
if (!agent) {
return;
}
await agent.getQueuedInquiries();
});

b.on('takeInquiry', async () => {
const agent = rand(agents);
if (!agent) {
return;
}
const response = await agent.getQueuedInquiries();
if (!response?.inquiries) {
return;
Expand All @@ -170,6 +180,10 @@ export default (): void => {
}

const processedInquiry = rand(inquiries);

if (!processedInquiry) {
return;
}
try {
// Re-fetch inquiry
await agent.getInquiry(processedInquiry._id);
Expand All @@ -186,6 +200,9 @@ export default (): void => {

b.on('message', async () => {
const agent = rand(agents);
if (!agent) {
return;
}
const sub = agent.getRandomLivechatSubscription();

if (!sub) {
Expand Down
7 changes: 6 additions & 1 deletion src/client/Omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export class OmnichannelClient extends Client {
const subscriptions = this.subscriptions.filter(
(sub) => config.IGNORE_ROOMS.indexOf(sub.rid) === -1 && config.IGNORE_ROOMS.indexOf(sub.name) === -1 && sub.t === 'l',
);
return rand(subscriptions);
const subscription = rand(subscriptions);

if (!subscription) {
throw new Error('no subscriptions');
}
return subscription;
}

async getRoutingConfig(): Promise<{ [k: string]: string } | undefined> {
Expand Down
4 changes: 4 additions & 0 deletions src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default (): void => {
async function getLoggedInClient() {
const client = rand(clients);

if (!client) {
throw new Error('No logged in client found');
}

if (client.status === 'logging') {
throw new AlreadyLoggingError();
}
Expand Down

0 comments on commit fffa157

Please sign in to comment.