import Context from '../context/Context'; import { Action } from '../types'; import { RoutePredicate, route } from '../router'; import WhatsappContext from './WhatsappContext'; type Route = ( action: Action ) => { predicate: RoutePredicate; action: Action; }; type Whatsapp = Route & { any: Route; message: Route; media: Route; received: Route; sent: Route; delivered: Route; read: Route; }; const whatsapp: Whatsapp = ( action: Action ) => { return route((context: C) => context.platform === 'whatsapp', action); }; whatsapp.any = whatsapp; function message(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isMessage, action ); } whatsapp.message = message; function media(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isMedia, action ); } whatsapp.media = media; function received(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isReceived, action ); } whatsapp.received = received; function sent(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isSent, action ); } whatsapp.sent = sent; function delivered(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isDelivered, action ); } whatsapp.delivered = delivered; function read(action: Action) { return route( (context: C) => context.platform === 'whatsapp' && context.event.isRead, action ); } whatsapp.read = read; export default whatsapp;