1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 23:16:41 +07:00
This commit is contained in:
Fedor Katurov 2021-04-07 17:33:36 +07:00
commit ddefc2743a
21 changed files with 873 additions and 0 deletions

View file

@ -0,0 +1,7 @@
import { createLogger, format, transports } from 'winston';
const logger = createLogger({
transports: new transports.Console({ format: format.simple() })
})
export default logger

View file

@ -0,0 +1,9 @@
import { TelegramConfig } from './types';
export class TelegramService {
constructor(private props: TelegramConfig) {
if (!props.key) {
throw new Error('Telegram api key not found. Get it from bot father')
}
}
}

View file

@ -0,0 +1,4 @@
export interface TelegramConfig {
key: string
webhookUrl?: string
}

View file

@ -0,0 +1,6 @@
import * as yup from 'yup';
export const telegramConfigSchema = yup.object().required().shape({
key: yup.string().required(),
webhookUrl: yup.string().notRequired(),
})

9
src/service/vk/index.ts Normal file
View file

@ -0,0 +1,9 @@
import { VkConfig } from './types';
export class VkService {
constructor(private config: VkConfig) {
if (!config.groups.length) {
throw new Error('No vk groups to handle. Specify them in config')
}
}
}

26
src/service/vk/types.ts Normal file
View file

@ -0,0 +1,26 @@
export interface VkConfig extends Record<string, any> {
groups: ConfigGroup[]
}
interface ConfigGroup {
id: number
name: string
testResponse: string
secretKey: string
apiKey: string
channels: GroupChannel[]
}
interface GroupChannel {
id: string,
events: VkEvent[]
}
export enum VkEvent {
Confirmation = 'confirmation',
WallPostNew = 'wall_post_new',
PostSuggestion = 'post_suggestion',
GroupJoin = 'group_join',
GroupLeave = 'group_leave',
MessageNew = 'message_new',
}

View file

@ -0,0 +1,20 @@
import * as yup from 'yup'
import { VkConfig, VkEvent } from './types';
const vkChannelEventSchema = yup.string().oneOf(Object.values(VkEvent))
const vkChannelSchema = yup.object().required().shape({
id: yup.string().required().matches(/^@/, ({ path }) => `${path} should start with "@"`),
events: yup.array().of(vkChannelEventSchema)
})
export const vkConfigSchema = yup.object<VkConfig>().required().shape({
groups: yup.array().required().of(yup.object().shape({
id: yup.number().positive(),
name: yup.string().required(),
testResponse: yup.string().required(),
secretKey: yup.string().required(),
apiKey: yup.string().required(),
channels: yup.array().of(vkChannelSchema),
}))
})