-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(providers): add new messente sms connector #10685
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
Open
roman-supy-io
wants to merge
4
commits into
novuhq:next
Choose a base branch
from
supy-io:feat/messente-sms-connector
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
119a82b
feat(integrations): add new messente sms connector
roman-supy-io 65126a2
Merge branch 'next' into feat/messente-sms-connector
roman-supy-io 7ed76fd
Merge branch 'next' into feat/messente-sms-connector
roman-supy-io 3d9b6cf
Merge branch 'next' into feat/messente-sms-connector
roman-supy-io File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
libs/application-generic/src/factories/sms/handlers/messente.handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/providers/src/lib/sms/messente/messente.provider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| 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; | ||
|
roman-supy-io marked this conversation as resolved.
|
||
|
|
||
| return { | ||
| id: message_id, | ||
| date: new Date().toISOString(), | ||
| }; | ||
| } | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
packages/providers/src/lib/sms/messente/messente.test.provider.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.