File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { AdminCommands } from './commands/admin/AdminCommands';
1111import { BotReply } from '../utils/chat/BotReply' ;
1212import { BotMiddleware } from './middleware/BotMiddleware' ;
1313import { MessagesService } from '../service/messages' ;
14+ import * as http from 'http' ;
1415export class CopBot {
1516 private static instance : CopBot ;
1617 private _bot : Bot < Context > ;
@@ -27,6 +28,15 @@ export class CopBot {
2728 }
2829 async start ( ) {
2930 try {
31+ // Ensure the bot is listening on the correct port (Render provides the PORT environment variable)
32+ const port = Config . port ;
33+
34+ // Use long-polling
35+ const server = http . createServer ( webhookCallback ( this . _bot , 'http' ) ) ;
36+
37+ server . listen ( port , ( ) => {
38+ console . log ( `Bot started on port ${ port } ` ) ;
39+ } ) ;
3040 await this . _bot . start ( {
3141 onStart : ( botInfo ) => {
3242 console . log ( `Bot started successfully! Username: ${ botInfo . username } ` ) ;
Original file line number Diff line number Diff line change @@ -5,14 +5,15 @@ class Config {
55 public token : string ;
66 public environment : 'development' | 'production' ;
77 public database : DatabaseConfig ;
8+ public port : number ;
89
910 private constructor ( ) {
1011 // Ensure that the token is available in the environment
1112 const token = process . env . TELEGRAM_BOT_TOKEN ;
1213 if ( ! token ) {
1314 throw new Error ( 'Telegram bot token is missing. Please set TELEGRAM_BOT_TOKEN in the environment.' ) ;
1415 }
15-
16+ const port = process . env . PORT ! ;
1617 // Set the environment, defaulting to development if not set
1718 const environment : 'development' | 'production' = process . env . NODE_ENV === 'production' ? 'production' : 'development' ;
1819
@@ -25,6 +26,7 @@ class Config {
2526 const dbUrl = environment === 'production' ? process . env . DATABASE_URL ! : process . env . DB_URL ! ;
2627 this . token = token ;
2728 this . environment = environment ;
29+ this . port = Number ( port ) ;
2830 // Initialize the database configuration
2931 this . database = {
3032 user : dbUser ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface DatabaseConfig {
1010export interface BotConfig {
1111 token : string ;
1212 environment : 'development' | 'production' ;
13+ port : number ;
1314 database : DatabaseConfig ;
1415}
1516export interface ErrorResponse {
You can’t perform that action at this time.
0 commit comments