mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 23:16:41 +07:00
initial
This commit is contained in:
commit
ddefc2743a
21 changed files with 873 additions and 0 deletions
7
src/service/logger/index.ts
Normal file
7
src/service/logger/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { createLogger, format, transports } from 'winston';
|
||||
|
||||
const logger = createLogger({
|
||||
transports: new transports.Console({ format: format.simple() })
|
||||
})
|
||||
|
||||
export default logger
|
9
src/service/telegram/index.ts
Normal file
9
src/service/telegram/index.ts
Normal 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')
|
||||
}
|
||||
}
|
||||
}
|
4
src/service/telegram/types.ts
Normal file
4
src/service/telegram/types.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export interface TelegramConfig {
|
||||
key: string
|
||||
webhookUrl?: string
|
||||
}
|
6
src/service/telegram/validation.ts
Normal file
6
src/service/telegram/validation.ts
Normal 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
9
src/service/vk/index.ts
Normal 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
26
src/service/vk/types.ts
Normal 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',
|
||||
}
|
20
src/service/vk/validation.ts
Normal file
20
src/service/vk/validation.ts
Normal 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),
|
||||
}))
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue