Skip to content

Commit

Permalink
Merge pull request #11 from RocketChat/modal/test
Browse files Browse the repository at this point in the history
feat: Add modal as a new test surface
  • Loading branch information
tiagoevanp authored Jul 3, 2024
2 parents d29a6b6 + 9ca1511 commit 8ddc2fa
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 128 deletions.
75 changes: 60 additions & 15 deletions AppsRocketChatTesterApp.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
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 { OpenModalSlashcommand } from "./slashcommands/OpenModalSlashcommand";
import { ModalViewSubmitHandler } from "./handlers/ModalHandlers";
import {
IUIKitResponse,
UIKitViewSubmitInteractionContext,
} from "@rocket.chat/apps-engine/definition/uikit";

export class RocketChatTester extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
Expand All @@ -26,10 +43,38 @@ export class RocketChatTester extends App {
});

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

configuration.videoConfProviders.provideVideoConfProvider(new TestVideoConfProvider());
configuration.videoConfProviders.provideVideoConfProvider(new UnconfiguredVideoConfProvider());
configuration.videoConfProviders.provideVideoConfProvider(
new TestVideoConfProvider()
);
configuration.videoConfProviders.provideVideoConfProvider(
new UnconfiguredVideoConfProvider()
);
}

public async executeViewSubmitHandler(
interactionContext: UIKitViewSubmitInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<IUIKitResponse> {
const data = interactionContext.getInteractionData();
const viewId = data.view.id;

if (viewId === "modal_example") {
return ModalViewSubmitHandler(interactionContext);
}

return { success: false };
}
}
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "bc4dd4a1-bf9b-408e-83a4-aba7eba0bf02",
"version": "0.0.5",
"requiredApiVersion": "^1.33.0",
"version": "0.1.0",
"requiredApiVersion": "^1.42.2",
"iconFile": "icon.png",
"author": {
"name": "Rocket.Chat",
Expand Down
Binary file added dist/appsrocketchattester_0.1.0.zip
Binary file not shown.
25 changes: 25 additions & 0 deletions handlers/ModalHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { UIKitViewSubmitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit";
import { IUIKitViewSubmitIncomingInteraction } from "@rocket.chat/apps-engine/definition/uikit/UIKitIncomingInteractionTypes";

const validation = (data: IUIKitViewSubmitIncomingInteraction) => {
const state = data.view.state as { default?: { modal_input: string } };

if (!state?.default?.modal_input) {
return false;
}

return true;
};

export const ModalViewSubmitHandler = (
interactionContext: UIKitViewSubmitInteractionContext
) => {
if (validation(interactionContext.getInteractionData())) {
return interactionContext.getInteractionResponder().successResponse();
} else {
return interactionContext.getInteractionResponder().viewErrorResponse({
viewId: interactionContext.getInteractionData().view.id,
errors: { modal_input: "Validation failed" },
});
}
};
Loading

0 comments on commit 8ddc2fa

Please sign in to comment.