import Context from '../context/Context'; import { Action } from '../types'; import { RoutePredicate, route } from '../router'; import SlackContext from './SlackContext'; import { EventTypes, InteractionTypes } from './SlackTypes'; type Route = ( action: Action ) => { predicate: RoutePredicate; action: Action; }; type Slack = Route & { any: Route; message: Route; event: ( eventType: EventTypes | InteractionTypes, action: Action ) => { predicate: RoutePredicate; action: Action; }; command: ( commandText: string, action: Action ) => { predicate: RoutePredicate; action: Action; }; }; const slack: Slack = (action: Action) => { return route((context: C) => context.platform === 'slack', action); }; slack.any = slack; function message(action: Action) { return route( (context: C) => context.platform === 'slack' && context.event.isMessage, action ); } slack.message = message; function event( eventType: EventTypes | InteractionTypes, action: Action ) { return route( (context: C) => context.platform === 'slack' && context.event.rawEvent.type && (eventType === '*' || context.event.rawEvent.type === eventType), action ); } slack.event = event; function command( commandText: string, action: Action ) { return route( (context: C) => context.platform === 'slack' && context.event.command && (commandText === '*' || context.event.command === commandText), action ); } slack.command = command; export default slack;