Skip to content

Commit

Permalink
Add possibility to define custom channels
Browse files Browse the repository at this point in the history
  • Loading branch information
BDav24 committed Jan 2, 2019
1 parent 0587c7f commit a083ce6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
- [How to use](#how-to-use)
- [1. General options](#1-general-options)
- [2. Providers](#2-providers)
- [3. Send a notification](#3-send-a-notification)
- [4. In production](#4-in-production)
- [3. Custom channels](#3-custom-channels)
- [4. Send a notification](#4-send-a-notification)
- [5. In production](#5-in-production)
- [Contributing](#contributing)
- [Need help? Found a bug?](#need-help-found-a-bug)
- [Related Projects](#related-projects)
Expand Down Expand Up @@ -98,8 +99,9 @@ $ NOTIFME_CATCHER_OPTIONS=smtp://127.0.0.1:3025?ignoreTLS=true node your-script-

- [1. General options](#1-general-options)
- [2. Providers](#2-providers)
- [3. Send a notification](#3-send-a-notification)
- [4. In production](#4-in-production)
- [3. Custom channels](#3-custom-channels)
- [4. Send a notification](#4-send-a-notification)
- [5. In production](#5-in-production)

### 1. General options

Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* global $Keys */
import NotificationCatcherProvider from './providers/notificationCatcherProvider'
import Sender from './sender'
import dedupe from './util/dedupe'
import logger from './util/logger'
import providerFactory from './providers'
import strategyProvidersFactory from './strategies/providers'
Expand Down Expand Up @@ -36,7 +37,7 @@ export type NotificationRequestType = {
voice?: VoiceRequestType,
webpush?: WebpushRequestType,
slack?: SlackRequestType
// TODO?: other channels (slack, messenger, skype, telegram, kik, spark...)
// TODO?: other channels (messenger, skype, telegram, kik, spark...)
}

export type NotificationStatusType = {
Expand Down Expand Up @@ -90,7 +91,11 @@ export default class NotifmeSdk {
const providers = providerFactory(mergedOptions.channels)
const strategies = strategyProvidersFactory(mergedOptions.channels)

this.sender = new Sender([...(Object.keys(CHANNELS)), ...(Object.keys(providers))], providers, strategies)
this.sender = new Sender(
dedupe([...Object.keys(CHANNELS), ...Object.keys(providers)]),
providers,
strategies
)
}

mergeWithDefaultConfig ({ channels, ...rest }: OptionsType) {
Expand Down
3 changes: 1 addition & 2 deletions src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export default function factory (channels: ChannelOptionsType): ProvidersType {
case 'slack':
return slackFactory(config)

default: {
default:
return config
}
}
})

Expand Down
5 changes: 5 additions & 0 deletions src/util/dedupe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* @flow */

export default function dedupe (array: Array<any>): Array<any> {
return array.filter((element, position) => array.indexOf(element) === position)
}

0 comments on commit a083ce6

Please sign in to comment.