import Context from '../context/Context'; import { Action } from '../types'; import { RoutePredicate, route } from '../router'; import ViberContext from './ViberContext'; type Route = ( action: Action ) => { predicate: RoutePredicate; action: Action; }; type Viber = Route & { any: Route; message: Route; subscribed: Route; unsubscribed: Route; conversationStarted: Route; delivered: Route; seen: Route; failed: Route; }; const viber: Viber = (action: Action) => { return route((context: C) => context.platform === 'viber', action); }; viber.any = viber; function message(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.isMessage, action ); } viber.message = message; function subscribed(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.isSubscribed, action ); } viber.subscribed = subscribed; function unsubscribed(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.isUnsubscribed, action ); } viber.unsubscribed = unsubscribed; function conversationStarted( action: Action ) { return route( (context: C) => context.platform === 'viber' && context.event.isConversationStarted, action ); } viber.conversationStarted = conversationStarted; function delivered(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.delivered, action ); } viber.delivered = delivered; function seen(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.seen, action ); } viber.seen = seen; function failed(action: Action) { return route( (context: C) => context.platform === 'viber' && context.event.failed, action ); } viber.failed = failed; export default viber;