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

#1 added handlebars template engine

This commit is contained in:
Fedor Katurov 2021-04-29 10:30:01 +07:00
parent 95ed64c640
commit eb6a645ad3
10 changed files with 112 additions and 17 deletions

View file

@ -3,8 +3,18 @@ import { MessageContext } from "vk-io";
import { NextMiddleware } from "middleware-io";
import logger from "../../logger";
import { ContextDefaultState } from "vk-io/lib/structures/contexts/context";
import { UsersUserFull } from "vk-io/lib/api/schemas/objects";
export class MessageNewHandler extends VkEventHandler {
interface Fields {
buttons: string[];
}
interface Values {
user: UsersUserFull;
text: string;
}
export class MessageNewHandler extends VkEventHandler<Fields, Values> {
public execute = async (
context: MessageContext<ContextDefaultState>,
next: NextMiddleware
@ -23,8 +33,12 @@ export class MessageNewHandler extends VkEventHandler {
`received message from ${from.first_name} ${from.last_name}: ${context.text}`
);
const template = this.template.template;
const fields = this.template.fields;
const parsed = this.template.theme({
user: from,
text: context.text,
});
await this.telegram.sendMessageToChan(this.channel, parsed).catch(next);
await next();
};