Skip to content

Send logs from your project directly on telegram, no backend or webHook needed!

License

Notifications You must be signed in to change notification settings

colgatto/telegram-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 /started 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

example image

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:)