0.4.0 • Published 1 year ago

telegram-log v0.4.0

Weekly downloads
2
License
RWTFPL
Repository
github
Last release
1 year ago

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

ParameterTypeDescriptionRequired
tokenstringtelegram bot token (get your bot's from @botfather)required
receiversstring/Arrayuser ids that will receive message, (get yours from @get_userId_bot)required
projectNamestringproject name if you need to distinguish them when you use same bot for multiple projects or applicationsoptional (default "")
modestringmessage format, can be "text", "html", "markdown"optional (default "text")
dateFormatstringrepresents the format of the date, uses dateformatoptional (default "d/mm/yyyy, HH:MM:ss")
silentboolsend the message without a notificationoptional (default false)
disableLinkPreviewbooldisable preLoading urls inside the telegram chatoptional (default false)
templatestring/boolcan use to select template ("default" or "minimal") or create your custom template, set it false to disable templateoptional (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:)
0.4.0

1 year ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago