1.0.0 • Published 3 years ago

telegraf-hearmodules v1.0.0

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

Telegraf hearModules

npm install telegraf-hearModules

Example

index.js

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

const bot = new Telegraf("Your bot token");
modulesLoad(bot, "Module folder", data = {
	// Your variables that will be available in the module
	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 = [
		/^Author/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"),
		]))
	};
};
1.0.0

3 years ago