Skip to content

Commit

Permalink
feat: adding ui surface test
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanPazRibeiro committed Apr 10, 2024
1 parent d29a6b6 commit 6d5c18f
Show file tree
Hide file tree
Showing 9 changed files with 853 additions and 33 deletions.
106 changes: 88 additions & 18 deletions AppsRocketChatTesterApp.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import { IAppAccessors, IConfigurationExtend, ILogger } 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 { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { SendMessageAsAppUserEndpoint } from './endpoints/SendMessageAsAppUser';
import { SendMessageAsUserEndpoint } from './endpoints/SendMessageAsUser';
import { OpenContextualBarSlashcommand } from './slashcommands/OpenContextualBarSlashcommand';
import { TestArgumentsSlashcommand } from './slashcommands/TestArgumentsSlashcommand';
import { TestSlashcommand } from './slashcommands/TestSlashcommand';
import { TestVideoConfProvider } from './videoConfProviders/TestVideoConfProvider';
import { UnconfiguredVideoConfProvider } from './videoConfProviders/UnconfiguredVideoConfProvider';
import {
IAppAccessors,
IConfigurationExtend,
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 { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
import { SendMessageAsAppUserEndpoint } from "./endpoints/SendMessageAsAppUser";
import { SendMessageAsUserEndpoint } from "./endpoints/SendMessageAsUser";
import { OpenContextualBarSlashcommand } from "./slashcommands/OpenContextualBarSlashcommand";
import { TestArgumentsSlashcommand } from "./slashcommands/TestArgumentsSlashcommand";
import { TestSlashcommand } from "./slashcommands/TestSlashcommand";
import { TestVideoConfProvider } from "./videoConfProviders/TestVideoConfProvider";
import { UnconfiguredVideoConfProvider } from "./videoConfProviders/UnconfiguredVideoConfProvider";
import {
UIKitActionButtonInteractionContext,
IUIKitResponse,
IUIKitInteractionHandler,
UIKitViewSubmitInteractionContext,
} from "@rocket.chat/apps-engine/definition/uikit";
import { executeActionButtonHandler } from "./handlers/ActionHandler";
import { executeViewSubmitHandler } from "./handlers/SubmitInteraction";
import { UIActionButtonContext } from "@rocket.chat/apps-engine/definition/ui";

export class RocketChatTester extends App {
export class RocketChatTester extends App implements IUIKitInteractionHandler {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}

public async extendConfiguration(configuration: IConfigurationExtend) {
configuration.api.provideApi({
await configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [
Expand All @@ -25,11 +45,61 @@ export class RocketChatTester extends App {
],
});

configuration.slashCommands.provideSlashCommand(new TestSlashcommand());
configuration.slashCommands.provideSlashCommand(new TestArgumentsSlashcommand());
configuration.slashCommands.provideSlashCommand(new OpenContextualBarSlashcommand());
await configuration.slashCommands.provideSlashCommand(
new TestSlashcommand()
);
await configuration.slashCommands.provideSlashCommand(
new TestArgumentsSlashcommand()
);
await configuration.slashCommands.provideSlashCommand(
new OpenContextualBarSlashcommand()
);

configuration.videoConfProviders.provideVideoConfProvider(new TestVideoConfProvider());
configuration.videoConfProviders.provideVideoConfProvider(new UnconfiguredVideoConfProvider());
await configuration.videoConfProviders.provideVideoConfProvider(
new TestVideoConfProvider()
);
await configuration.videoConfProviders.provideVideoConfProvider(
new UnconfiguredVideoConfProvider()
);
await configuration.ui.registerButton({
actionId: "error",
labelI18n: "error",
context: UIActionButtonContext.ROOM_ACTION,
});
await configuration.ui.registerButton({
actionId: "timeout",
labelI18n: "timeout",
context: UIActionButtonContext.ROOM_ACTION,
});
await configuration.ui.registerButton({
actionId: "update",
labelI18n: "update",
context: UIActionButtonContext.ROOM_ACTION,
});
await configuration.ui.registerButton({
actionId: "success",
labelI18n: "success-btn",
context: UIActionButtonContext.ROOM_ACTION,
});
}

public async executeActionButtonHandler(
context: UIKitActionButtonInteractionContext,
_read: IRead,
_http: IHttp,
_persistence: IPersistence,
modify: IModify
): Promise<IUIKitResponse> {
return executeActionButtonHandler(context, modify);
}

public async executeViewSubmitHandler(
context: UIKitViewSubmitInteractionContext,
_read: IRead,
_http: IHttp,
_persistence: IPersistence,
modify: IModify
): Promise<IUIKitResponse> {
return executeViewSubmitHandler(context, modify);
}
}
49 changes: 46 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "bc4dd4a1-bf9b-408e-83a4-aba7eba0bf02",
"version": "0.0.5",
"version": "0.0.6",
"requiredApiVersion": "^1.33.0",
"iconFile": "icon.png",
"author": {
Expand All @@ -11,6 +11,49 @@
"name": "Apps.RocketChat.Tester",
"nameSlug": "appsrocketchattester",
"classFile": "AppsRocketChatTesterApp.ts",
"description": "An app that provides endpoints to test Apps integration to Rocket.Chat",
"implements": []
"description": "An app that provides endpoints to test Apps integration to Rocket.Chat ",
"implements": [
"IUIKitInteractionHandler"
],
"permissions": [
{
"name": "api"
},
{
"name": "persistence"
},
{
"name": "slashcommand"
},
{
"name": "networking"
},
{
"name": "ui.registerButtons"
},
{
"name": "ui.interact"
},
{
"name": "user.read"
},
{
"name": "user.write"
},
{
"name": "message.write"
},
{
"name": "room.read"
},
{
"name": "room.write"
},
{
"name": "server-setting.read"
},
{
"name": "video-conference-provider"
}
]
}
Binary file added dist/appsrocketchattester_0.0.6.zip
Binary file not shown.
15 changes: 15 additions & 0 deletions handlers/ActionHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UIKitActionButtonInteractionContext } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionContext";
import { modal } from "../ui/Modal";
import { IModify } from "@rocket.chat/apps-engine/definition/accessors";

export const executeActionButtonHandler = (
context: UIKitActionButtonInteractionContext,
modify: IModify
) => {
const data = context.getInteractionData();
const { actionId } = data;

modal(actionId, modify);

return context.getInteractionResponder().successResponse();
};
55 changes: 55 additions & 0 deletions handlers/SubmitInteraction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
IRead,
IHttp,
IPersistence,
IModify,
} from "@rocket.chat/apps-engine/definition/accessors";
import {
UIKitViewSubmitInteractionContext,
IUIKitResponse,
} from "@rocket.chat/apps-engine/definition/uikit";
import { modal } from "../ui/Modal";

export const executeViewSubmitHandler = async (
context: UIKitViewSubmitInteractionContext,
modify: IModify
): Promise<IUIKitResponse> => {
const data = context.getInteractionData();

const {
view: { id: viewId, submit },
} = data;

const action = submit?.actionId;

switch (action) {
case "error": {
return context.getInteractionResponder().viewErrorResponse({
viewId,
errors: {
"errors-test": "error value",
},
});
}

case "timeout": {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
context.getInteractionResponder().successResponse()
);
}, 60000);
});
}

case "update": {
return context
.getInteractionResponder()
.updateContextualBarViewResponse(modal(action, modify));
}

default: {
return context.getInteractionResponder().successResponse();
}
}
};
6 changes: 6 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error": "error",
"timeout": "timeout",
"update": "update",
"success": "success"
}
Loading

0 comments on commit 6d5c18f

Please sign in to comment.