This repository has been archived on 2025-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
Files
sd-telegram-bot/src/helpers/logging.ts
2023-09-08 22:09:35 +03:00

20 lines
554 B
TypeScript

import { Middleware } from "grammy";
import type { Update } from "@grammyjs/types";
import type { Context } from "#root/context.js";
export function getUpdateInfo(ctx: Context): Omit<Update, "update_id"> {
const { update_id, ...update } = ctx.update;
return update;
}
export function logHandle(id: string): Middleware<Context> {
return (ctx, next) => {
ctx.logger.info({
msg: `handle ${id}`,
...(id.startsWith("unhandled") ? { update: getUpdateInfo(ctx) } : {}),
});
return next();
};
}