Skip to content
Open
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
10 changes: 10 additions & 0 deletions apps/dashboard/public/images/providers/light/square/messente.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './isendpro-sms.handler';
export * from './kannel.handler';
export * from './maqsam.handler';
export * from './messagebird.handler';
export * from './messente.handler';
export * from './mobishastra.handler';
export * from './nexmo.handler';
export * from './novu.handler';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MessenteSmsProvider } from '@novu/providers';
import { ChannelTypeEnum, ICredentials, SmsProviderIdEnum } from '@novu/shared';
import { BaseSmsHandler } from './base.handler';

export class MessenteSmsHandler extends BaseSmsHandler {
constructor() {
super(SmsProviderIdEnum.Messente, ChannelTypeEnum.SMS);
}
buildProvider(credentials: ICredentials) {
this.provider = new MessenteSmsProvider({
username: credentials.user,
password: credentials.password,
});
}
}
2 changes: 2 additions & 0 deletions libs/application-generic/src/factories/sms/sms.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
KannelSmsHandler,
MaqsamHandler,
MessageBirdHandler,
MessenteSmsHandler,
MobishastraHandler,
NexmoHandler,
NovuSmsHandler,
Expand Down Expand Up @@ -81,6 +82,7 @@ export class SmsFactory implements ISmsFactory {
new BulkSmsHandler(),
new ISendProSmsHandler(),
new CmTelecomHandler(),
new MessenteSmsHandler(),
];

