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:
parent
51fe9160ca
commit
5453e884c6
5 changed files with 162 additions and 2 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue