Skip to content

Commit

Permalink
Merge pull request #5035 from varsubham/feat/rocket-chat
Browse files Browse the repository at this point in the history
feat(provider): add rocket.chat chat provider
  • Loading branch information
Cliftonz authored Jan 11, 2024
2 parents 4379864 + 829805e commit 7e5097b
Show file tree
Hide file tree
Showing 22 changed files with 346 additions and 10 deletions.
6 changes: 6 additions & 0 deletions apps/web/public/static/images/providers/dark/rocket-chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions apps/web/public/static/images/providers/light/rocket-chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion libs/shared/src/consts/providers/channels/chat.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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: 'rocket-chat.svg', dark: 'rocket-chat.svg' },
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,20 @@ 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,
},
];
1 change: 1 addition & 0 deletions libs/shared/src/consts/providers/provider.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export enum ChatProviderIdEnum {
Zulip = 'zulip',
GrafanaOnCall = 'grafana-on-call',
GetStream = 'getstream',
RocketChat = 'rocket-chat',
}

export enum PushProviderIdEnum {
Expand Down
1 change: 1 addition & 0 deletions packages/application-generic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"@novu/twilio": "^0.22.0",
"@novu/zulip": "^0.22.0",
"@novu/nexmo": "^0.22.0",
"@novu/rocket-chat": "^0.22.0",
"@sentry/node": "^7.12.1",
"@segment/analytics-node": "^1.1.4",
"axios": "^1.6.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { RocketChatHandler } from './handlers/rocket-chat.handler';

export class ChatFactory implements IChatFactory {
handlers: IChatHandler[] = [
Expand All @@ -19,6 +20,7 @@ export class ChatFactory implements IChatFactory {
new ZulipHandler(),
new GrafanaOnCallHandler(),
new GetstreamChatHandler(),
new RocketChatHandler(),
];

getHandler(integration: IntegrationEntity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ICredentials, ChatProviderIdEnum } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
import { BaseChatHandler } from './base.handler';
import { RocketChatProvider } from '@novu/rocket-chat';

export class RocketChatHandler extends BaseChatHandler {
constructor() {
super(ChatProviderIdEnum.RocketChat, ChannelTypeEnum.CHAT);
}

buildProvider(credentials: ICredentials) {
const config: { token: string; user: string } = {
token: credentials.token as string,
user: credentials.user as string,
};
this.provider = new RocketChatProvider(config);
}
}
73 changes: 64 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions providers/rocket-chat/.czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
3 changes: 3 additions & 0 deletions providers/rocket-chat/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
9 changes: 9 additions & 0 deletions providers/rocket-chat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/*
.nyc_output
build
node_modules
test
src/**.js
coverage
*.log
package-lock.json
14 changes: 14 additions & 0 deletions providers/rocket-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Novu RocketChat Provider

A RocketChat chat provider library for [@novu/node](https://github.com/novuhq/novu)

## Usage

```javascript
import { RocketChatProvider } from '@novu/rocket-chat';

const provider = new RocketChatProvider({
user: process.env.ROCKET_CHAT_USER_ID,
token: process.env.ROCKET_CHAT_TOKEN,
});
```
8 changes: 8 additions & 0 deletions providers/rocket-chat/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
axios: 'axios/dist/node/axios.cjs',
},
};
78 changes: 78 additions & 0 deletions providers/rocket-chat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@novu/rocket-chat",
"version": "0.22.0",
"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"
]
}
}
1 change: 1 addition & 0 deletions providers/rocket-chat/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/rocket-chat.provider';
29 changes: 29 additions & 0 deletions providers/rocket-chat/src/lib/rocket-chat.provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RocketChatProvider } from './rocket-chat.provider';

test('should trigger rocket-chat library correctly', async () => {
const mockConfig = {
user: '<your-user>',
token: '<your-auth-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: '<your-root-url>',
channel: '<your-channel>',
content: '<your-chat-message>',
});

expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith({
webhookUrl: '<your-root-url>',
channel: '<your-channel>',
content: '<your-chat-message>',
});
});
Loading

0 comments on commit 7e5097b

Please sign in to comment.