-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMainModalHandler.ts
More file actions
53 lines (52 loc) · 1.64 KB
/
MainModalHandler.ts
File metadata and controls
53 lines (52 loc) · 1.64 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
import { IRead, IPersistence, IHttp, IModify } from "@rocket.chat/apps-engine/definition/accessors";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands";
import { GithubApp } from "../GithubApp";
import { MainModal } from "../modals/MainModal";
import { getAccessTokenForUser } from "../persistance/auth";
import { sendNotification } from "../lib/message";
export async function handleMainModal(
read: IRead,
context: SlashCommandContext,
app: GithubApp,
persistence: IPersistence,
http: IHttp,
room: IRoom,
modify: IModify
) {
let accessToken = await getAccessTokenForUser(
read,
context.getSender(),
app.oauth2Config
);
if (accessToken && accessToken.token) {
const triggerId = context.getTriggerId();
if (triggerId) {
const modal = await MainModal({
modify: modify,
read: read,
persistence: persistence,
http: http,
slashcommandcontext: context,
id: app.getID(),
});
await modify
.getUiController()
.openSurfaceView(
modal,
{ triggerId },
context.getSender()
);
} else {
console.log("invalid Trigger ID !");
}
} else {
await sendNotification(
read,
modify,
context.getSender(),
room,
"Login to go in the Main Modal ! `/github login`"
);
}
}