import * as express from "express" ; import { Listener } from "../listeners/listener" ; import { Looker } from "../looker" ; import { ReplyContext } from "../reply_context" ; export interface IChannel { id : string ; label : string ; } export abstract class Service { protected listeners ! : Array < typeof Listener > ; protected messageHandler ! : ( context : ReplyContext ) => void ; protected urlHandler ! : ( context : ReplyContext , url : string ) => void ; private runningListeners : Listener [ ] = [ ] ; public begin ( opts ) { this . listeners = opts . listeners ; this . messageHandler = opts . messageHandler ; this . urlHandler = opts . urlHandler ; this . start ( ) ; } public abstract usableChannels ( ) ; public abstract replyContextForChannelId ( id ) ; protected abstract start ( ) ; protected setWebserver ( expressWebserver ) { for ( const listener of this . listeners ) { const instance = new listener ( expressWebserver , this , Looker . all ) ; this . startListener ( instance ) ; } } protected startListener ( listener ) { listener . listen ( ) ; this . runningListeners . push ( listener ) ; console . log ( `Started ${ listener . constructor . name }` ) ; } }