notifme/notifme-sdk

View on GitHub
src/providers/voice/index.js

Summary

Maintainability
A
3 hrs
Test Coverage
A
100%
/* @flow */
import VoiceLoggerProvider from '../logger'
import VoiceNotificationCatcherProvider from './notificationCatcher'
import VoiceTwilioProvider from './twilio'
// Types
import type { VoiceRequestType } from '../../models/notification-request'

export interface VoiceProviderType {
  id: string,
  send(request: VoiceRequestType): Promise<string>
}

export default function factory ({ type, ...config }: Object): VoiceProviderType {
  switch (type) {
    // Development
    case 'logger':
      return new VoiceLoggerProvider(config, 'voice')

    case 'notificationcatcher':
      return new VoiceNotificationCatcherProvider('voice')

    // Custom
    case 'custom':
      return config

    // Providers
    case 'twilio':
      return new VoiceTwilioProvider(config)

    default:
      throw new Error(`Unknown voice provider "${type}".`)
  }
}