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:
parent
95ed64c640
commit
eb6a645ad3
10 changed files with 112 additions and 17 deletions
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue