forked from RocketChat/Apps.Salesforce.LiveAgent
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSalesforceLiveAgentApp.ts
More file actions
130 lines (119 loc) · 4.6 KB
/
SalesforceLiveAgentApp.ts
File metadata and controls
130 lines (119 loc) · 4.6 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import {
IAppAccessors,
IConfigurationExtend,
IEnvironmentRead,
IHttp,
ILogger,
IModify,
IPersistence,
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { ApiSecurity, ApiVisibility } from '@rocket.chat/apps-engine/definition/api';
import { App } from '@rocket.chat/apps-engine/definition/App';
import {
ILivechatEventContext,
ILivechatRoom,
IPostLivechatAgentAssigned,
IPostLivechatAgentUnassigned,
IPostLivechatRoomClosed,
} from '@rocket.chat/apps-engine/definition/livechat';
import { IMessage, IPostMessageSent } from '@rocket.chat/apps-engine/definition/messages';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { IRoomUserTyping, IRoomUserTypingContext } from '@rocket.chat/apps-engine/definition/rooms';
import {
IUIKitLivechatInteractionHandler,
IUIKitResponse,
UIKitLivechatBlockInteractionContext,
} from '@rocket.chat/apps-engine/definition/uikit';
import { AppSettings } from './config/AppSettings';
import { AvailabilityEndpoint } from './endpoints/AvailabilityEndpoint';
import { HandoverEndpoint } from './endpoints/HandoverEndpoint';
import { DialogflowAgentAssignedClass } from './lib/DialogflowAgentAssignedHandler';
import { IdleSessionTimeoutProcessor } from './lib/IdleSessionTimeoutProcessor';
import { LivechatBlockActionClassInitiate } from './lib/LivechatBlockActionHandler';
import { LivechatRoomClosedClass } from './lib/LivechatRoomClosedHandler';
import { OnUserTypingHandler } from './lib/OnUserTypingHandler';
import { PostMessageClassInitiate } from './lib/PostMessageClassInitiateHandler';
import { SalesforceAgentAssignedClass } from './lib/SalesforceAgentAssignedHandler';
export class SalesforceLiveAgentApp
extends App
implements
IPostMessageSent,
IPostLivechatAgentAssigned,
IPostLivechatAgentUnassigned,
IPostLivechatRoomClosed,
IRoomUserTyping,
IUIKitLivechatInteractionHandler
{
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async initialize(configurationExtend: IConfigurationExtend, _environmentRead: IEnvironmentRead): Promise<void> {
await this.extendConfiguration(configurationExtend);
this.getLogger().log('App Initialized');
}
public async executeLivechatBlockActionHandler(
context: UIKitLivechatBlockInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
): Promise<IUIKitResponse> {
const livechatBlockActionClassInitiate = new LivechatBlockActionClassInitiate(this, context, read, http, persistence, modify);
await livechatBlockActionClassInitiate.exec();
return context.getInteractionResponder().successResponse();
}
public async executePostLivechatAgentAssigned(
data: ILivechatEventContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
) {
const salesforceAgentAssigned = new SalesforceAgentAssignedClass(this, data, read, http, persistence, modify);
await salesforceAgentAssigned.exec();
}
public async executePostLivechatAgentUnassigned(
data: ILivechatEventContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
) {
const dialogflowAgentAssigned = new DialogflowAgentAssignedClass(this, data, read, http, persistence, modify);
await dialogflowAgentAssigned.exec();
}
public async executePostLivechatRoomClosed(
room: ILivechatRoom,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
): Promise<void> {
const livechatRoomClosedClass = new LivechatRoomClosedClass(this, room, read, http, persistence, modify);
await livechatRoomClosedClass.exec();
}
public async executePostMessageSent(
message: IMessage,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
): Promise<void> {
const postMessageClassInitiate = new PostMessageClassInitiate(this, message, read, http, persistence, modify);
await postMessageClassInitiate.exec();
}
public async executeOnRoomUserTyping(data: IRoomUserTypingContext, read: IRead, http: IHttp, persistence: IPersistence): Promise<void> {
const onUserTypingHandler = new OnUserTypingHandler(this, data, read, http, persistence);
await onUserTypingHandler.exec();
}
public async extendConfiguration(configuration: IConfigurationExtend): Promise<void> {
configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [new HandoverEndpoint(this), new AvailabilityEndpoint(this)],
});
await configuration.scheduler.registerProcessors([new IdleSessionTimeoutProcessor('idle-session-timeout')]);
AppSettings.forEach((setting) => configuration.settings.provideSetting(setting));
}
}