getHandler(integration: Pick<IntegrationEntity, 'credentials' | 'channel' | 'providerId' | 'configurations'>) {
Expand Down
1 change: 1 addition & 0 deletions packages/framework/src/schemas/providers/sms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export const smsProviderSchemas = {
imedia: genericProviderSchemas,
sinch: genericProviderSchemas,
'isendpro-sms': genericProviderSchemas,
messente: genericProviderSchemas,
} as const satisfies Record<SmsProviderIdEnum, { output: JsonSchema }>;
1 change: 1 addition & 0 deletions packages/framework/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export enum SmsProviderIdEnum {
IMedia = 'imedia',
Sinch = 'sinch',
ISendProSms = 'isendpro-sms',
Messente = 'messente',
}

export enum ChatProviderIdEnum {
Expand Down
1 change: 1 addition & 0 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"qs": "^6.11.0",
"resend": "^6.0.3",
"sms77-client": "^2.14.0",
"messente_api": "^2.5.0",
"svix": "^1.29.0",
"telnyx": "^1.23.0",
"twilio": "^4.19.3",
Expand Down
1 change: 1 addition & 0 deletions packages/providers/src/lib/sms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './isendpro-sms/isendpro-sms.provider';
export * from './kannel/kannel.provider';
export * from './maqsam/maqsam.provider';
export * from './messagebird/messagebird.provider';
export * from './messente/messente.provider';
export * from './mobishastra/mobishastra.provider';
export * from './nexmo/nexmo.provider';
export * from './plivo/plivo.provider';
Expand Down
96 changes: 96 additions & 0 deletions packages/providers/src/lib/sms/messente/messente.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as messente from 'messente_api';

import { SmsProviderIdEnum } from "@novu/shared";
import {
ChannelTypeEnum,
ISendMessageSuccessResponse,
ISmsOptions,
ISmsProvider,
} from "@novu/stateless";
import { BaseProvider, CasingEnum } from "../../../base.provider";
import { WithPassthrough } from "../../../utils/types";

type MessageChannel = 'sms' | 'viber' | 'whatsapp';

interface MessagePayload {
readonly channel: MessageChannel;
readonly text: string;
readonly sender: string;
}

interface SendMessageRequest {
readonly to: string;
readonly messages: MessagePayload[];
}

interface MessageResponse {
readonly channel: MessageChannel;
readonly message_id: string;
readonly sender: string;
}

interface SendMessageResponse {
readonly to: string;
readonly messages: MessageResponse[];
}

export class MessenteSmsProvider extends BaseProvider implements ISmsProvider {
id = SmsProviderIdEnum.Messente;
channelType = ChannelTypeEnum.SMS as ChannelTypeEnum.SMS;
protected casing: CasingEnum = CasingEnum.CAMEL_CASE;
readonly #messente: messente.OmnimessageApi;

constructor(private readonly config: {
readonly username: string;
readonly password: string;
}) {
super();

const { instance } = messente.ApiClient;
const basicAuth = instance.authentications["basicAuth"];

basicAuth.username = config.username;
basicAuth.password = config.password;

this.#messente = new messente.OmnimessageApi();
Comment thread
roman-supy-io marked this conversation as resolved.
}

async sendMessage(
options: ISmsOptions,
bridgeProviderData: WithPassthrough<Record<string, unknown>> = {},
): Promise<ISendMessageSuccessResponse> {
const params = this.transform<SendMessageRequest>(bridgeProviderData, {
to: options.to,
messages: [
{
channel: 'sms',
text: options.content,
sender: options.from,
},
],
}).body;

const response = await new Promise<SendMessageResponse>((resolve, reject) => {
this.#messente.sendOmnimessage(
{
to: params.to,
messages: params.messages,
},
(error: Error | null, data: SendMessageResponse) => {
if (error) {
reject(error);
} else {
resolve(data);
}
},
);
});

const [{ message_id }] = response.messages;
Comment thread
roman-supy-io marked this conversation as resolved.

return {
id: message_id,
date: new Date().toISOString(),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { expect, test, vi } from 'vitest';
import { MessenteSmsProvider } from './messente.provider';

const sendOmnimessageMock = vi.hoisted(() => vi.fn());

vi.mock('messente_api', () => ({
ApiClient: {
instance: {
authentications: {
basicAuth: { username: '', password: '' },
},
},
},
OmnimessageApi: vi.fn(() => ({
sendOmnimessage: sendOmnimessageMock,
})),
}));

test('should trigger messente library correctly', async () => {
sendOmnimessageMock.mockImplementation((_params, callback) => {
callback(null, {
to: '+176543',
messages: [{ channel: 'sms', message_id: 'test-message-id', sender: '+112345' }],
});
});

const provider = new MessenteSmsProvider({
username: 'test-username',
password: 'test-password',
});

const response = await provider.sendMessage({
to: '+176543',
content: 'SMS Content',
from: '+112345',
});

expect(sendOmnimessageMock).toHaveBeenCalledWith(
{
to: '+176543',
messages: [{ channel: 'sms', text: 'SMS Content', sender: '+112345' }],
},
expect.any(Function)
);
expect(response.id).toBe('test-message-id');
});

test('should trigger messente library correctly with _passthrough', async () => {
sendOmnimessageMock.mockImplementation((_params, callback) => {
callback(null, {
to: '+299999',
messages: [{ channel: 'sms', message_id: 'passthrough-message-id', sender: '+112345' }],
});
});

const provider = new MessenteSmsProvider({
username: 'test-username',
password: 'test-password',
});

const response = await provider.sendMessage(
{
to: '+176543',
content: 'SMS Content',
from: '+112345',
},
{
_passthrough: {
body: {
to: '+299999',
},
},
}
);

expect(sendOmnimessageMock).toHaveBeenCalledWith(
{
to: '+299999',
messages: [{ channel: 'sms', text: 'SMS Content', sender: '+112345' }],
},
expect.any(Function)
);
expect(response.id).toBe('passthrough-message-id');
});
9 changes: 9 additions & 0 deletions packages/shared/src/consts/providers/channels/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
kannelConfig,
maqsamConfig,
messagebirdConfig,
messenteConfig,
mobishastraConfig,
nexmoConfig,
plivoConfig,
Expand Down Expand Up @@ -350,4 +351,12 @@ export const smsProviders: IProviderConfig[] = [
docReference: 'https://developers.cm.com/messaging/docs/sms',
logoFileName: { light: 'cm-telecom.svg', dark: 'cm-telecom.svg' },
},
{
id: SmsProviderIdEnum.Messente,
displayName: 'Messente',
channel: ChannelTypeEnum.SMS,
credentials: messenteConfig,
docReference: 'https://messente.com/docs',
logoFileName: { light: 'messente.svg', dark: 'messente.svg' },
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -1446,3 +1446,23 @@ export const cmTelecomConfig: IConfigCredential[] = [
},
...smsConfigBase,
];

export const messenteConfig: IConfigCredential[] = [
{
key: CredentialsKeyEnum.User,
displayName: 'Username',
description: 'Your Messente API username',
links: [{ text: 'Check Messente documentation', url: 'https://dashboard.messente.com/api-settings' }],
type: 'string',
required: true,
},
{
key: CredentialsKeyEnum.Password,
displayName: 'Password',
description: 'Your Messente API password',
links: [{ text: 'Check Messente documentation', url: 'https://dashboard.messente.com/api-settings' }],
type: 'string',
required: true,
},
...smsConfigBase,
];
1 change: 1 addition & 0 deletions packages/shared/src/types/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export enum SmsProviderIdEnum {
Sinch = 'sinch',
ISendProSms = 'isendpro-sms',
CmTelecom = 'cm-telecom',
Messente = 'messente',
}

export enum ChatProviderIdEnum {
Expand Down
Loading
Loading