forked from RocketChat/Apps.Dialogflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueueWindowProcessor.ts
More file actions
28 lines (24 loc) · 1.28 KB
/
QueueWindowProcessor.ts
File metadata and controls
28 lines (24 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors';
import { IJobContext, IProcessor } from '@rocket.chat/apps-engine/definition/scheduler';
import { Logs } from '../enum/Logs';
import { getError } from './Helper';
import { setIsProcessingMessage } from './Persistence';
import { cancelAllEventSchedulerJobForSessionAndName } from './Scheduler';
export class QueueWindowScheduler implements IProcessor {
public id: string;
constructor(id: string) {
this.id = id;
}
public async processor(jobContext: IJobContext, read: IRead, modify: IModify, http: IHttp, persistence: IPersistence): Promise<void> {
const sessionId = jobContext.rid;
const eventName = jobContext.eventName;
try {
await setIsProcessingMessage(read, persistence, sessionId, false);
await cancelAllEventSchedulerJobForSessionAndName(modify, sessionId, eventName);
console.log(`{ roomID: ${jobContext.rid} } The DF App is dropping the blackout window from the event ${ eventName } due to blackout`);
} catch (error) {
// Failed to send event, so close blackout window
console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${sessionId} } ${getError(error)}`);
}
}
}