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

Add whatsapp-business provider #4128

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
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/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ export const chatProviders: IProviderConfig[] = [
docReference: 'https://developers.mattermost.com/integrate/webhooks/incoming/',
logoFileName: { light: 'mattermost.svg', dark: 'mattermost.svg' },
},
{
id: ChatProviderIdEnum.WhatsApp,
displayName: 'WhatsApp Business',
channel: ChannelTypeEnum.CHAT,
betaVersion: true,
credentials: [] as IConfigCredentials[],
docReference: 'https://developers.facebook.com/docs/whatsapp',
logoFileName: { light: 'whatsApp.png', dark: 'whatsApp.png' },
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,25 @@ export const sendchampConfig: IConfigCredentials[] = [
},
...smsConfigBase,
];


export const whatsAppBusinessConfig: IConfigCredentials[] = [
{
key: CredentialsKeyEnum.ApiKey,
displayName: 'API Key',
type: 'string',
required: true,
},
{
key: CredentialsKeyEnum.ApplicationId,
displayName: 'ApplicationId',
type: 'string',
required: true,
},
{
key: CredentialsKeyEnum.ApiVersion,
displayName: 'Api Version',
type: 'string',
required: true,
},
];
2 changes: 2 additions & 0 deletions libs/shared/src/consts/providers/provider.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum CredentialsKeyEnum {
RedirectUrl = 'redirectUrl',
Hmac = 'hmac',
IpPoolName = 'ipPoolName',
ApiVersion = 'apiVersion',
}

export enum EmailProviderIdEnum {
Expand Down Expand Up @@ -79,6 +80,7 @@ export enum ChatProviderIdEnum {
Discord = 'discord',
MsTeams = 'msteams',
Mattermost = 'mattermost',
WhatsApp = 'whatsapp-business',
}

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 @@ -94,6 +94,7 @@
"@novu/termii": "^0.20.0-alpha.0",
"@novu/testing": "^0.20.0-alpha.0",
"@novu/twilio": "^0.20.0-alpha.0",
"@novu/whatsapp-business": "^0.20.0-alpha.0",
"@sentry/node": "^7.12.1",
"analytics-node": "^6.2.0",
"bullmq": "^3.10.2",
Expand Down
12 changes: 8 additions & 4 deletions packages/application-generic/src/factories/chat/chat.factory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { IChatFactory, IChatHandler } from './interfaces';
import { SlackHandler } from './handlers/slack.handler';
import { IntegrationEntity } from '@novu/dal';
import { DiscordHandler } from './handlers/discord.handler';
import { MSTeamsHandler } from './handlers/msteams.handler';
import { MattermostHandler } from './handlers/mattermost.handler';
import {
DiscordHandler,
MattermostHandler,
MSTeamsHandler,
SlackHandler,
WhatsappBusinessHandler,
} from './handlers';

export class ChatFactory implements IChatFactory {
handlers: IChatHandler[] = [
new SlackHandler(),
new DiscordHandler(),
new MSTeamsHandler(),
new MattermostHandler(),
new WhatsappBusinessHandler(),
];

getHandler(integration: IntegrationEntity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './discord.handler';
export * from './mattermost.handler';
export * from './msteams.handler';
export * from './slack.handler';
export * from './whatsapp-business.handler';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ICredentials } from '@novu/shared';
import { ChannelTypeEnum } from '@novu/stateless';
import { BaseChatHandler } from './base.handler';
import { WhatsappBusinessChatProvider } from '@novu/whatsapp-business';

export class WhatsappBusinessHandler extends BaseChatHandler {
constructor() {
super('whatsapp-business', ChannelTypeEnum.CHAT);
}

buildProvider(credentials: ICredentials) {
const config: {
apiKey: string;
apiVersion: string;
applicationId: string;
} = {
apiKey: credentials.apiKey,
apiVersion: credentials.apiVersion,
applicationId: credentials.applicationId,
};

this.provider = new WhatsappBusinessChatProvider(config);
}
}
79 changes: 67 additions & 12 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/whatsapp-business/.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/whatsapp-business/.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/whatsapp-business/.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
15 changes: 15 additions & 0 deletions providers/whatsapp-business/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Novu WhatsappBusiness Provider

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

## Usage

```javascript
import { WhatsappBusinessChatProvider } from '@novu/whatsapp-business';

const provider = new WhatsappBusinessChatProvider({
apiKey: process.env.API_KEY,
apiVersion: process.env.API_VERSION,
applicationId: process.env.APPLICATION_ID,
});
```
5 changes: 5 additions & 0 deletions providers/whatsapp-business/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',
};
Loading
Loading