express-errors-to-telegram
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

express-errors-to-telegram

Express error handling middleware for reporting application errors to Telegram. Fully supports typescript.

Setup

  1. Obtain new bot token via @BotFather
  2. Create a public channel and add your bot to the channel. After step 3 you can make channel private.
  3. Open https://api.telegram.org/bot<botToken>/getChat?chat_id=@<channel> where botToken is token obtained at step 1 and channel is channel name created at step 2. From response you need number from id field (e.g. -10014XXX54925):
{"ok":true,"result":{"id":-1001411154925,"title":"<yout channel title>","username":"<your bot name>","type":"channel"}}

Now, when you have botToken and chat_id you can use it in your application.

Install

$ yarn add express-errors-to-telegram --save

or if you prefer npm

$ npm install --save express-errors-to-telegram

Usage

const express = require('express');
const errorToTelegram = require('express-errors-to-telegram');

const app = express();

// Route that triggers a error
app.get('/error', function (req, res, next) {
  const err = new Error('Internal Server Error');
  err.status = 500;
  next(err);
})

// Send error reporting to Telegram
app.use(errorToTelegram('bot:token', 'chat_id', { handle4xx: false, handle5xx: true }));
app.listen(3000);

Package Sidebar

Install

npm i express-errors-to-telegram

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

7.27 kB

Total Files

5

Last publish

Collaborators

  • xrip