From b331b39a7595178c1d8aab8905235ab51b890682 Mon Sep 17 00:00:00 2001 From: tenorok Date: Wed, 10 Jan 2018 10:44:30 +0300 Subject: [PATCH] Created getIntegration method. --- lib/core/Bot.d.ts | 1 + lib/core/Bot.js | 7 +++++++ src/core/Bot.ts | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/lib/core/Bot.d.ts b/lib/core/Bot.d.ts index 20c6510..e17b5c3 100644 --- a/lib/core/Bot.d.ts +++ b/lib/core/Bot.d.ts @@ -16,6 +16,7 @@ export declare class Bot { constructor(obj?: IOptions); getHTTPEndpoints(): string[]; getRouter(): express.Router | null; + getIntegration(name: string): any | null; use(instance: any, filter?: string | string[]): void; hear(pattern: string | boolean, messageTypes?: string | callbackType, cb?: callbackType): Observable; hears(patterns: string[], messageTypes?: string | callbackType, cb?: callbackType): Observable; diff --git a/lib/core/Bot.js b/lib/core/Bot.js index 3670516..0641672 100644 --- a/lib/core/Bot.js +++ b/lib/core/Bot.js @@ -32,6 +32,13 @@ class Bot { } return this.router; } + getIntegration(name) { + const integrationFind = R.filter((integration) => integration.serviceName() === name, this.integrations); + if (!R.isEmpty(integrationFind)) { + return integrationFind[0]; + } + return null; + } use(instance, filter) { if (instance.listen) { this.logger.info({ method: 'use', message: `Integration: ${instance.serviceName()}` }); diff --git a/src/core/Bot.ts b/src/core/Bot.ts index 0ff7cea..5a68050 100644 --- a/src/core/Bot.ts +++ b/src/core/Bot.ts @@ -67,6 +67,17 @@ export class Bot { return this.router; } + public getIntegration(name: string): any | null { + const integrationFind = R.filter((integration: any) => + integration.serviceName() === name, this.integrations); + + if (!R.isEmpty(integrationFind)) { + return integrationFind[0]; + } + + return null; + } + public use(instance: any, filter?: string | string[]): void { // it's an integration if (instance.listen) {