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

feat(provider): add clicksend sms provider #4465

Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@
"autodocs",
"stackalt",
"mediumdark",
"Docgen"
"Docgen",
"Clicksend",
"clicksend"
],
"flagWords": [],
"patterns": [
Expand Down
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.
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.
9 changes: 9 additions & 0 deletions libs/shared/src/consts/providers/channels/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
termiiConfig,
africasTalkingConfig,
sendchampConfig,
clickSendConfig,
} from '../credentials';
import { SmsProviderIdEnum } from '../provider.enum';

Expand Down Expand Up @@ -179,4 +180,12 @@ export const smsProviders: IProviderConfig[] = [
docReference: 'https://docs.novu.co/channels-and-providers/sms/sendchamp',
logoFileName: { light: 'sendchamp.svg', dark: 'sendchamp.svg' },
},
{
id: SmsProviderIdEnum.Clicksend,
displayName: 'Clicksend',
channel: ChannelTypeEnum.SMS,
credentials: clickSendConfig,
docReference: 'https://developers.clicksend.com/docs/rest/v3/?javascript--nodejs#ClickSend-v3-API-SMS',
logoFileName: { light: 'clicksend.png', dark: 'clicksend.png' },
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,24 @@ export const sendchampConfig: IConfigCredentials[] = [
},
...smsConfigBase,
];

export const clickSendConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.ApiKey,
displayName: 'API Key',
type: 'text',
required: true,
},
{
key: CredentialsKeyEnum.User,
displayName: 'Username',
type: 'text',
required: true,
},
{
key: CredentialsKeyEnum.From,
displayName: 'From',
type: 'string',
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 @@ -71,6 +71,7 @@ export enum SmsProviderIdEnum {
AfricasTalking = 'africas-talking',
Novu = 'novu-sms',
Sendchamp = 'sendchamp',
Clicksend = 'clicksend',
}

export enum ChatProviderIdEnum {
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 @@ -51,6 +51,7 @@
"@novu/apns": "^0.20.0-alpha.0",
"@novu/burst-sms": "^0.20.0-alpha.0",
"@novu/clickatell": "^0.20.0-alpha.0",
"@novu/clicksend": "^0.20.0-alpha.0",
"@novu/dal": "^0.20.0-alpha.0",
"@novu/discord": "^0.20.0-alpha.0",
"@novu/email-webhook": "^0.20.0-alpha.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ChannelTypeEnum, ICredentials } from '@novu/shared';
import { ClicksendSmsProvider } from '@novu/clicksend';
import { BaseSmsHandler } from './base.handler';

export class ClicksendSmsHandler extends BaseSmsHandler {
constructor() {
super('clicksend', ChannelTypeEnum.SMS);
}

buildProvider(credentials: ICredentials) {
if (!credentials.user || !credentials.apiKey || !credentials.from) {
throw Error('Invalid credentials');
}

const config = {
apiKey: credentials.apiKey,
username: credentials.user,
from: credentials.from,
};

this.provider = new ClicksendSmsProvider(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './sms-central.handler';
export * from './africas-talking.handler';
export * from './sendchamp.handler';
export * from './novu.handler';
export * from './clicksend.handler';
2 changes: 2 additions & 0 deletions packages/application-generic/src/factories/sms/sms.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SmsCentralHandler,
AfricasTalkingSmsHandler,
SendchampSmsHandler,
ClicksendSmsHandler,
NovuSmsHandler,
} from './handlers';

Expand All @@ -40,6 +41,7 @@ export class SmsFactory implements ISmsFactory {
new SmsCentralHandler(),
new AfricasTalkingSmsHandler(),
new SendchampSmsHandler(),
new ClicksendSmsHandler(),
new NovuSmsHandler(),
];

Expand Down
35 changes: 35 additions & 0 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/clicksend/.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/clicksend/.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/clicksend/.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/clicksend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Novu Clicksend Provider

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

## Usage

```javascript
import { ClicksendSmsProvider } from '@novu/clicksend'

const provider = new ClicksendSmsProvider({
apiKey: process.env.CLICKSEND_API_KEY,
username: process.env.CLICKSEND_USERNAME,
from: process.env.CLICKSEND_FROM
```
5 changes: 5 additions & 0 deletions providers/clicksend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
83 changes: 83 additions & 0 deletions providers/clicksend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "@novu/clicksend",
"version": "0.20.0-alpha.0",
"description": "A clicksend 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"
},
"engines": {
"node": ">=13.0.0 <17.0.0",
"pnpm": "^7.26.0"
},
"dependencies": {
"@novu/stateless": "0.20.0-alpha.0",
"axios": "^1.5.1",
"clicksend": "^5.0.37"
},
"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/clicksend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/clicksend.provider';
35 changes: 35 additions & 0 deletions providers/clicksend/src/lib/clicksend.provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ClicksendSmsProvider } from './clicksend.provider';

const mockConfig = {
apiKey: '<api-key>',
username: 'test-username',
from: 'clicksend',
};

const mockNovuMessage = {
to: '+61411111111',
content: 'sms content',
};

test('should trigger clicksend library correctly', async () => {
const smsProvider = new ClicksendSmsProvider(mockConfig);

const spy = jest
.spyOn(smsProvider, 'sendMessage')
.mockImplementation(async () => {
return {
id: 'BF7AD270-0DE2-418B-B606-71D527D9C1AE',
date: new Date().toISOString(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
});

await smsProvider.sendMessage(mockNovuMessage);

expect(spy).toHaveBeenCalled();

expect(spy).toHaveBeenCalledWith({
to: '+61411111111',
content: 'sms content',
});
});
43 changes: 43 additions & 0 deletions providers/clicksend/src/lib/clicksend.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
ChannelTypeEnum,
ISendMessageSuccessResponse,
ISmsOptions,
ISmsProvider,
} from '@novu/stateless';

// eslint-disable-next-line import/extensions
const api = require('clicksend/api');

export class ClicksendSmsProvider implements ISmsProvider {
id = 'clicksend';
channelType = ChannelTypeEnum.SMS as ChannelTypeEnum.SMS;

constructor(
private config: {
apiKey: string;
username: string;
from?: string;
}
) {}

async sendMessage(
options: ISmsOptions
): Promise<ISendMessageSuccessResponse> {
const smsApi = new api.SMSApi(this.config.username, this.config.apiKey);

const smsMessage = new api.SmsMessage();
smsMessage.from = this.config.from;
smsMessage.to = options.to;
smsMessage.body = options.content;

const smsCollection = new api.SmsMessageCollection();
smsCollection.messages = [smsMessage];

const response = await smsApi.smsSendPost(smsCollection);

return {
id: response.body.data.messages[0].message_id,
date: response.body.data.messages[0].date,
};
}
}
10 changes: 10 additions & 0 deletions providers/clicksend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "build/main",
"rootDir": "src",
"types": ["node", "jest"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules/**"]
}
Loading
Loading