From 02cbc1044a8ae7616ac52db86941db4524cef63b Mon Sep 17 00:00:00 2001 From: Jalaj Sharma Date: Fri, 25 Jul 2025 23:08:25 +0530 Subject: [PATCH] working bot --- .env-sample | 1 - jj.txt | 31 +++++++++++++++++++++++++++++++ package.json | 13 ++++++------- src/index.ts | 12 +++++++++++- yarn.lock | 21 +++++++++++++-------- 5 files changed, 61 insertions(+), 17 deletions(-) delete mode 100644 .env-sample create mode 100644 jj.txt diff --git a/.env-sample b/.env-sample deleted file mode 100644 index 70b63594..00000000 --- a/.env-sample +++ /dev/null @@ -1 +0,0 @@ -BOT_TOKEN="" diff --git a/jj.txt b/jj.txt new file mode 100644 index 00000000..e315169b --- /dev/null +++ b/jj.txt @@ -0,0 +1,31 @@ + + +import { Telegraf } from 'telegraf'; +import { config } from 'dotenv'; +config(); +import { about } from './commands'; +import { greeting } from './text'; +import { VercelRequest, VercelResponse } from '@vercel/node'; +import { development, production } from './core'; + +const BOT_TOKEN = process.env.BOT_TOKEN || ''; +const ENVIRONMENT = process.env.NODE_ENV || ''; +if (!BOT_TOKEN) { + console.error('Error: BOT_TOKEN is not defined in .env file'); + process.exit(1); +} +console.log(`BOT_TOKEN: ${BOT_TOKEN}`); +console.log(`NODE_ENV: ${ENVIRONMENT}`); + +const bot = new Telegraf(BOT_TOKEN); + +bot.command('about', about()); +bot.on('message', greeting()); + +//prod mode (Vercel) +export const startVercel = async (req: VercelRequest, res: VercelResponse) => { + await production(req, res, bot); +}; +//dev mode +ENVIRONMENT !== 'production' && development(bot); + diff --git a/package.json b/package.json index 06091e55..0c891d21 100644 --- a/package.json +++ b/package.json @@ -15,16 +15,15 @@ "@types/node": "^22.8.6", "@vercel/ncc": "^0.38.2", "debug": "^4.3.7", - "nodemon": "^3.1.7", + "dotenv": "^17.2.0", + "nodemon": "^3.1.10", "prettier": "^3.3.3", "ts-node": "^10.9.2", - "typescript": "^5.6.3" + "typescript": "^5.8.3" }, "scripts": { - "dev": "DEBUG=bot* dotenv -- nodemon -e ts -x ts-node src/index.ts", - "devWindows": "@powershell -Command $env:DEBUG='bot*';dotenv -- -- nodemon -e ts -x ts-node src/index.ts", - "build": "ncc build src/index.ts -o public -m", - "prettier": "prettier --write 'src/**/*.ts'", - "lint": "tsc --noemit" + "build": "tsc", + "start": "node dist/index.js", + "dev": "nodemon -e ts -x ts-node src/index.ts" } } diff --git a/src/index.ts b/src/index.ts index 38343434..3d1270a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,8 @@ -import { Telegraf } from 'telegraf'; + +import { Telegraf } from 'telegraf'; +import { config } from 'dotenv'; +config(); import { about } from './commands'; import { greeting } from './text'; import { VercelRequest, VercelResponse } from '@vercel/node'; @@ -7,6 +10,12 @@ import { development, production } from './core'; const BOT_TOKEN = process.env.BOT_TOKEN || ''; const ENVIRONMENT = process.env.NODE_ENV || ''; +if (!BOT_TOKEN) { + console.error('Error: BOT_TOKEN is not defined in .env file'); + process.exit(1); +} +// console.log(`BOT_TOKEN: ${BOT_TOKEN}`); +// console.log(`NODE_ENV: ${ENVIRONMENT}`); const bot = new Telegraf(BOT_TOKEN); @@ -19,3 +28,4 @@ export const startVercel = async (req: VercelRequest, res: VercelResponse) => { }; //dev mode ENVIRONMENT !== 'production' && development(bot); + diff --git a/yarn.lock b/yarn.lock index 9017ca5b..72885809 100644 --- a/yarn.lock +++ b/yarn.lock @@ -530,6 +530,11 @@ dotenv@^16.3.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== +dotenv@^17.2.0: + version "17.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-17.2.0.tgz#e19678fdabcf86d4bfdb6764a758d7d44efbb6a2" + integrity sha512-Q4sgBT60gzd0BB0lSyYD3xM4YxrXA9y4uBDof1JNYGzOXrQdQ6yX+7XIAqoFOGQFOTK1D3Hts5OllpxMDZFONQ== + eastasianwidth@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb" @@ -950,10 +955,10 @@ node-gyp-build@^4.2.2: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.2.tgz#4f802b71c1ab2ca16af830e6c1ea7dd1ad9496fa" integrity sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw== -nodemon@^3.1.7: - version "3.1.7" - resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-3.1.7.tgz#07cb1f455f8bece6a499e0d72b5e029485521a54" - integrity sha512-hLj7fuMow6f0lbB0cD14Lz2xNjwsyruH251Pk4t/yIitCFJbmY1myuLlHm/q06aST4jg6EgAh74PIBBrRqpVAQ== +nodemon@^3.1.10: + version "3.1.10" + resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-3.1.10.tgz#5015c5eb4fffcb24d98cf9454df14f4fecec9bc1" + integrity sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw== dependencies: chokidar "^3.5.2" debug "^4" @@ -1299,10 +1304,10 @@ typescript@4.9.5: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== -typescript@^5.6.3: - version "5.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" - integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== +typescript@^5.8.3: + version "5.8.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.3.tgz#92f8a3e5e3cf497356f4178c34cd65a7f5e8440e" + integrity sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ== undefsafe@^2.0.5: version "2.0.5"