https://github.com/wildegor/winston-telegram
Winston Telegram - a winston trasport supports Telegram Notifications
https://github.com/wildegor/winston-telegram
clean-architecture logging telegram telegram-bot winston winston-telegram
Last synced: 9 months ago
JSON representation
Winston Telegram - a winston trasport supports Telegram Notifications
- Host: GitHub
- URL: https://github.com/wildegor/winston-telegram
- Owner: WildEgor
- License: mit
- Created: 2024-01-03T11:09:28.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-01-04T04:58:52.000Z (over 2 years ago)
- Last Synced: 2025-02-01T20:17:10.019Z (over 1 year ago)
- Topics: clean-architecture, logging, telegram, telegram-bot, winston, winston-telegram
- Language: TypeScript
- Homepage:
- Size: 323 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Winston-Telegram
[](https://www.npmjs.com/package/@wildegor/winston-telegram/)
A [Telegram][0] transport for [winston][1].
Originally forked from [ivanmarban/winston-telegram][2] and updated to support winston 3.x and new features.
[](https://www.npmjs.com/package/@wildegor/winston-telegram)
[](https://npmcharts.com/compare/@wildegor/winston-telegram?minimal=true)
[](https://github.com/wildegor/winston-telegram/actions/workflows/testing.yml)
[](https://coveralls.io/github/wildegor/winston-telegram?branch=main)
[](https://standardjs.com)
### Main features:
- [x] Send log message to Telegram;
- [x] Send log messages with batching delay;
- [x] Send log messages with custom template;
- [x] Send log messages with custom formatMessage function;
- [x] Send log messages to specific chat;
- [x] Send log messages to specific topic;
- [x] Send log messages with silent mode;
- [x] Send log messages with disable notification;
- [x] Send log messages with custom parse mode;
- [x] Send log messages with custom levels;
- [x] Send log messages with handle exceptions;
- [x] Send log messages with custom batching separator.
## Installation:
``` sh
$ yarn add winston@3
$ yarn add winston-transport@4
$ yarn add axios
$ yarn add @wildegor/winston-telegram@latest
```
## Usage
``` js
const logger = require('winston')
const TelegramTransport = require('@wildegor/winston-telegram')
// or
import { TelegramTransport } from '@wildegor/winston-telegram';
logger.add(new TelegramTransport(options))
```
Options:
* __token:__ The Telegram bot authentication token. *[required]*
* __chatId:__ The Telegram chatid you want to send to. *[optional]*
* __parseMode:__ The Telegram mode for parsing entities in the message text. See [formatting options][3] for more details. *[optional]*
* __levels:__ Levels of messages that this transport should log. *[optional]* *[default ALL]*
* __silent:__ Whether to suppress output. *[boolean]* *[optional]*
* __disableNotification:__ Sends the message silently. *[boolean]* *[optional]*
* __template:__ Format output message. *[string]* *[optional]*
* __formatMessage:__ Format output message by own method. *[function]* *[optional]*
* __handleExceptions:__ Handle uncaught exceptions. *[boolean]* *[optional]*
* __batchingDelay:__ Time in ms within which to batch messages together. *[integer]* *[optional]* *[default 0 or disabled]*
* __batchingSeparator:__ String with which to join batched messages with *[string]* *[default "\n\n"]*
String template is based on named arguments:
``` js
'{level}' -> level of messages
'{message}' -> text of messages
'{metadata}' -> metadata object of messages
```
## Examples
Follow below steps to run the [examples][4]:
``` sh
$ git clone git@github.com:wildegor/winston-telegram.git -b main --single-branch
$ yarn install
```
Replace `TELEGRAM_TOKEN` and `CHAT_ID` with appropriate values, then run whatever example you want:
``` sh
$ cd examples/simple-log # or examples/replace-nest-logger
$ yarn install
$ yarn start:dev
```
[0]: https://telegram.org/
[1]: https://github.com/flatiron/winston
[2]: https://github.com/ivanmarban/winston-telegram
[3]: https://core.telegram.org/bots/api#formatting-options
[4]: https://github.com/wildegor/winston-telegram/tree/main/examples