0.1.1 • Published 1 year ago

@henta/bot v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@henta/bot

A convenient and flexible class for creating bots on henta

📌 Is part of HENTA Framework

Usage

const hentaBot = new HentaBot(process.env.MODE as BotMode);

// you can add any platforms that are convenient for you
hentaBot.addPlatform(new TelegramPlatform({ token: process.env.TG_TOKEN }));

/*
these middlewares will be processed when your bot receives a message. With their help, you can, for example, request a user from a database, catch and process errors, or check whether you need to respond to this message.

Order matters.
*/
hentaBot.setMiddleware([
  async (ctx, next) => {
    if (ctx.text === 'hello') {
      await ctx.answer({ text: 'hello world' });
    }

    return next();
  },
  async (ctx, next) => {
    if (ctx.isAnswered) {
      return next();
    }

    await ctx.answer({ text: 'maybe "hello"?' });
    return next();
  }
]);

/*
Here you can catch errors when sending a message or additionally process it for some effects or notes about changes (balance changes, new items in the inventory, etc.).
*/
hentaBot.setAnswerMiddleware([]);
await hentaBot.run();
0.1.1

1 year ago

0.1.0

1 year ago