-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement getClient helper function (#634)
- Loading branch information
1 parent
5211016
commit 9f0b334
Showing
5 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import LineBot from './line/LineBot'; | ||
import MessengerBot from './messenger/MessengerBot'; | ||
import SlackBot from './slack/SlackBot'; | ||
import TelegramBot from './telegram/TelegramBot'; | ||
import ViberBot from './viber/ViberBot'; | ||
import getBottenderConfig from './shared/getBottenderConfig'; | ||
import getSessionStore from './getSessionStore'; | ||
import { Channel } from './types'; | ||
|
||
const BOT_MAP = { | ||
messenger: MessengerBot, | ||
line: LineBot, | ||
slack: SlackBot, | ||
telegram: TelegramBot, | ||
viber: ViberBot, | ||
}; | ||
|
||
function getClient(channel: Channel) { | ||
const { channels = {} } = getBottenderConfig(); | ||
const sessionStore = getSessionStore(); | ||
|
||
const channelConfig = (channels as any)[channel]; | ||
|
||
if (!channelConfig) { | ||
return null; | ||
} | ||
|
||
const ChannelBot = BOT_MAP[channel]; | ||
|
||
const channelBot = new ChannelBot({ | ||
...channelConfig, | ||
sessionStore, | ||
} as any); | ||
|
||
return channelBot.connector.client; | ||
} | ||
|
||
export default getClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters