1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 23:16: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

@ -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()
}
}