telegram-log
v0.4.0
Published
Send log from your project directly on telegram, any backend or webHook needed
Downloads
11
Maintainers
Readme
telegram-log
Send the log from your project directly on telegram, no backend or webHook needed!
You can use two different template or you can easily create and use your own too.
Install
npm install --save telegram-log
Use @botfather to generate your bot and @get_userId_bot to know your user id.
Note
Remember that users in the receiverList must have /start
ed your bot to be able to receive messages!
Example
Basic usage
const tLog = require('telegram-log').init({
token: 'TELEGRAM_BOT_TOKEN',
receivers: 'TELEGRAM_USER_ID'
});
tLog.info('User login');
tLog.warning('Hard disk is almost full');
tLog.error('Internal Server Error',500);
tLog.debug('hello guy',123);
Custom options
const tLog = require('telegram-log');
const options = {
token: 'TELEGRAM_BOT_TOKEN',
receivers: 'TELEGRAM_USER_ID',
dateFormat: 'd/mm/yy, H:MM:ss',
};
tLog.init(options);
//you can add custom options just for the single log
tLog.info('User login on https://facebook.com', { disableLinkPreview: true, template: '{{emojiType}}{{text}}' } );
tLog.warning('Hardisk `Games` is almost full', { mode: 'Markdown', silent: true, template: 'minimal' } );
tLog.error('<b>Internal Server Error</b>', 500, { mode: 'HTML' } );
tLog.debug('hello guy', { template: false } );
Result
Documentation
Options
| Parameter | Type | Description | Required |
| ------ | ------ | ------ | ------ |
| token | string | telegram bot token (get your bot's from @botfather) | required |
| receivers | string/Array | user ids that will receive message, (get yours from @get_userId_bot) | required |
| projectName | string | project name if you need to distinguish them when you use same bot for multiple projects or applications | optional (default ""
) |
| mode | string | message format, can be "text"
, "html"
, "markdown"
| optional (default "text"
) |
| dateFormat | string | represents the format of the date, uses dateformat | optional (default "d/mm/yyyy, HH:MM:ss"
) |
| silent | bool | send the message without a notification | optional (default false
) |
| disableLinkPreview | bool | disable preLoading urls inside the telegram chat | optional (default false
) |
| template | string/bool | can use to select template ("default"
or "minimal"
) or create your custom template, set it false
to disable template | optional (default "default"
) |
Template
If you don't like the default
or minimal
templates you can create and use your own with the options's parameter.
Use double curly braces to add variables to your template like {{date}}
or {{projectName}}
.
Accepted names for variables are :
- text
- code
- projectName
- date
- type (
info
,warning
,error
,debug
) - emojiType (:speech_balloon:, :warning:, :bangbang:, :beetle:)