yarn add telegraf-update-logger
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();
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(str)
})
);
bot.startPolling();
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();
Creates a middleware that logs every update and then invokes the next middleware.
Params:
options
object?
= {}
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
PRs accepted.