To install the stable version:
npm install --save telegram-node-bot
This assumes you are using npm as your package manager. If you don’t, you can access these files on unpkg, download them, or point your package manager to them.
First of all you need to create your bot and get Token, you can do it right in telegram, just write to @BotFather.
Now let's write simple bot!
'use strict'
const Telegram = require('telegram-node-bot')
const TelegramBaseController = Telegram.TelegramBaseController
const TextCommand = Telegram.TextCommand
const tg = new Telegram.Telegram('YOUR_TOKEN')
class PingController extends TelegramBaseController {
/**
* @param {Scope} $
*/
pingHandler($) {
$.sendMessage('pong')
}
get routes() {
return {
'pingCommand': 'pingHandler'
}
}
}
tg.router
.when(
new TextCommand('ping', 'pingCommand'),
new PingController()
)
That's it!