1.5.0 • Published 5 years ago
telegraf-update-logger v1.5.0
telegraf-update-logger

Font: Ubuntu Mono, Theme: OceanicMaterial
Install
yarn add telegraf-update-loggerExamples
log all updates to console with colors
const Telegraf = require('telegraf');
const updateLogger = require('telegraf-update-logger');
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.use(updateLogger({ colors: true }));
bot.startPolling();log channel posts to file
const Telegraf = require('telegraf');
const updateLogger = require('telegraf-update-logger');
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.use(
updateLogger({
filter: (update) => update.channel_post || update.edited_channel_post,
log: (str) => fs.appendFileSync('messages.log', str),
}),
);
bot.startPolling();log all updates with custom colors
const Telegraf = require('telegraf');
const updateLogger = require('telegraf-update-logger');
const chalk = require('chalk');
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.use(
updateLogger({
colors: {
id: chalk.red,
chat: chalk.yellow,
user: chalk.green,
type: chalk.bold,
},
}),
);
bot.startPolling();reply to all messages with formatted updates
const Telegraf = require('telegraf');
const updateLogger = require('telegraf-update-logger');
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.on('message', (ctx) => ctx.reply(updateLogger.format(ctx.update)));
bot.startPolling();API
updateLogger(options: object?): function
Creates a middleware that logs every update and then invokes the next middleware.
Params:
optionsobject?= {}.filter(update: Update) => boolean – a function that determines which updates should be logged.log(formattedUpdate: string) => void= console.log– a function that logs formatted updates- ...
formatoptions
updateLogger.format(update: Update, options: object?): string
Formats an update as string.
Params:
updateUpdateoptionsobject?= {}.colorsboolean | object= false– enables/disables/sets colors.idfunction– a function that sets colors of message IDs.chatfunction– a function that sets colors of chat titles.userfunction– a function that sets colors of user names.typefunction– a function that sets colors of message types
Contribute
PRs accepted.