An event driven plugin based NodeJS Telegram Bot.
To start, set up a bot from @BotFather and store the key in an environment variable $TELEGRAM_TOKEN
or alternatively edit the key in app.js
. Then run node app.js
or alternatively nodemon
to begin.
Make sure you get the npm packages first via npm install
!
node-telegram-bot utilizes telegram-bot-api by mast, therefore expects the same parameters to the bot. You can change the default parameters in app.js
.
This bot utilizes plugins to extend its features. They are stored as *.js
files in the plugins folder. There are two parts to a plugin:
- An
init
function that is called when the bot is started - An array of
regex
& aregexHandler
to handle incoming matches.
Both can be used either or both at the same time. The only difference is that regex
and regexHandler
are only called after the text-message
event is emitted.
As reference, read Telegram Bots API and telegram-bot-api. Sample plugins can be found in the ./plugins
folder.
The bot utilizes Winston logger to log chats and errors. Chat and info
logs will end up in ./logs/chat.log
while warn
and error
will be output via STDIN
.
Start up events are emitted in the following order:
bot-starting
bot-started
plugins-loading
plugin-PLUGIN_NAME-loaded
plugins-loaded
- Payload type events
- Message type events
One of the following may be emitted depending on the type of payload received. The original Message object and the Telegram client is returned with each event. For received-reply
event, the reply_to_message
property from the Message object is provided as the first parameter.
received-service-notification
received-message
received-forward
received-reply
One of the following may be emitted depending on the type of message received. The message, the original Message object and the Telegram client is returned with each event.
text-message
document-message
photo-message
sticker-message
video-message
contact-message
location-message
- NodeJS
- npm