1.0.1 • Published 3 years ago

telegraf-hears-modules v1.0.1

Weekly downloads
5
License
ISC
Repository
github
Last release
3 years ago
Shitcode be like:

Telegraf hearModules

npm install telegraf-hears-modules

example

  • #FFCC66 Module is disabled this.disable = true
  • #99CC99 Successful module loading
  • #F2777A Error module loading

Example

index.js

const { Telegraf } = require("telegraf"); // import telegraf
const { modulesLoad } = require("telegraf-hears-modules"); // import telegraf-hears-modules

const bot = new Telegraf("Your bot token");
modulesLoad(bot, "Folder with modules", data = {
  // Your variables that will be available in the module \ optional
  testField: "Leystof"
}); // Loading modules

bot.launch()

Module file

module.exports.Module = function (bot, data) {
  // this.disable = true // if true === module not loading \ Optional field

  this.triggers = [
    /^Field/i,
  ]; // text or regexp

  this.func = async (ctx) => {
    // Here the execution of the command
    return ctx.reply(data.testField)
  };
};

Callback example

const { Markup } = require("telegraf");

module.exports.Module = function (bot) {

  this.triggers = [
    /^Test/i,
  ];

  this.callback = "test"

  this.func = async (ctx) => {
    if (ctx.callbackQuery) {
      return ctx.editMessageText("Callback work ✨")
    }

    return ctx.reply(`Test callback`, Markup.inlineKeyboard([
      Markup.button.callback("Click", "test"),
    ]))
  };
};

Tests

const { Telegraf } = require("telegraf");
const { testLoad } = require("telegraf-hears-modules");

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

testLoad(bot);