A lightweight and easy-to-use Node.js logging library that sends alerts via Telegram bots.
- 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
npm install tell-js
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.");
To use tell-js
, you need to provide two pieces of information:
- Telegram Bot Token
- Chat ID
- 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
.
- 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
.
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;
}
})
})
]
});
-
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.
- 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.
Creates a new Tell instance.
options.chatId
: Your Telegram chat ID (string)options.botToken
: Your Telegram bot token (string)
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
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GNU General Public License v3.0 License - see the LICENSE file for details.
If you encounter any problems or have any questions, please open an issue on the GitHub repository or send an email to the maintainer.
See CHANGELOG.md for a detailed history of changes to tell-js
.
- Thanks to the Telegram team for their excellent bot API.
- Inspired by the logging strategy of @levelsio for his projects.