telegraf-update-logger
v1.5.0
Published
Update logging middleware for Telegraf
Downloads
32
Maintainers
Readme
telegraf-update-logger
Font: Ubuntu Mono, Theme: OceanicMaterial
Install
yarn add telegraf-update-logger
Examples
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:
options
object?
= {}
.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- ...
format
options
updateLogger.format(update: Update, options: object?): string
Formats an update as string.
Params:
update
Updateoptions
object?
= {}
.colors
boolean | object
= false
– enables/disables/sets colors.id
function
– a function that sets colors of message IDs.chat
function
– a function that sets colors of chat titles.user
function
– a function that sets colors of user names.type
function
– a function that sets colors of message types
Contribute
PRs accepted.