Generic Interface over Function
export interface MessageTranslator<A, B> {
to(from: A): B;
}export class Processor {
private detectIntentRequestTranslator: MessageTranslator<DetectIntentRequestDF, DetectIntentRequest>;
private detectIntentResponseTranslator: MessageTranslator<DetectIntentResponse, DetectIntentResponseDF>;
constructor() {
this.detectIntentRequestTranslator = new DetectIntentRequestTranslator();
this.detectIntentResponseTranslator = new DetectIntentResponseTranslator();
}
doSomething(): number {
const request: DetectIntentRequest = this.detectIntentRequestTranslator.to(call.request);
const resposne: DetectIntentResponse = this.detectIntentResponseTranslator.to(call.response);
// do something
return 1;
}
}Last updated