@alximicus/simple-node-telegram-bot
v0.1.12
Published
Package which will help you to create good telegram bots.
Downloads
24
Maintainers
Readme
Simple node telegram bot
Simple, well-typed and easy to use package which allow you to create Telegram bots.
Currently, bot using pooling for receiving updates. Webhook will be added later.
Motivation
To have a simple, easy supported and kept updated package for creating telegram bots.
Usage
Create the bot instance:
import { ATelegram } from '@alximicus/simple-node-telegram-bot';
const bot = new ATelegram('your_bot_token');
// ...
Regexp subscriptions (searching match inside text message):
// ...
bot.onText(/\/hello/, (update, api) => {
api.sendMessage({
chat_id: update.message.from.id,
text: 'Hello, my friend!',
});
});
// ...
Commands subscriptions (searching text commands inside entities
array):
// ...
const enum MyBotCommands {
Subscribe = '/subscribe',
Unsubscribe = '/unsubscribe',
Start = '/start',
}
bot.onCommand(MyBotCommands.Subscribe, (update, api) => {
// subscription code
api.sendMessage({
chat_id: update.message.from.id,
text: 'You successfully subscribed to news!'
});
});
// ...
or you can subscribe on any update:
// ...
bot.update$.subscribe({
next: (update) => {
// now you have access to every update
console.log(update);
}
})
// ...
To be continued...