0.1.5 • Published 2 months ago

@henta/input v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@henta/input

Multifunctional input data parser.

📌 Is part of HENTA Framework

Attachments

Base:

import { AttachmentRequest } from '@henta/input';
import type { Attachment, PlatformContext } from '@henta/core';

async function handler(
    ctx: PlatformContext,
    @ArgumentRequest({ type: 'photo' }) photo: Attachment
) {
    console.log(photo);
    await ctx.answer({ text: 'hello world' });
}

const requests = getAttachmentRequests(command.handler)
    ?.map(v => v.request);
    
console.log(requests);

function myHentaMiddleware(ctx: PlatformContext, next) {
    const args = await requireInputArgs(handler, ctx);
    await command.handler(ctx, ...args);
    return next();
}

// hentaBot: HentaBot
hentaBot.use(myHentaMiddleware);

BotCmd command

import { CommandView, BotcmdView, BotcmdCommand } from '@henta/botcmd';
import type { Attachment, PlatformContext } from '@henta/core';
import { AttachmentRequest } from '@henta/input';

@BotcmdView({ name: 'mycommand' })
export default class MyCommandView extends CommandView {
  @BotcmdCommand()
  async handler(
    ctx: Context,
    // You can use converter
    // And also pass only the type to the first argument
    @AttachmentRequest('photo', (item) => item.getUrl()) url: string,
    @AttachmentRequest(AttachmentType.Photo) attachment: Attachment
  ) {
    await ctx.answer({
      text: 'Oh, yes..',
      files: [
        Upload.fromUrl('photo', url),
        Upload.fromUrl('photo', await attachment.getUrl()),
      ],
    });
  }
}
0.1.5

2 months ago

0.1.4

3 months ago

0.1.3

3 months ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago