README
Library features:
- 🤖 Full Telegram Bot API 4.4 support.
- 🔭 Easy to use.
- 💰 Supports payments.
- 📡 Build-in modification and event system.
🔨 Installation
Download and install via npm package manager (stable):
npm install tgbotar --save
Or clone fresh code directly from git:
git clone https://github.com/i7Firas/tgbotar.git
cd tgbotar
npm install
📌 Usage
Import tgbotar
module and create a new bot object:
const TGBotar = require('tgbotar');
const bot = new TGBotar('TELEGRAM_BOT_TOKEN');
bot.on('text', (msg) => msg.reply.text(msg.text));
bot.start();
Don't forget to insert your Telegram Bot API token key.
🔖 Examples
- Send text on
/start
or/help
command:
bot.on(['/start', '/help'], (msg) => msg.reply.text('Hello World'));
- Send photo:
bot.on('/photo', (msg) => {
return msg.reply.photo('https://telegra.ph/file/fd2d68a59c928de61f1fb.jpg');
});
- Command with arguments
/echo <message>
:
bot.on(/^\/echo (.+)$/, (msg, argu) => {
const text = argu.match[1];
return bot.sendMessage(msg.from.id, text);
});
⏰ Events
Use bot.on(<event>, <function>)
to handle all possible TGBotar events.
For example, to catch a command, just add a slash:
bot.on('/start', (msg) => {
return bot.sendMessage(msg.from.id, `Hello, ${ msg.from.first_name }`);
});