Skip to content

PDF logging and send automatically by telegram bot #2

Discussion options

You must be logged in to vote

To save log information to PDF and send it to users automatically in Node.js, you'll need to follow these steps:

  • Generate a PDF from log data
  • Save the PDF file
  • Send the PDF to users by bot sendDocument method.

Here are the essential modules for this task:

  • pdfkit: For creating PDF documents
  • node-telegram-bot-api: telegram bot module
  • fs: For file system operations (built-in Node.js module)

Code

  • logging pdf:
import fs from 'fs';
import PDFDocument from 'pdfkit';

class PDFLogger {
  private doc: PDFKit.PDFDocument; // PDF Document instance
  private stream: fs.WriteStream; // Write stream for the PDF file
  private filePath: string;       // Path to save the PDF file

  constructor(fil…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Spirit-crypto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants