1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 15:06:41 +07:00

added telegram service connector

This commit is contained in:
Fedor Katurov 2021-04-26 11:04:24 +07:00
parent 51fe9160ca
commit 5453e884c6
5 changed files with 162 additions and 2 deletions

View file

@ -15,6 +15,6 @@ const config = userConfig && mergeRight(defaultConfig, userConfig) || defaultCon
export default function prepareConfig() {
validateConfig(config)
logger.debug('config is ok:', config)
logger.debug('config is ok: ', config)
return config
}

View file

@ -5,7 +5,7 @@ import { VkService } from './service/vk';
try {
const config = prepareConfig()
const telegramService = new TelegramService(config.telegram)
const telegramService = new TelegramService(config.telegram).start()
const vkService = new VkService(config.vk)
} catch (e) {

View file

@ -1,9 +1,39 @@
import { TelegramConfig } from './types';
import { Telegraf } from 'telegraf';
import logger from '../logger';
// import SocksProxyAgent from 'socks-proxy-agent';
export class TelegramService {
bot: Telegraf
constructor(private props: TelegramConfig) {
if (!props.key) {
throw new Error('Telegram api key not found. Get it from bot father')
}
// const agent = (CONFIG.PROXY && new SocksProxyAgent(CONFIG.PROXY)) || null;
const options = {
channelMode: true,
telegram: {
// agent, // TODO: add proxy support
webhookReply: !!props.webhookUrl,
},
};
this.bot = new Telegraf(props.key, options);
process.once('SIGINT', () => this.bot.stop('SIGINT'))
process.once('SIGTERM', () => this.bot.stop('SIGTERM'))
logger.info('Telegram service started')
}
start() {
if (!this.bot) {
throw new Error('Not initialized')
}
return this.bot.launch()
}
}