tell-js
v1.1.3
Published
A logging library to send alerts to a Telegram bot.
Downloads
4
Readme
tell-js
A lightweight and easy-to-use Node.js logging library that sends alerts via Telegram bots.
Features
- Simple and intuitive API
- Supports multiple log levels (info, error, warn, log)
- Sends log messages directly to your Telegram chat
- Easy integration with existing Node.js projects
Installation
npm install tell-js
Usage
import Tell from 'tell-js';
const logger = new Tell({
chatId: "YOUR_CHAT_ID",
botToken: "YOUR_BOT_TOKEN"
});
logger.info("This is information");
logger.error("This is an error message");
logger.warn("This is a warning message");
logger.log("A regular log message.");
Configuration
To use tell-js
, you need to provide two pieces of information:
- Telegram Bot Token
- Chat ID
Creating a Telegram Bot Token
- Open Telegram and search for the
@BotFather
bot. - Start a chat and send the command
/newbot
. - Follow the prompts to choose a name and username for your bot.
- Once created, BotFather will provide you with a token. This is your
BOT_TOKEN
.
Getting Your Chat ID
- Start a chat with your newly created bot.
- Send a message to the bot.
- Open this URL in your browser, replacing
<BOT_TOKEN>
with your actual bot token:https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
- Look for the
"chat":{"id":
field in the response. The number after it is yourCHAT_ID
.
Integrating with Winston
import winston from 'winston';
import Tell from 'tell-js';
import { Writable } from 'stream';
const tell = new Tell({
chatId: "YOUR_CHAT_ID",
botToken: "YOUR_BOT_TOKEN"
});
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.Stream({
stream: new Writable({
write: (msg: string) => {
// Use tell-js methods here.
tell.log(msg);
return true;
}
})
})
]
});
FAQ
Q: Is there a message size limit? A: Yes, Telegram has a limit of 4096 characters per message. If your log message exceeds this, it will be split into multiple messages.
Q: Can I use this in a browser environment? A: No,
tell-js
is designed for Node.js environments only, as it requires access to server-side resources.Q: How secure is it to send logs via Telegram? A: While Telegram provides encryption, we recommend not logging sensitive information like passwords or API keys.
Troubleshooting
- Messages not sending: Ensure your bot token and chat ID are correct.
- Rate limiting issues: Check your
rateLimit
setting and Telegram's rate limit policies. - "Bot not initialized" error: Make sure you've created the Tell instance before using logging methods.
API Reference
new Tell(options)
Creates a new Tell instance.
options.chatId
: Your Telegram chat ID (string)options.botToken
: Your Telegram bot token (string)
Methods
logger.info(message)
: Sends an info-level messagelogger.error(message)
: Sends an error-level messagelogger.warn(message)
: Sends a warning-level messagelogger.log(message)
: Sends a regular log message
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the GNU General Public License v3.0 License - see the LICENSE file for details.
Support
If you encounter any problems or have any questions, please open an issue on the GitHub repository or send an email to the maintainer.
Changelog
See CHANGELOG.md for a detailed history of changes to tell-js
.
Acknowledgements
- Thanks to the Telegram team for their excellent bot API.
- Inspired by the logging strategy of @levelsio for his projects.