1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-05-11 06:36:40 +07:00

added vk events handler stub

This commit is contained in:
Fedor Katurov 2021-04-28 09:55:02 +07:00
parent dfae42c197
commit 3f908da91e
11 changed files with 125 additions and 67 deletions
src/service/telegram

View file

@ -1,17 +1,17 @@
import { TelegramConfig } from "./types";
import { TelegramConfig, WebhookConfig } from "./types";
import { Telegraf } from "telegraf";
import logger from "../logger";
import { Response } from "express";
import { Update } from "typegram";
import loggerTgMiddleware from "../logger/tg";
import { WebhookConfig } from "../../config/types";
// import SocksProxyAgent from 'socks-proxy-agent';
export class TelegramService {
public readonly bot: Telegraf;
public readonly webhook: WebhookConfig = {};
constructor(private props: TelegramConfig, private webhook: WebhookConfig) {
constructor(private props: TelegramConfig) {
// const agent = (CONFIG.PROXY && new SocksProxyAgent(CONFIG.PROXY)) || null;
const options: Partial<Telegraf.Options<any>> = {
telegram: {
@ -21,6 +21,8 @@ export class TelegramService {
},
};
this.webhook = props.webhook;
this.bot = new Telegraf(props.key, options);
this.bot.use(loggerTgMiddleware);

View file

@ -1,3 +1,9 @@
export interface WebhookConfig {
url?: string;
enabled?: boolean;
}
export interface TelegramConfig {
key: string;
webhook: WebhookConfig;
}

View file

@ -1,5 +1,12 @@
import * as yup from "yup";
import { boolean, object, string } from "yup";
const webhookValidationSchema = object().optional().shape({
url: string(),
enabled: boolean(),
});
export const telegramConfigSchema = yup.object().required().shape({
key: yup.string().required(),
webhook: webhookValidationSchema,
});