0.1.1 • Published 5 years ago

tgbotars v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

npm.io

Library features:

🔨 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);
});

See more examples!

⏰ 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 }`);
});