File tree Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ require ( '../cli.js' ) ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-console */
2+ const inquirer = require ( 'inquirer' ) ;
3+ const https = require ( 'https' ) ;
4+ const ora = require ( 'ora' ) ;
5+ const { printError } = require ( './src/utils/print' ) ;
6+
7+ inquirer
8+ . prompt ( [
9+ {
10+ type : 'input' ,
11+ message : 'Enter your botToken:' ,
12+ name : 'botToken' ,
13+ } ,
14+ {
15+ type : 'input' ,
16+ message : 'Enter channel\'s username (without @):' ,
17+ name : 'channelUsername' ,
18+ } ,
19+ ] )
20+ . then ( ( answers ) => {
21+ const { botToken, channelUsername } = answers ;
22+ const url = `https://api.telegram.org/bot${ botToken } /getChat?chat_id=@${ channelUsername } ` ;
23+ const spinner = ora ( 'Fetching ChatId...' ) . start ( ) ;
24+ https . get ( url , ( res ) => {
25+ res . on ( 'data' , ( data ) => {
26+ spinner . stop ( ) ;
27+
28+ const response = JSON . parse ( data . toString ( ) ) ;
29+ if ( ! response . ok ) return printError ( 'Invalid botToken or channel username provided!' ) ;
30+ return console . log ( 'ChatId of the channel:' , response . result . id ) ;
31+ } ) ;
32+ res . on ( 'error' , ( error ) => printError ( `Telegram server error: ${ error } ` ) ) ;
33+ } ) ;
34+ } )
35+ . catch ( ( error ) => {
36+ if ( error . isTtyError ) {
37+ console . log ( 'Prompt couldn\'t be rendered in the current environment' ) ;
38+ // Prompt couldn't be rendered in the current environment
39+ } else {
40+ // Something else when wrong
41+ }
42+ } ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " express-notify-telegram" ,
3- "version" : " 1.0 .0" ,
3+ "version" : " 1.1 .0" ,
44 "description" : " A simple Express middleware to notify errors into Telegram" ,
55 "main" : " index.js" ,
66 "scripts" : {
77 "start" : " node index.js"
88 },
9+ "bin" : {
10+ "express-notify-telegram" : " ./bin/which"
11+ },
912 "keywords" : [
1013 " telegram" ,
1114 " express" ,
1922 "eslint-plugin-import" : " ^2.22.1"
2023 },
2124 "dependencies" : {
22- "on-finished" : " ^2.3.0"
25+ "inquirer" : " ^7.3.3" ,
26+ "on-finished" : " ^2.3.0" ,
27+ "ora" : " ^5.1.0"
2328 },
2429 "repository" : {
2530 "type" : " git" ,
Original file line number Diff line number Diff line change @@ -5,4 +5,8 @@ const printWarning = (text) => console.warn(
55 '\x1b[0m' , text ,
66) ;
77
8- module . exports = { printWarning } ;
8+ const printError = ( text ) => console . error (
9+ '\x1b[31m' , 'Invalid botToken or channel username provided!' ,
10+ ) ;
11+
12+ module . exports = { printWarning, printError } ;
You can’t perform that action at this time.
0 commit comments