mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 15:06:41 +07:00
added webhook parser
This commit is contained in:
parent
9433cc327a
commit
87da9078fe
7 changed files with 32 additions and 20 deletions
|
@ -6,6 +6,7 @@ import loggerHttpMiddleware from "../../service/logger/http";
|
|||
import logger from "../../service/logger";
|
||||
import { TelegramService } from "../../service/telegram";
|
||||
import http from "http";
|
||||
import { WebhookConfig } from "../../config/types";
|
||||
|
||||
export class HttpApi {
|
||||
app: Express;
|
||||
|
@ -13,7 +14,8 @@ export class HttpApi {
|
|||
constructor(
|
||||
private props: HttpConfig,
|
||||
private telegram: TelegramService,
|
||||
private vk: VkService
|
||||
private vk: VkService,
|
||||
private webhook?: WebhookConfig
|
||||
) {
|
||||
this.app = express();
|
||||
this.app.use(express.json());
|
||||
|
@ -35,8 +37,8 @@ export class HttpApi {
|
|||
this.app.use(bodyParser.json());
|
||||
this.app.use(express.json());
|
||||
|
||||
if (props?.webhook?.enabled && props?.webhook?.url) {
|
||||
logger.info(`using webhook at ${props.webhook.url}`);
|
||||
if (this?.webhook?.enabled && this?.webhook?.path) {
|
||||
logger.info(`using webhook at ${this.webhook.path}`);
|
||||
this.app.post(props.webhook.url, this.handleWebhook);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
export interface HttpConfig extends Record<string, any> {
|
||||
port: number;
|
||||
webhook?: {
|
||||
url?: string;
|
||||
enabled?: boolean;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
import { boolean, number, object, string } from "yup";
|
||||
import { number, object } from "yup";
|
||||
|
||||
export const httpConfigSchema = object()
|
||||
.required()
|
||||
.shape({
|
||||
port: number().defined().required().positive(),
|
||||
webhook: object().optional().shape({
|
||||
url: string(),
|
||||
enabled: boolean(),
|
||||
}),
|
||||
});
|
||||
export const httpConfigSchema = object().required().shape({
|
||||
port: number().defined().required().positive(),
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue