New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

telegraf-command-handler

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegraf-command-handler

just a command handler for Telegraf

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Telegraf Command Handler

A command handler for Telegraf, which is similar to the command handler for Discord.js and such. The goal is that all commands are not in 1 file... But divided into several different files.

Installation

npm i telegraf-command-handler
# or
yarn add telegraf-command-handler
# or
pnpm add telegraf-command-handler

Usage

/* main file */
const { Telegraf } = require('telegraf');
const { TelegrafCommandHandler } = require('telegraf-command-handler');
const path = require('path');

const bot = new Telegraf('Your bot token');

const CommandHandler = new TelegrafCommandHandler({
    path: path.resolve() + "/path/to/dir",
});

bot.use(CommandHandler.load());

// ...bot.launch()
/* command file */
module.exports = {
    name: "start",
    async execute(ctx) {
        ctx.reply("hello world");
    }
}

Constructor Options

interface Options {
    /* path to your command directory */
    path: string;
    /* a function that executed when error comes from your command file */
    errorHandling: (ctx: Context, error: any) => any | undefined;
}

Command Example

module.exports = {
    /* command name (it will executed like /echo) */
    name: "echo",
    /* optional command aliases (can be string or Array<string>) */
    aliases: ["say"],
    /* command code */
    async execute(ctx, args) {
        ctx.reply(args.join(" "))
    }
}

Keywords

telegraf

FAQs

Package last updated on 04 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts