Skip to content

Commit 4b33b92

Browse files
alfredodelfabrosampaiodiego
authored andcommitted
feature: adds executePreLivechatRoomCreatePrevent hook (#14)
Co-authored-by: Diego Sampaio <[email protected]>
1 parent 33aed28 commit 4b33b92

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

AppsRocketChatTesterApp.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ import {
2727
IUIKitResponse,
2828
UIKitViewSubmitInteractionContext,
2929
} from "@rocket.chat/apps-engine/definition/uikit";
30-
import { UserNotAllowedException } from "@rocket.chat/apps-engine/definition/exceptions";
30+
import { AppsEngineException, UserNotAllowedException } from "@rocket.chat/apps-engine/definition/exceptions";
3131
import {
3232
IPreRoomUserJoined,
3333
IRoomUserJoinedContext,
3434
} from "@rocket.chat/apps-engine/definition/rooms";
35+
import { ILivechatRoom, IPreLivechatRoomCreatePrevent } from "@rocket.chat/apps-engine/definition/livechat";
3536

36-
export class RocketChatTester extends App implements IPreRoomUserJoined {
37+
export class RocketChatTester extends App implements IPreRoomUserJoined, IPreLivechatRoomCreatePrevent {
3738
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
3839
super(info, logger, accessors);
3940
}
4041

42+
async executeLivechatRoomCreatePrevent(room: ILivechatRoom, read: IRead, http: IHttp, persis: IPersistence): Promise<void> {
43+
if (room.visitor.name == 'visitor prevent from app') {
44+
throw new AppsEngineException('Visitor name is not allowed');
45+
}
46+
}
47+
4148
public async extendConfiguration(configuration: IConfigurationExtend) {
4249
configuration.api.provideApi({
4350
visibility: ApiVisibility.PUBLIC,

app.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "bc4dd4a1-bf9b-408e-83a4-aba7eba0bf02",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"requiredApiVersion": "^1.44.0",
55
"iconFile": "icon.png",
66
"author": {
@@ -13,6 +13,7 @@
1313
"classFile": "AppsRocketChatTesterApp.ts",
1414
"description": "An app that provides endpoints to test Apps integration to Rocket.Chat",
1515
"implements": [
16-
"IPreRoomUserJoined"
16+
"IPreRoomUserJoined",
17+
"IPreLivechatRoomCreatePrevent"
1718
]
1819
}

dist/appsrocketchattester_0.3.0.zip

14.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)