mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-05-12 15:16:40 +07:00
added working message handler
This commit is contained in:
parent
12c8e30a1e
commit
1754092f7c
6 changed files with 77 additions and 39 deletions
|
@ -1,12 +1,28 @@
|
|||
import { VkEventHandler } from "./types";
|
||||
import { ContextDefaultState, MessageContext } from "vk-io";
|
||||
import { VkEventHandler } from "./VkEventHandler";
|
||||
import { MessageContext } from "vk-io";
|
||||
import { NextMiddleware } from "middleware-io";
|
||||
import logger from "../../logger";
|
||||
import { ContextDefaultState } from "vk-io/lib/structures/contexts/context";
|
||||
|
||||
export class MessageNewHandler extends VkEventHandler {
|
||||
public execute = async (
|
||||
context: MessageContext<ContextDefaultState>,
|
||||
next: NextMiddleware
|
||||
) => {
|
||||
if (context.isOutbox) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const users = await this.instance.api.users.get({
|
||||
user_ids: [String(context.senderId)],
|
||||
});
|
||||
const from = users[0];
|
||||
|
||||
logger.debug(
|
||||
`received message from ${from.first_name} ${from.last_name}: ${context.text}`
|
||||
);
|
||||
|
||||
export class MessageNewHandler extends VkEventHandler<
|
||||
MessageContext<ContextDefaultState>
|
||||
> {
|
||||
public execute = async (context, next: NextMiddleware) => {
|
||||
console.log("received message!");
|
||||
await next();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue