From 0eb8f966d4fe3cd8341095be0e790e2a38d9ad32 Mon Sep 17 00:00:00 2001 From: varsubham Date: Tue, 26 Dec 2023 14:04:59 +0530 Subject: [PATCH 01/13] feat(provider): rocket.chat initial commit --- .../app/integrations/dtos/credentials.dto.ts | 5 ++ .../integration/integration.schema.ts | 1 + .../src/consts/providers/channels/chat.ts | 10 ++- .../credentials/provider-credentials.ts | 24 ++++++ .../src/consts/providers/provider.enum.ts | 2 + .../integration/credential.interface.ts | 1 + packages/application-generic/package.json | 1 + .../src/factories/chat/chat.factory.ts | 2 + .../chat/handlers/rocket-chat.handler.ts | 14 ++++ pnpm-lock.yaml | 77 +++++++++++++++--- providers/rocket-chat/.czrc | 3 + providers/rocket-chat/.eslintrc.json | 3 + providers/rocket-chat/.gitignore | 9 +++ providers/rocket-chat/README.md | 9 +++ providers/rocket-chat/jest.config.js | 5 ++ providers/rocket-chat/package.json | 78 +++++++++++++++++++ providers/rocket-chat/src/index.ts | 1 + .../src/lib/rocket-chat.provider.spec.ts | 3 + .../src/lib/rocket-chat.provider.ts | 53 +++++++++++++ providers/rocket-chat/tsconfig.json | 10 +++ providers/rocket-chat/tsconfig.module.json | 9 +++ 21 files changed, 308 insertions(+), 12 deletions(-) create mode 100644 packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts create mode 100644 providers/rocket-chat/.czrc create mode 100644 providers/rocket-chat/.eslintrc.json create mode 100644 providers/rocket-chat/.gitignore create mode 100644 providers/rocket-chat/README.md create mode 100644 providers/rocket-chat/jest.config.js create mode 100644 providers/rocket-chat/package.json create mode 100644 providers/rocket-chat/src/index.ts create mode 100644 providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts create mode 100644 providers/rocket-chat/src/lib/rocket-chat.provider.ts create mode 100644 providers/rocket-chat/tsconfig.json create mode 100644 providers/rocket-chat/tsconfig.module.json diff --git a/apps/api/src/app/integrations/dtos/credentials.dto.ts b/apps/api/src/app/integrations/dtos/credentials.dto.ts index 95049a0a749..da8ac3a0575 100644 --- a/apps/api/src/app/integrations/dtos/credentials.dto.ts +++ b/apps/api/src/app/integrations/dtos/credentials.dto.ts @@ -196,4 +196,9 @@ export class CredentialsDto implements ICredentials { @IsString() @IsOptional() externalLink?: string; + + @ApiPropertyOptional() + @IsString() + @IsOptional() + roomId?: string; } diff --git a/libs/dal/src/repositories/integration/integration.schema.ts b/libs/dal/src/repositories/integration/integration.schema.ts index 492956caa67..f2fbfa672a7 100644 --- a/libs/dal/src/repositories/integration/integration.schema.ts +++ b/libs/dal/src/repositories/integration/integration.schema.ts @@ -58,6 +58,7 @@ const integrationSchema = new Schema( imageUrl: Schema.Types.String, state: Schema.Types.String, externalLink: Schema.Types.String, + roomId: Schema.Types.String, }, active: { type: Schema.Types.Boolean, diff --git a/libs/shared/src/consts/providers/channels/chat.ts b/libs/shared/src/consts/providers/channels/chat.ts index 5234c9c783b..b72e9eb5aa6 100644 --- a/libs/shared/src/consts/providers/channels/chat.ts +++ b/libs/shared/src/consts/providers/channels/chat.ts @@ -1,5 +1,5 @@ import { IConfigCredentials, IProviderConfig } from '../provider.interface'; -import { grafanaOnCallConfig, slackConfig, getstreamConfig } from '../credentials'; +import { grafanaOnCallConfig, slackConfig, getstreamConfig, rocketChatConfig } from '../credentials'; import { ChatProviderIdEnum } from '../provider.enum'; @@ -70,4 +70,12 @@ export const chatProviders: IProviderConfig[] = [ docReference: 'https://getstream.io/chat/docs/node/?language=javascript', logoFileName: { light: 'getstream.svg', dark: 'getstream.svg' }, }, + { + id: ChatProviderIdEnum.RocketChat, + displayName: 'Rocket.Chat', + channel: ChannelTypeEnum.CHAT, + credentials: rocketChatConfig, + docReference: 'https://developer.rocket.chat/reference/api/rest-api/endpoints', + logoFileName: { light: 'zulip.svg', dark: 'zulip.svg' }, + }, ]; diff --git a/libs/shared/src/consts/providers/credentials/provider-credentials.ts b/libs/shared/src/consts/providers/credentials/provider-credentials.ts index e10fe9ada0a..9dcf4a3ca46 100644 --- a/libs/shared/src/consts/providers/credentials/provider-credentials.ts +++ b/libs/shared/src/consts/providers/credentials/provider-credentials.ts @@ -1019,3 +1019,27 @@ export const azureSmsConfig: IConfigCredentials[] = [ }, ...smsConfigBase, ]; + +export const rocketChatConfig: IConfigCredentials[] = [ + { + key: CredentialsKeyEnum.Token, + displayName: 'Personal Access Token (x-auth-token)', + description: 'Personal Access Token of your user', + type: 'text', + required: true, + }, + { + key: CredentialsKeyEnum.User, + displayName: 'User id (x-user-id)', + description: 'Your User id', + type: 'text', + required: true, + }, + { + key: CredentialsKeyEnum.roomId, + displayName: 'Room Id', + description: 'Your Room ID', + type: 'text', + required: true, + }, +]; diff --git a/libs/shared/src/consts/providers/provider.enum.ts b/libs/shared/src/consts/providers/provider.enum.ts index 63b108924f2..0d6b0b69cce 100644 --- a/libs/shared/src/consts/providers/provider.enum.ts +++ b/libs/shared/src/consts/providers/provider.enum.ts @@ -43,6 +43,7 @@ export enum CredentialsKeyEnum { imageUrl = 'imageUrl', state = 'state', externalLink = 'externalLink', + roomId = 'roomId', } export enum EmailProviderIdEnum { @@ -107,6 +108,7 @@ export enum ChatProviderIdEnum { Zulip = 'zulip', GrafanaOnCall = 'grafana-on-call', GetStream = 'getstream', + RocketChat = 'rocket-chat', } export enum PushProviderIdEnum { diff --git a/libs/shared/src/entities/integration/credential.interface.ts b/libs/shared/src/entities/integration/credential.interface.ts index 43461059350..d882aee3a69 100644 --- a/libs/shared/src/entities/integration/credential.interface.ts +++ b/libs/shared/src/entities/integration/credential.interface.ts @@ -41,4 +41,5 @@ export interface ICredentials { imageUrl?: string; state?: string; externalLink?: string; + roomId?: string; } diff --git a/packages/application-generic/package.json b/packages/application-generic/package.json index 8e983d13d90..50222a0c296 100644 --- a/packages/application-generic/package.json +++ b/packages/application-generic/package.json @@ -113,6 +113,7 @@ "@novu/twilio": "^0.22.0", "@novu/zulip": "^0.22.0", "@novu/nexmo": "^0.22.0", + "@novu/rocket-chat": "^0.16.3", "@sentry/node": "^7.12.1", "analytics-node": "^6.2.0", "axios": "^1.6.2", diff --git a/packages/application-generic/src/factories/chat/chat.factory.ts b/packages/application-generic/src/factories/chat/chat.factory.ts index 957afccada3..45149e4e6c2 100644 --- a/packages/application-generic/src/factories/chat/chat.factory.ts +++ b/packages/application-generic/src/factories/chat/chat.factory.ts @@ -8,6 +8,7 @@ import { GrafanaOnCallHandler } from './handlers/grafana-on-call.handler'; import { RyverHandler } from './handlers/ryver.handler'; import { ZulipHandler } from './handlers/zulip.handler'; import { GetstreamChatHandler } from './handlers/getstream.handler'; +import { RocketChatChatHandler } from './handlers/rocket-chat.handler'; export class ChatFactory implements IChatFactory { handlers: IChatHandler[] = [ @@ -19,6 +20,7 @@ export class ChatFactory implements IChatFactory { new ZulipHandler(), new GrafanaOnCallHandler(), new GetstreamChatHandler(), + new RocketChatChatHandler(), ]; getHandler(integration: IntegrationEntity) { diff --git a/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts new file mode 100644 index 00000000000..881b892203f --- /dev/null +++ b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts @@ -0,0 +1,14 @@ +import { ICredentials, ChatProviderIdEnum } from '@novu/shared'; +import { ChannelTypeEnum } from '@novu/stateless'; +import { BaseChatHandler } from './base.handler'; +import { RocketChatChatProvider } from '@novu/rocket-chat'; + +export class RocketChatChatHandler extends BaseChatHandler { + constructor() { + super(ChatProviderIdEnum.RocketChat, ChannelTypeEnum.CHAT); + } + + buildProvider(credentials: ICredentials) { + this.provider = new RocketChatChatProvider(credentials); + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 249a47df2b9..86096ec727d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2597,6 +2597,9 @@ importers: '@novu/resend': specifier: ^0.22.0 version: link:../../providers/resend + '@novu/rocket-chat': + specifier: ^0.16.3 + version: link:../../providers/rocket-chat '@novu/ryver': specifier: ^0.22.0 version: link:../../providers/ryver @@ -5631,6 +5634,49 @@ importers: specifier: 4.9.5 version: 4.9.5 + providers/rocket-chat: + dependencies: + '@novu/stateless': + specifier: 0.16.3 + version: 0.16.3 + axios: + specifier: ^1.6.2 + version: 1.6.2 + devDependencies: + '@istanbuljs/nyc-config-typescript': + specifier: ~1.0.1 + version: 1.0.2(nyc@15.1.0) + '@types/jest': + specifier: ~27.5.2 + version: 27.5.2 + cspell: + specifier: ~6.19.2 + version: 6.19.2 + jest: + specifier: ~27.5.1 + version: 27.5.1(ts-node@10.9.1) + npm-run-all: + specifier: ^4.1.5 + version: 4.1.5 + nyc: + specifier: ~15.1.0 + version: 15.1.0 + prettier: + specifier: ~2.8.0 + version: 2.8.7 + rimraf: + specifier: ~3.0.2 + version: 3.0.2 + ts-jest: + specifier: ~27.1.5 + version: 27.1.5(@babel/core@7.23.2)(@types/jest@27.5.2)(jest@27.5.1)(typescript@4.9.5) + ts-node: + specifier: ~10.9.1 + version: 10.9.1(@types/node@14.18.42)(typescript@4.9.5) + typescript: + specifier: 4.9.5 + version: 4.9.5 + providers/ryver: dependencies: '@novu/stateless': @@ -13702,7 +13748,7 @@ packages: '@types/react': optional: true dependencies: - '@babel/runtime': 7.23.2 + '@babel/runtime': 7.21.0 '@emotion/babel-plugin': 11.10.6 '@emotion/is-prop-valid': 1.2.0 '@emotion/react': 11.10.6(@types/react@17.0.62)(react@17.0.2) @@ -17060,6 +17106,15 @@ packages: vue-resize: 2.0.0-alpha.1(vue@3.2.47) dev: false + /@novu/stateless@0.16.3: + resolution: {integrity: sha512-9wrqUluSaR9rCdDp4oUWFBwsk6OSM4P+yMaEtFGHrGmSPMcspnvXQaQoARKakuUpCXFvQlPPJq5+yaicv4o/hA==} + engines: {node: '>=10'} + dependencies: + handlebars: 4.7.7 + lodash.get: 4.4.2 + lodash.merge: 4.6.2 + dev: false + /@npmcli/arborist@5.3.0: resolution: {integrity: sha512-+rZ9zgL1lnbl8Xbb1NQdMjveOMwj4lIYfcDtyJHHi5x4X8jtR6m8SXooJMZy5vmFVZ8w7A2Bnd/oX9eTuU8w5A==} engines: {node: ^12.13.0 || ^14.15.0 || >=16.0.0} @@ -49632,13 +49687,13 @@ packages: uglify-js: optional: true dependencies: - '@jridgewell/trace-mapping': 0.3.19 + '@jridgewell/trace-mapping': 0.3.18 '@swc/core': 1.3.49 esbuild: 0.18.20 jest-worker: 27.5.1 - schema-utils: 3.3.0 + schema-utils: 3.1.2 serialize-javascript: 6.0.1 - terser: 5.22.0 + terser: 5.16.9 webpack: 5.78.0(@swc/core@1.3.49)(esbuild@0.18.20)(webpack-cli@5.1.4) /terser-webpack-plugin@5.3.9(@swc/core@1.3.49)(esbuild@0.18.20)(webpack@5.82.1): @@ -49682,12 +49737,12 @@ packages: uglify-js: optional: true dependencies: - '@jridgewell/trace-mapping': 0.3.19 + '@jridgewell/trace-mapping': 0.3.18 esbuild: 0.18.17 jest-worker: 27.5.1 - schema-utils: 3.3.0 + schema-utils: 3.1.2 serialize-javascript: 6.0.1 - terser: 5.22.0 + terser: 5.16.9 webpack: 5.88.2(esbuild@0.18.17) dev: true @@ -49707,11 +49762,11 @@ packages: uglify-js: optional: true dependencies: - '@jridgewell/trace-mapping': 0.3.19 + '@jridgewell/trace-mapping': 0.3.18 jest-worker: 27.5.1 - schema-utils: 3.3.0 + schema-utils: 3.1.2 serialize-javascript: 6.0.1 - terser: 5.22.0 + terser: 5.16.9 webpack: 5.78.0 dev: true @@ -50268,7 +50323,7 @@ packages: chalk: 4.1.2 enhanced-resolve: 5.15.0 micromatch: 4.0.5 - semver: 7.5.4 + semver: 7.5.2 typescript: 4.9.5 webpack: 5.82.1(@swc/core@1.3.49)(esbuild@0.18.20)(webpack-cli@5.1.4) dev: true diff --git a/providers/rocket-chat/.czrc b/providers/rocket-chat/.czrc new file mode 100644 index 00000000000..d1bcc209ca1 --- /dev/null +++ b/providers/rocket-chat/.czrc @@ -0,0 +1,3 @@ +{ + "path": "cz-conventional-changelog" +} diff --git a/providers/rocket-chat/.eslintrc.json b/providers/rocket-chat/.eslintrc.json new file mode 100644 index 00000000000..ec40100be69 --- /dev/null +++ b/providers/rocket-chat/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../.eslintrc.js" +} diff --git a/providers/rocket-chat/.gitignore b/providers/rocket-chat/.gitignore new file mode 100644 index 00000000000..963d5292865 --- /dev/null +++ b/providers/rocket-chat/.gitignore @@ -0,0 +1,9 @@ +.idea/* +.nyc_output +build +node_modules +test +src/**.js +coverage +*.log +package-lock.json diff --git a/providers/rocket-chat/README.md b/providers/rocket-chat/README.md new file mode 100644 index 00000000000..de03087d85a --- /dev/null +++ b/providers/rocket-chat/README.md @@ -0,0 +1,9 @@ +# Novu RocketChat Provider + +A RocketChat chat provider library for [@novu/node](https://github.com/novuhq/novu) + +## Usage + +```javascript + FILL IN THE INITIALIZATION USAGE +``` diff --git a/providers/rocket-chat/jest.config.js b/providers/rocket-chat/jest.config.js new file mode 100644 index 00000000000..e86e13bab91 --- /dev/null +++ b/providers/rocket-chat/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/providers/rocket-chat/package.json b/providers/rocket-chat/package.json new file mode 100644 index 00000000000..396a0e2e92e --- /dev/null +++ b/providers/rocket-chat/package.json @@ -0,0 +1,78 @@ +{ + "name": "@novu/rocket-chat", + "version": "0.16.3", + "description": "A rocket-chat wrapper for novu", + "main": "build/main/index.js", + "typings": "build/main/index.d.ts", + "module": "build/module/index.js", + "private": false, + "repository": "https://github.com/novuhq/novu", + "license": "MIT", + "keywords": [], + "scripts": { + "prebuild": "rimraf build", + "build": "run-p build:*", + "build:main": "tsc -p tsconfig.json", + "build:module": "tsc -p tsconfig.module.json", + "fix": "run-s fix:*", + "fix:prettier": "prettier \"src/**/*.ts\" --write", + "fix:lint": "eslint src --ext .ts --fix", + "test": "run-s test:*", + "lint": "eslint src --ext .ts", + "test:unit": "jest src", + "watch:build": "tsc -p tsconfig.json -w", + "watch:test": "jest src --watch", + "reset-hard": "git clean -dfx && git reset --hard && yarn", + "prepare-release": "run-s reset-hard test" + }, + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@novu/stateless": "0.16.3", + "axios": "^1.6.2" + }, + "devDependencies": { + "@istanbuljs/nyc-config-typescript": "~1.0.1", + "@types/jest": "~27.5.2", + "cspell": "~6.19.2", + "jest": "~27.5.1", + "npm-run-all": "^4.1.5", + "nyc": "~15.1.0", + "prettier": "~2.8.0", + "rimraf": "~3.0.2", + "ts-jest": "~27.1.5", + "ts-node": "~10.9.1", + "typescript": "4.9.5" + }, + "files": [ + "build/main", + "build/module", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ], + "ava": { + "failFast": true, + "timeout": "60s", + "typescript": { + "rewritePaths": { + "src/": "build/main/" + } + }, + "files": [ + "!build/module/**" + ] + }, + "prettier": { + "singleQuote": true + }, + "nyc": { + "extends": "@istanbuljs/nyc-config-typescript", + "exclude": [ + "**/*.spec.js" + ] + } +} diff --git a/providers/rocket-chat/src/index.ts b/providers/rocket-chat/src/index.ts new file mode 100644 index 00000000000..65539af5399 --- /dev/null +++ b/providers/rocket-chat/src/index.ts @@ -0,0 +1 @@ +export * from './lib/rocket-chat.provider'; diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts new file mode 100644 index 00000000000..bbb08d058e5 --- /dev/null +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts @@ -0,0 +1,3 @@ +import { RocketChatChatProvider } from './rocket-chat.provider'; + +test('should trigger rocket-chat library correctly', async () => {}); diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts new file mode 100644 index 00000000000..bf05f661c0c --- /dev/null +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -0,0 +1,53 @@ +import { + ChannelTypeEnum, + ISendMessageSuccessResponse, + IChatOptions, + IChatProvider, +} from '@novu/stateless'; +import axios from 'axios'; + +export class RocketChatChatProvider implements IChatProvider { + id = 'rocket-chat'; + channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT; + private axiosInstance = axios.create(); + + constructor( + private config: { + token?: string; + user?: string; + idPath?: string; + roomId?: string; + } + ) {} + + async sendMessage( + options: IChatOptions + ): Promise { + let payload = { + message: { + rid: this.config.roomId, + msg: options.content, + }, + }; + try { + // take whatever json payload client enters (this is for optional params) + payload = JSON.parse(options.content); + payload.message.rid = this.config.roomId; + } catch (err) {} + + const headers = { + 'x-auth-token': this.config.token, + 'x-user-id': this.config.idPath, + 'Content-Type': 'application/json', + }; + const baseURL = `${options.webhookUrl.toString()}/api/v1/chat.sendMessage`; + const { data } = await this.axiosInstance.post(baseURL, payload, { + headers: headers, + }); + + return { + id: data.message._id, + date: data.message.ts, + }; + } +} diff --git a/providers/rocket-chat/tsconfig.json b/providers/rocket-chat/tsconfig.json new file mode 100644 index 00000000000..5b8120fea36 --- /dev/null +++ b/providers/rocket-chat/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "build/main", + "rootDir": "src", + "types": ["node", "jest"] + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules/**"] +} diff --git a/providers/rocket-chat/tsconfig.module.json b/providers/rocket-chat/tsconfig.module.json new file mode 100644 index 00000000000..79be3a5c40b --- /dev/null +++ b/providers/rocket-chat/tsconfig.module.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "target": "esnext", + "outDir": "build/module", + "module": "esnext" + }, + "exclude": ["node_modules/**"] +} From b2ca46da8bc1821d94c58e7a6574b051070e8669 Mon Sep 17 00:00:00 2001 From: varsubham Date: Tue, 26 Dec 2023 15:35:08 +0530 Subject: [PATCH 02/13] feat(provider): remove room-id from config --- apps/api/src/app/integrations/dtos/credentials.dto.ts | 5 ----- .../src/repositories/integration/integration.schema.ts | 1 - .../consts/providers/credentials/provider-credentials.ts | 7 ------- libs/shared/src/consts/providers/provider.enum.ts | 1 - .../src/entities/integration/credential.interface.ts | 1 - providers/rocket-chat/src/lib/rocket-chat.provider.ts | 8 ++++---- 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/apps/api/src/app/integrations/dtos/credentials.dto.ts b/apps/api/src/app/integrations/dtos/credentials.dto.ts index da8ac3a0575..95049a0a749 100644 --- a/apps/api/src/app/integrations/dtos/credentials.dto.ts +++ b/apps/api/src/app/integrations/dtos/credentials.dto.ts @@ -196,9 +196,4 @@ export class CredentialsDto implements ICredentials { @IsString() @IsOptional() externalLink?: string; - - @ApiPropertyOptional() - @IsString() - @IsOptional() - roomId?: string; } diff --git a/libs/dal/src/repositories/integration/integration.schema.ts b/libs/dal/src/repositories/integration/integration.schema.ts index f2fbfa672a7..492956caa67 100644 --- a/libs/dal/src/repositories/integration/integration.schema.ts +++ b/libs/dal/src/repositories/integration/integration.schema.ts @@ -58,7 +58,6 @@ const integrationSchema = new Schema( imageUrl: Schema.Types.String, state: Schema.Types.String, externalLink: Schema.Types.String, - roomId: Schema.Types.String, }, active: { type: Schema.Types.Boolean, diff --git a/libs/shared/src/consts/providers/credentials/provider-credentials.ts b/libs/shared/src/consts/providers/credentials/provider-credentials.ts index 9dcf4a3ca46..224c4c36405 100644 --- a/libs/shared/src/consts/providers/credentials/provider-credentials.ts +++ b/libs/shared/src/consts/providers/credentials/provider-credentials.ts @@ -1035,11 +1035,4 @@ export const rocketChatConfig: IConfigCredentials[] = [ type: 'text', required: true, }, - { - key: CredentialsKeyEnum.roomId, - displayName: 'Room Id', - description: 'Your Room ID', - type: 'text', - required: true, - }, ]; diff --git a/libs/shared/src/consts/providers/provider.enum.ts b/libs/shared/src/consts/providers/provider.enum.ts index 0d6b0b69cce..88f16f5f037 100644 --- a/libs/shared/src/consts/providers/provider.enum.ts +++ b/libs/shared/src/consts/providers/provider.enum.ts @@ -43,7 +43,6 @@ export enum CredentialsKeyEnum { imageUrl = 'imageUrl', state = 'state', externalLink = 'externalLink', - roomId = 'roomId', } export enum EmailProviderIdEnum { diff --git a/libs/shared/src/entities/integration/credential.interface.ts b/libs/shared/src/entities/integration/credential.interface.ts index d882aee3a69..43461059350 100644 --- a/libs/shared/src/entities/integration/credential.interface.ts +++ b/libs/shared/src/entities/integration/credential.interface.ts @@ -41,5 +41,4 @@ export interface ICredentials { imageUrl?: string; state?: string; externalLink?: string; - roomId?: string; } diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts index bf05f661c0c..e8dc40bd376 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -16,28 +16,28 @@ export class RocketChatChatProvider implements IChatProvider { token?: string; user?: string; idPath?: string; - roomId?: string; } ) {} async sendMessage( options: IChatOptions ): Promise { + const roomId = options.channel; let payload = { message: { - rid: this.config.roomId, + rid: roomId, msg: options.content, }, }; try { // take whatever json payload client enters (this is for optional params) payload = JSON.parse(options.content); - payload.message.rid = this.config.roomId; + payload.message.rid = roomId; } catch (err) {} const headers = { 'x-auth-token': this.config.token, - 'x-user-id': this.config.idPath, + 'x-user-id': this.config.user, 'Content-Type': 'application/json', }; const baseURL = `${options.webhookUrl.toString()}/api/v1/chat.sendMessage`; From cf6cd337de132eb433a10dd158776aee68ba9cc5 Mon Sep 17 00:00:00 2001 From: varsubham Date: Tue, 26 Dec 2023 21:25:47 +0530 Subject: [PATCH 03/13] feat(provider): remove json payload --- providers/rocket-chat/src/lib/rocket-chat.provider.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts index e8dc40bd376..841cd9c39be 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -23,18 +23,12 @@ export class RocketChatChatProvider implements IChatProvider { options: IChatOptions ): Promise { const roomId = options.channel; - let payload = { + const payload = { message: { rid: roomId, msg: options.content, }, }; - try { - // take whatever json payload client enters (this is for optional params) - payload = JSON.parse(options.content); - payload.message.rid = roomId; - } catch (err) {} - const headers = { 'x-auth-token': this.config.token, 'x-user-id': this.config.user, From 393d8bef21d21abfbd339bac639b3ac7cd69b862 Mon Sep 17 00:00:00 2001 From: varsubham Date: Fri, 29 Dec 2023 13:18:44 +0530 Subject: [PATCH 04/13] feat(provider): remove id-path config --- providers/rocket-chat/src/lib/rocket-chat.provider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts index 841cd9c39be..11c5501ddab 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -15,7 +15,6 @@ export class RocketChatChatProvider implements IChatProvider { private config: { token?: string; user?: string; - idPath?: string; } ) {} From 1f4f22731a011334742fb7acd7c3f8d44d1ac02c Mon Sep 17 00:00:00 2001 From: varsubham Date: Fri, 29 Dec 2023 13:45:50 +0530 Subject: [PATCH 05/13] feat(provider): make config non-nullable --- .../src/factories/chat/handlers/rocket-chat.handler.ts | 6 +++++- providers/rocket-chat/src/lib/rocket-chat.provider.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts index 881b892203f..2a0a1ddcb4d 100644 --- a/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts +++ b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts @@ -9,6 +9,10 @@ export class RocketChatChatHandler extends BaseChatHandler { } buildProvider(credentials: ICredentials) { - this.provider = new RocketChatChatProvider(credentials); + const config: { token: string; user: string } = { + token: credentials.token as string, + user: credentials.user as string, + }; + this.provider = new RocketChatChatProvider(config); } } diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts index 11c5501ddab..02589116eaf 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -13,8 +13,8 @@ export class RocketChatChatProvider implements IChatProvider { constructor( private config: { - token?: string; - user?: string; + token: string; + user: string; } ) {} From a74178de7e7142b791b5523b8997417496f39ce9 Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 13:35:40 +0530 Subject: [PATCH 06/13] feat(provider): add axios module-name-mapper --- providers/rocket-chat/jest.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/rocket-chat/jest.config.js b/providers/rocket-chat/jest.config.js index e86e13bab91..61faa20934a 100644 --- a/providers/rocket-chat/jest.config.js +++ b/providers/rocket-chat/jest.config.js @@ -2,4 +2,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + moduleNameMapper: { + axios: 'axios/dist/node/axios.cjs', + }, }; From c44a57fa973ccbb6d50a52f1f853b97683b2775e Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 14:01:45 +0530 Subject: [PATCH 07/13] feat(provider): update name --- .../application-generic/src/factories/chat/chat.factory.ts | 4 ++-- .../src/factories/chat/handlers/rocket-chat.handler.ts | 6 +++--- providers/rocket-chat/src/lib/rocket-chat.provider.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/application-generic/src/factories/chat/chat.factory.ts b/packages/application-generic/src/factories/chat/chat.factory.ts index 45149e4e6c2..ca365353e51 100644 --- a/packages/application-generic/src/factories/chat/chat.factory.ts +++ b/packages/application-generic/src/factories/chat/chat.factory.ts @@ -8,7 +8,7 @@ import { GrafanaOnCallHandler } from './handlers/grafana-on-call.handler'; import { RyverHandler } from './handlers/ryver.handler'; import { ZulipHandler } from './handlers/zulip.handler'; import { GetstreamChatHandler } from './handlers/getstream.handler'; -import { RocketChatChatHandler } from './handlers/rocket-chat.handler'; +import { RocketChatHandler } from './handlers/rocket-chat.handler'; export class ChatFactory implements IChatFactory { handlers: IChatHandler[] = [ @@ -20,7 +20,7 @@ export class ChatFactory implements IChatFactory { new ZulipHandler(), new GrafanaOnCallHandler(), new GetstreamChatHandler(), - new RocketChatChatHandler(), + new RocketChatHandler(), ]; getHandler(integration: IntegrationEntity) { diff --git a/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts index 2a0a1ddcb4d..e31b47aee5b 100644 --- a/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts +++ b/packages/application-generic/src/factories/chat/handlers/rocket-chat.handler.ts @@ -1,9 +1,9 @@ import { ICredentials, ChatProviderIdEnum } from '@novu/shared'; import { ChannelTypeEnum } from '@novu/stateless'; import { BaseChatHandler } from './base.handler'; -import { RocketChatChatProvider } from '@novu/rocket-chat'; +import { RocketChatProvider } from '@novu/rocket-chat'; -export class RocketChatChatHandler extends BaseChatHandler { +export class RocketChatHandler extends BaseChatHandler { constructor() { super(ChatProviderIdEnum.RocketChat, ChannelTypeEnum.CHAT); } @@ -13,6 +13,6 @@ export class RocketChatChatHandler extends BaseChatHandler { token: credentials.token as string, user: credentials.user as string, }; - this.provider = new RocketChatChatProvider(config); + this.provider = new RocketChatProvider(config); } } diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.ts index 02589116eaf..0ef276e348c 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.ts @@ -6,7 +6,7 @@ import { } from '@novu/stateless'; import axios from 'axios'; -export class RocketChatChatProvider implements IChatProvider { +export class RocketChatProvider implements IChatProvider { id = 'rocket-chat'; channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT; private axiosInstance = axios.create(); From bedf0701116c67c1adaa8dfa2fe3d763e89fdb13 Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 14:41:28 +0530 Subject: [PATCH 08/13] feat(provider): add logo --- apps/web/public/static/images/providers/dark/rocketchat.svg | 6 ++++++ .../static/images/providers/dark/square/rocketchat.svg | 6 ++++++ .../web/public/static/images/providers/light/rocketchat.svg | 6 ++++++ .../static/images/providers/light/square/rocketchat.svg | 6 ++++++ libs/shared/src/consts/providers/channels/chat.ts | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 apps/web/public/static/images/providers/dark/rocketchat.svg create mode 100644 apps/web/public/static/images/providers/dark/square/rocketchat.svg create mode 100644 apps/web/public/static/images/providers/light/rocketchat.svg create mode 100644 apps/web/public/static/images/providers/light/square/rocketchat.svg diff --git a/apps/web/public/static/images/providers/dark/rocketchat.svg b/apps/web/public/static/images/providers/dark/rocketchat.svg new file mode 100644 index 00000000000..8c1fd745bb9 --- /dev/null +++ b/apps/web/public/static/images/providers/dark/rocketchat.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/apps/web/public/static/images/providers/dark/square/rocketchat.svg b/apps/web/public/static/images/providers/dark/square/rocketchat.svg new file mode 100644 index 00000000000..8c1fd745bb9 --- /dev/null +++ b/apps/web/public/static/images/providers/dark/square/rocketchat.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/apps/web/public/static/images/providers/light/rocketchat.svg b/apps/web/public/static/images/providers/light/rocketchat.svg new file mode 100644 index 00000000000..8c1fd745bb9 --- /dev/null +++ b/apps/web/public/static/images/providers/light/rocketchat.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/apps/web/public/static/images/providers/light/square/rocketchat.svg b/apps/web/public/static/images/providers/light/square/rocketchat.svg new file mode 100644 index 00000000000..8c1fd745bb9 --- /dev/null +++ b/apps/web/public/static/images/providers/light/square/rocketchat.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/libs/shared/src/consts/providers/channels/chat.ts b/libs/shared/src/consts/providers/channels/chat.ts index b72e9eb5aa6..c8f4f6388d3 100644 --- a/libs/shared/src/consts/providers/channels/chat.ts +++ b/libs/shared/src/consts/providers/channels/chat.ts @@ -76,6 +76,6 @@ export const chatProviders: IProviderConfig[] = [ channel: ChannelTypeEnum.CHAT, credentials: rocketChatConfig, docReference: 'https://developer.rocket.chat/reference/api/rest-api/endpoints', - logoFileName: { light: 'zulip.svg', dark: 'zulip.svg' }, + logoFileName: { light: 'rocketchat.svg', dark: 'rocketchat.svg' }, }, ]; From 23c66e76b64c5f5d1436578fb6f232ee7a5d3c09 Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 14:49:49 +0530 Subject: [PATCH 09/13] feat(provider): add test case --- .../src/lib/rocket-chat.provider.spec.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts b/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts index bbb08d058e5..d861f99f532 100644 --- a/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts +++ b/providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts @@ -1,3 +1,29 @@ -import { RocketChatChatProvider } from './rocket-chat.provider'; +import { RocketChatProvider } from './rocket-chat.provider'; -test('should trigger rocket-chat library correctly', async () => {}); +test('should trigger rocket-chat library correctly', async () => { + const mockConfig = { + user: '', + token: '', + }; + const provider = new RocketChatProvider(mockConfig); + + const spy = jest + .spyOn(provider, 'sendMessage') + .mockImplementation(async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; + }); + + await provider.sendMessage({ + webhookUrl: '', + channel: '', + content: '', + }); + + expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith({ + webhookUrl: '', + channel: '', + content: '', + }); +}); From 87c20494502a0f1f0da495b21cd0c4ad9452308b Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 15:06:32 +0530 Subject: [PATCH 10/13] feat(provider): bump version --- packages/application-generic/package.json | 2 +- pnpm-lock.yaml | 2 +- providers/rocket-chat/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/application-generic/package.json b/packages/application-generic/package.json index 50222a0c296..57556ffc82b 100644 --- a/packages/application-generic/package.json +++ b/packages/application-generic/package.json @@ -113,7 +113,7 @@ "@novu/twilio": "^0.22.0", "@novu/zulip": "^0.22.0", "@novu/nexmo": "^0.22.0", - "@novu/rocket-chat": "^0.16.3", + "@novu/rocket-chat": "^0.22.0", "@sentry/node": "^7.12.1", "analytics-node": "^6.2.0", "axios": "^1.6.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86096ec727d..e6aff7d904b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2598,7 +2598,7 @@ importers: specifier: ^0.22.0 version: link:../../providers/resend '@novu/rocket-chat': - specifier: ^0.16.3 + specifier: ^0.22.0 version: link:../../providers/rocket-chat '@novu/ryver': specifier: ^0.22.0 diff --git a/providers/rocket-chat/package.json b/providers/rocket-chat/package.json index 396a0e2e92e..7d2b8fab745 100644 --- a/providers/rocket-chat/package.json +++ b/providers/rocket-chat/package.json @@ -1,6 +1,6 @@ { "name": "@novu/rocket-chat", - "version": "0.16.3", + "version": "0.22.0", "description": "A rocket-chat wrapper for novu", "main": "build/main/index.js", "typings": "build/main/index.d.ts", From 50be98aa7c773dfc151a1853baab0a5bbb600d74 Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 15:11:35 +0530 Subject: [PATCH 11/13] feat(provider): add readme --- providers/rocket-chat/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/providers/rocket-chat/README.md b/providers/rocket-chat/README.md index de03087d85a..ea2bbe8587b 100644 --- a/providers/rocket-chat/README.md +++ b/providers/rocket-chat/README.md @@ -5,5 +5,10 @@ A RocketChat chat provider library for [@novu/node](https://github.com/novuhq/no ## Usage ```javascript - FILL IN THE INITIALIZATION USAGE +import { RocketChatProvider } from '@novu/rocket-chat'; + +const provider = new RocketChatProvider({ + user: process.env.ROCKET_CHAT_USER_ID, + token: process.env.ROCKET_CHAT_TOKEN, +}); ``` From 05d75281a270efeef9035af3d3307713135f5426 Mon Sep 17 00:00:00 2001 From: varsubham Date: Sat, 30 Dec 2023 22:02:06 +0530 Subject: [PATCH 12/13] feat(provider): rename logo --- .../images/providers/dark/{rocketchat.svg => rocket-chat.svg} | 0 .../providers/dark/square/{rocketchat.svg => rocket-chat.svg} | 0 .../images/providers/light/{rocketchat.svg => rocket-chat.svg} | 0 .../providers/light/square/{rocketchat.svg => rocket-chat.svg} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename apps/web/public/static/images/providers/dark/{rocketchat.svg => rocket-chat.svg} (100%) rename apps/web/public/static/images/providers/dark/square/{rocketchat.svg => rocket-chat.svg} (100%) rename apps/web/public/static/images/providers/light/{rocketchat.svg => rocket-chat.svg} (100%) rename apps/web/public/static/images/providers/light/square/{rocketchat.svg => rocket-chat.svg} (100%) diff --git a/apps/web/public/static/images/providers/dark/rocketchat.svg b/apps/web/public/static/images/providers/dark/rocket-chat.svg similarity index 100% rename from apps/web/public/static/images/providers/dark/rocketchat.svg rename to apps/web/public/static/images/providers/dark/rocket-chat.svg diff --git a/apps/web/public/static/images/providers/dark/square/rocketchat.svg b/apps/web/public/static/images/providers/dark/square/rocket-chat.svg similarity index 100% rename from apps/web/public/static/images/providers/dark/square/rocketchat.svg rename to apps/web/public/static/images/providers/dark/square/rocket-chat.svg diff --git a/apps/web/public/static/images/providers/light/rocketchat.svg b/apps/web/public/static/images/providers/light/rocket-chat.svg similarity index 100% rename from apps/web/public/static/images/providers/light/rocketchat.svg rename to apps/web/public/static/images/providers/light/rocket-chat.svg diff --git a/apps/web/public/static/images/providers/light/square/rocketchat.svg b/apps/web/public/static/images/providers/light/square/rocket-chat.svg similarity index 100% rename from apps/web/public/static/images/providers/light/square/rocketchat.svg rename to apps/web/public/static/images/providers/light/square/rocket-chat.svg From 549213825680fc8c28a256725a565bbd543423cd Mon Sep 17 00:00:00 2001 From: varsubham Date: Fri, 5 Jan 2024 19:25:06 +0530 Subject: [PATCH 13/13] feat(provider): fix typo --- libs/shared/src/consts/providers/channels/chat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/shared/src/consts/providers/channels/chat.ts b/libs/shared/src/consts/providers/channels/chat.ts index c8f4f6388d3..9d354dd6536 100644 --- a/libs/shared/src/consts/providers/channels/chat.ts +++ b/libs/shared/src/consts/providers/channels/chat.ts @@ -76,6 +76,6 @@ export const chatProviders: IProviderConfig[] = [ channel: ChannelTypeEnum.CHAT, credentials: rocketChatConfig, docReference: 'https://developer.rocket.chat/reference/api/rest-api/endpoints', - logoFileName: { light: 'rocketchat.svg', dark: 'rocketchat.svg' }, + logoFileName: { light: 'rocket-chat.svg', dark: 'rocket-chat.svg' }, }, ];