Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Replace tslint with eslint and improve typing of app #72

Merged
merged 6 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.github
i18n
.*
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
"no-case-declarations": "off"
},
};
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: npm i -g @rocket.chat/apps-cli

- name: Tslint check
run: npm run tslint
run: npm run lint

- name: Bundle App
run: rc-apps package
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"useTabs": true,
"tabWidth": 4
}
130 changes: 85 additions & 45 deletions DialogflowApp.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,104 @@
import {
IAppAccessors,
IConfigurationExtend,
IConfigurationModify,
IHttp,
ILogger,
IModify,
IPersistence,
IRead,
IAppAccessors,
IConfigurationExtend,
IConfigurationModify,
IHttp,
ILogger,
IModify,
IPersistence,
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { ApiSecurity, ApiVisibility } from '@rocket.chat/apps-engine/definition/api';
import {
ApiSecurity,
ApiVisibility,
} from '@rocket.chat/apps-engine/definition/api';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { ILivechatMessage } from '@rocket.chat/apps-engine/definition/livechat';
import { IPostMessageSent } from '@rocket.chat/apps-engine/definition/messages';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { ISetting } from '@rocket.chat/apps-engine/definition/settings';
import { IUIKitLivechatInteractionHandler, IUIKitResponse, UIKitLivechatBlockInteractionContext } from '@rocket.chat/apps-engine/definition/uikit';
import {
IUIKitLivechatInteractionHandler,
IUIKitResponse,
UIKitLivechatBlockInteractionContext,
} from '@rocket.chat/apps-engine/definition/uikit';
import { settings } from './config/Settings';
import { FulfillmentsEndpoint } from './endpoints/FulfillmentsEndpoint';
import { IncomingEndpoint } from './endpoints/IncomingEndpoint';
import { ExecuteLivechatBlockActionHandler } from './handler/ExecuteLivechatBlockActionHandler';
import { OnSettingUpdatedHandler } from './handler/OnSettingUpdatedHandler';
import { PostMessageSentHandler } from './handler/PostMessageSentHandler';

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

public async executeLivechatBlockActionHandler(context: UIKitLivechatBlockInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify): Promise<IUIKitResponse> {
const handler = new ExecuteLivechatBlockActionHandler(this, context, read, http, persistence, modify);
return await handler.run();
}
public async executeLivechatBlockActionHandler(
context: UIKitLivechatBlockInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
): Promise<IUIKitResponse> {
const handler = new ExecuteLivechatBlockActionHandler(
this,
context,
read,
http,
persistence,
modify,
);
return await handler.run();
}

public async executePostMessageSent(message: ILivechatMessage,
read: IRead,
http: IHttp,
persis: IPersistence,
modify: IModify): Promise<void> {
const handler = new PostMessageSentHandler(this, message, read, http, persis, modify);
await handler.run();
}
public async executePostMessageSent(
message: ILivechatMessage,
read: IRead,
http: IHttp,
persis: IPersistence,
modify: IModify,
): Promise<void> {
const handler = new PostMessageSentHandler(
this,
message,
read,
http,
persis,
modify,
);
await handler.run();
}

public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
const onSettingUpdatedHandler: OnSettingUpdatedHandler = new OnSettingUpdatedHandler(this, read, http);
await onSettingUpdatedHandler.run();
}
public async onSettingUpdated(
setting: ISetting,
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
configurationModify: IConfigurationModify,
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
read: IRead,
http: IHttp,
): Promise<void> {
const onSettingUpdatedHandler: OnSettingUpdatedHandler =
new OnSettingUpdatedHandler(this, read, http);
await onSettingUpdatedHandler.run();
}

protected async extendConfiguration(configuration: IConfigurationExtend): Promise<void> {
configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [
new IncomingEndpoint(this),
new FulfillmentsEndpoint(this),
],
});
await Promise.all(settings.map((setting) => configuration.settings.provideSetting(setting)));
}
protected async extendConfiguration(
configuration: IConfigurationExtend,
): Promise<void> {
configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [
new IncomingEndpoint(this),
new FulfillmentsEndpoint(this),
],
});
await Promise.all(
settings.map((setting) =>
configuration.settings.provideSetting(setting),
),
);
}
}
33 changes: 15 additions & 18 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
{
"id": "21b7d3ba-031b-41d9-8ff2-fbbfa081ae90",
"version": "1.2.4",
"requiredApiVersion": "^1.17.0",
"iconFile": "icon.png",
"author": {
"name": "Rocket.Chat",
"homepage": "https://rocket.chat/",
"support": "support@rocket.chat"
},
"name": "Dialogflow",
"nameSlug": "dialogflow",
"classFile": "DialogflowApp.ts",
"description": "Integration between Rocket.Chat and the Dialogflow Chatbot platform",
"implements": [
"IPostMessageSent",
"IUIKitLivechatInteractionHandler"
]
}
"id": "21b7d3ba-031b-41d9-8ff2-fbbfa081ae90",
"version": "1.2.4",
"requiredApiVersion": "^1.17.0",
"iconFile": "icon.png",
"author": {
"name": "Rocket.Chat",
"homepage": "https://rocket.chat/",
"support": "support@rocket.chat"
},
"name": "Dialogflow",
"nameSlug": "dialogflow",
"classFile": "DialogflowApp.ts",
"description": "Integration between Rocket.Chat and the Dialogflow Chatbot platform",
"implements": ["IPostMessageSent", "IUIKitLivechatInteractionHandler"]
}
Loading